Jump to content

Recommended Posts

Posted

@mLipok is right as he implies that the code used to invoke MySQL insert statement has to cope with the right encoding, and that is what a good ADO UDF has to do. So use his proven working UDF and all will be fine.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

  • 9 months later...
Posted

Func _EzMySql_AddTable2d($sTableName, $aData) NOT WORKING!!!

Bellow is a modification:

Func _EzMySql_AddTable2d($sTableName, $aData)
    Local $querystring, $iResult
    If Not $sTableName Then Return SetError(6, 0, 0)
    If Not IsArray($aData) Then Return SetError(7, 0, 0)
    If Not UBound($aData) > 1 Then Return SetError(8, 0, 0)
    If Not UBound($aData, 2) Then Return SetError(9, 0, 0)
    Local $iColumns = UBound($aData,2)-1
    For $iRow = 1 To UBound($aData)-1
         $querystring &= "INSERT INTO " & "`" &$sTableName &"`"& " ("
        For $i = 0 To $iColumns Step 1
            $querystring &= "`" & $aData[0][$i] &"`" & ","
        Next
        $querystring = StringTrimRight($querystring, 1)
        $querystring &= ")  VALUES ('"
        For $i = 0 To $iColumns Step 1
            $querystring &= $aData[$iRow][$i] & "','"
        Next
        $querystring = StringTrimRight($querystring, 2)
        $querystring &= ");"
    Next
    If Not _EzMySql_Exec($querystring) Then Return SetError(@error, 0, 0)
    Return 1
EndFunc

 

Posted (edited)

As a sidenote, it would be much better efficiency-wise to wrap the outer FOR loop inside a transaction.... BUT:

More importantly, if a string in a cell of the added array contains a single quote, the whole insert will fail. Any string content must be escaped (by doubling internal single quote).

Also it may be good to think about insertion of a huge array in a single insert: some (all?) engine might very well limit SQL statement size.

Finally, the datatype of the array's cells is ignored and everything is inserted as string literal, which not all tables will cope with.

All in all, I'm afraid real-world things aren't that simple.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

Not much more than what I suggested. The actual real issue is you know nothing about the potential content of the array. It may be 15 rows of 3 columns containing all short strings, but it might as well be 12 million rows array of 153 columns with some cell holding 600kb strings. In such situation, the basic principle is "know your data", which is essentially impossible in a generic function.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

  • 10 months later...
Posted
If Not _EzMySql_Startup() Then
    MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf
If Not _EzMySql_Open("myhostname", "mydbusername", "mydbpassword", "mydbname", "3306") Then
    MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    amtt("Error Connecting To DB")
    Exit
EndIf
$sql = "SELECT userID FROM ws_LS_user WHERE statslinkcode='"& $igstatslinkcode &"';"
$quserid = _EzMySql_Query($sql)

Hello, 

I am trying to return the value of userID based on the WHERE Condition. The user enters the unique code ($igstatslinkcode) which matches one they already created on the Website (statslinkcode) - i believe this part is working correctly.

However, i cannot get the contents of the userID Field, i can only get $quserid = 1.

Could someone please explain how i can retrieve the value of a single field from a single column?

Many thanks in advance.

Posted

Anyone?

If i use the code from the example:

For $i = 1 To _EzMySql_Rows() Step 1
    $a1Row = _EzMySql_FetchData()
    _ArrayDisplay($a1Row, "Result: " & $i)
Next

I can even get the correct result displayed in the _ArrayDisplay but still no idea how to convert this one value to a variable i can use...

Posted (edited)

can you post the output please to give a clearer example of what is in the array? which element in the array do you need? just dummy up the data if you need to

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted (edited)

Well firstly, thank-you Earthshine for replying to me.

Just to reiterate what i'm trying to do so it's clear:

$sql = "SELECT userID FROM ws_LS_user WHERE statslinkcode='"& $igstatslinkcode &"';"
                $quserid = _EzMySql_Query($sql)
                For $i = 1 To _EzMySql_Rows() Step 1
                $fuserid = _EzMySql_FetchData()
                $auserid = _ArrayDisplay($fuserid, "Result: " & $i)

"statslinkcode" exists in the Database, it is created by each user on my Website and each code is unique.

"$igstatslinkcode" is entered by the User within the Autoit Application, if it matches one in the Web-DB it should return the userID of that User from the Web-DB and obviously, only that one result as it's 1x unique code per User.

I would then like to have this single unique userid returned from the Web-DB available as a variable such as: $userid so i can use it to do various other things for that single user.

In testing (on my own User) when i enter the Unique Code attached to my User it seems to produce the correct result within this "_ArrayDisplay" Window (see attached image). My userID is 2. So i want the value of Col 0 as a variable whenever this query is run and don't need this ArrayDisplay window popping up at all :-D

Cheers!

PS. Sorry for the huge image - my resolution is 4k.

 

result.png

Edited by GoldenEagle
Posted (edited)

the arraydisplay is just to show you what's in it. you can comment that out.

try just printing out $fuserid[1] and assign to variable if you need to

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted
27 minutes ago, Earthshine said:

the arraydisplay is just to show you what's in it. you can comment that out.

try just printing out $fuserid[1] and assign to variable if you need to

Thank-you so much for pointing me in the right direction. As you can tell i'm totally new to AutoIT (massive noob) and in fact i'm starting to edit and add to the Source Code of a program that another developer gave to me.

I really felt foolish being unable to work this out on my own or from reading through this or similar topics and had spent hours going round in circles. I also had a feeling the answer would be simple in the end. When i attempted to use $userid[1] the Program crashed, so i tried with 0 considering it was Col 0 and it's working perfectly.

This is the code now working for me:

$sql = "SELECT userID FROM ws_LS_user WHERE statslinkcode='"& $igstatslinkcode &"';"
                $quserid = _EzMySql_Query($sql)
                For $i = 1 To _EzMySql_Rows() Step 1
                $userid = _EzMySql_FetchData()
                $fuserid = $userid[0]
                Next

I wonder if i need this: "For $i = 1 To _EzMySql_Rows() Step 1" at all?

Cheers again & Have a great evening!

= )

Posted (edited)

if all you are going to get back is a one row array, you won't need that for loop.

that is for looping through and getting a bunch in a loop.

The help file is a great place to look for some of this stuff. For loops are covered as an example, which, in your case you don't need right now but may one day.

happy programming! (ps i gave you the wrong index number but that was so you would get it on your own through experimentation, and you did!! congrats!)

Edited by Earthshine

My resources are limited. You must ask the right questions

 

  • 1 year later...
  • 4 months later...
  • 1 year later...
Posted

We just upgraded our MySql servers and they now required SSL connections. Took me a couple days to dig out all the info I needed to make it work so I thought it may be useful for other people. I have added a new function, _EzmySql_SetOptions, and updated the DLLs to support SSL connections.

For my servers, these are the options I needed to set before opening the connection to the database.

If Not _EzMySql_Startup() Then
    MsgBox(262144, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SetOption($MYSQL_ENABLE_CLEARTEXT_PLUGIN, 1) Then
    MsgBox(262144, "Error setting Option", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SetOption($MYSQL_OPT_SSL_CA, $pathToCA) Then
    MsgBox(262144, "Error setting Option", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SetOption($MYSQL_OPT_SSL_CERT, $pathToCert) Then
    MsgBox(262144, "Error setting Option", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_SetOption($MYSQL_OPT_SSL_KEY, $pathToKey) Then
    MsgBox(262144, "Error setting Option", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

If Not _EzMySql_Open($dbip, $dbuser, $dbpw, "", $dbport) Then
    MsgBox(262144, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

 

EZmySql.zip

Posted

Hi everyone, I wanted to know if anyone has used this library with BLOB type data. I was able to successfully insert a file into the database, but now there is no way I can save it to disk. By running the query ... "INTO DUMPFILE" I cannot decide the path to save locally "Permission Problem". While with the code below I am not able to save the binary file to disk. Can someone help me ?

$sQuery_Func = "SELECT * FROM " & $Table & " WHERE ID=" & _MySQL_FastEscape($ID) & ";"

$aRecord = _EzMySql_GetTable1d($sQuery_Func)

if Not IsArray($aRecord) Then Exit

$BlobField = $aRecord[1]
$BlobExtension = $aRecord[2]
MsgBox(0,"","DataType=" & VarGetType($BlobField) & @LF) ;This Will Print 'String'

$FilePath_Output = "c:\testfile." & $BlobExtension

    $tmp_file_blob=StringToBinary($BlobField)
    $file = FileOpen($FilePath_Output,18)
    FileWrite($file, $tmp_file_blob)
    FileClose($file)

Thanks in advance :ILA2:

:rolleyes:

  • 4 months later...
Posted

HI to all, I'am working on  a project using mySql and this UDF saved my life.

I started with the files from  the post of @Zuldan23 but I made slight changes (only in file EZmySqlConstants.au3) to avoid warnings in compile (not declared variables), transforming some variables in global consts.

I attach my files.

EZmySql.zip

  • 7 months later...
Posted

Hello

Using EzMySql UDF I display the contents of the table.

$aOk = _EzMySql_GetTable2d("SELECT post_title, max_price, stock_quantity FROM `fdgh57jgh_posts`, `fdgh57jgh_wc_product_meta_lookup` WHERE fdgh57jgh_posts.ID = fdgh57jgh_wc_product_meta_lookup.product_id")
$error = @error
If Not IsArray($aOk) Then MsgBox(0, $sMySqlStatement & " error", $error)
_ArrayDisplay($aOk, "2d Array Names of certain eyecolour")

How can you modify the encoding of the displayed Polish characters? (e.g. ł, ń, ą ...)

obraz.png.aec85e8e5c033cedfcd3ff748932ef39.png

 

Posted
13 hours ago, walec said:

How can you modify the encoding of the displayed Polish characters? (e.g. ł, ń, ą ...)

I suppose, there is not the problem.

IMHO You should change connection properties.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...