Jump to content
ProgAndy

MySQL UDFs (without ODBC)

Recommended Posts

thx for your answer,

but what i really wanted to know was, if it is the right workaround to close and init after a failed connection,

because i guess it is a bug, that the script crashes by trying to connect after a connection error,

see the example script test.au3 - "Fehler Demo"

MsgBox(0,"Fehler-Demo","Fehler-Demo")
$connected = _MySQL_Real_Connect($MysqlConn,"localhostdfdf","droot","","cdcol")
If $connected = 0 Then
    $errno = _MySQL_errno($MysqlConn)
    MsgBox(0,"Error:",$errno & @LF & _MySQL_error($MysqlConn))
    If $errno = $CR_UNKNOWN_HOST Then MsgBox(0,"Error:","$CR_UNKNOWN_HOST" & @LF & $CR_UNKNOWN_HOST)
Endif

; XAMPP cdcol
MsgBox(0, "XAMPP-Cdcol-demo", "XAMPP-Cdcol-demo")

$connected = _MySQL_Real_Connect($MysqlConn, "localhost", "user", "pass", "cdcol") <------------ CRASH ---------

Share this post


Link to post
Share on other sites

thx for your answer,

but what i really wanted to know was, if it is the right workaround to close and init after a failed connection,

because i guess it is a bug, that the script crashes by trying to connect after a connection error,

see the example script test.au3 - "Fehler Demo"

MsgBox(0,"Fehler-Demo","Fehler-Demo")
$connected = _MySQL_Real_Connect($MysqlConn,"localhostdfdf","droot","","cdcol")
If $connected = 0 Then
    $errno = _MySQL_errno($MysqlConn)
    MsgBox(0,"Error:",$errno & @LF & _MySQL_error($MysqlConn))
    If $errno = $CR_UNKNOWN_HOST Then MsgBox(0,"Error:","$CR_UNKNOWN_HOST" & @LF & $CR_UNKNOWN_HOST)
Endif

; XAMPP cdcol
MsgBox(0, "XAMPP-Cdcol-demo", "XAMPP-Cdcol-demo")

$connected = _MySQL_Real_Connect($MysqlConn, "localhost", "user", "pass", "cdcol") <------------ CRASH ---------

Strange. It is working for me. But your workaround seems to be OK.

Which version of the DLL do you use? The one provided with the most recent download?

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

I'm really sorry. It's working for me with Firefox and IE7+8 so i can not reproduce your problem. Anyways, i uploaded it to radpidshare for you. (@all: please do not download it unless you have problems with the original download, there are only 10 available downloads on rapidshare)

I also had trouble. I downloaded the .zip file from the first post, but when trying to unzip it with version 10 of winzip it failed. I updated to version 14 of winzip and it still failed in the same way. It was having issue with the libmysql.dll extraction. Things went fine when I downloaded from the rapidshare link. I used Firefox 3.5.8

Here's the error from winzip:

Extracting libmysql.dll

Error: Invalid compressed data to expand (inflate) the file

Error in file #7: bad Zip file offset (Error local header signature not found): disk #1 offset: 845188

Extracting MySQL.au3

Thanks so much for your contribution. I'm not sure if/when I'll use the MySQL UDF, but I sure want to have it in my pocket in case I need it!

Edited by rolok

Share this post


Link to post
Share on other sites

Sorry, this was a transmission error. Somehow the file was not transferred correctly when I moved to a new server. Just download it again, it should work now.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Hi,

I am trying to run the example file. When running i get an error from line 16: If @error Then Exit MsgBox(0, '', "")

Do i need to install some drivers? Hope you can help me getting it working.

Some debug information.

Editted line 18 to: If @error Then Exit MsgBox(0, '', @error) got error 2

File mysql.au3 line: 266. Got an return from there. No idea what my problem is.

Got an error -1 at dllopen, so it can not open the dll file. why? Everything is in the same folder.

Edited by Erik.

I little problem, hard to find and fix

Share this post


Link to post
Share on other sites

The DLL must be in the same folder as your main script or you have to specify the correct path in _MySQL_InitLibrary(). Also you have to run your script in 32bit (x86) mode since the DLL is not designed for 64bits.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Open the context-menu for the au3-file and choose Run (x86) or something like that.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

I think you have to use the Fulll SciTe4AutoIt and add the line #AutoIt3Wrapper_usex64=y to your script.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

First of all, thanks so much for your UDF, really like it.

At first, I'm a bit lost on how to use it but after a few tries, I got it.

I got some question, is there an option to keep the connection alive?

...because after sometimes, the connection will hang.

...or is there an option to auto-reconnect after timeout?

Regards,

slayerz


AUTOIT[sup] I'm lovin' it![/sup]

Share this post


Link to post
Share on other sites

Hi, it is possible to let the library reconnect when te connection timed out and you send a new query. To do that, you have to change the _MySQL_Real_connect to the following:

_MySQL_Options($hMySQL, $MYSQL_OPT_RECONNECT, 1, 'int*')
_MySQL_Real_Connect($hMySQL, ...)
_MySQL_Options($hMySQL, $MYSQL_OPT_RECONNECT, 1, 'int*')

More options can be found here.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Thanks ProgAndy, this is much more elegant than sending dummy command every 10 minutes to keep the connection alive.

:(

Some more question :

mysql_real_connect() incorrectly reset the MYSQL_OPT_RECONNECT option to its default value before MySQL 5.1.6. Therefore, prior to that version, if you want reconnect to be enabled for each connection, you must call mysql_options() with the MYSQL_OPT_RECONNECT option after each call to mysql_real_connect(). This is not necessary as of 5.1.6: Call mysql_options() only before mysql_real_connect() as usual.

If I call _MySQL_Options($hMySQL, $MYSQL_OPT_RECONNECT, 1, 'int*') after _MySQL_Real_Connect($hMySQL,...), is it will give the same result as your code?

Sorry, little confuse... :)

EDIT : It's OK ProgAndy, I got it now, hehe...your solution will be compatible for any MySQL version

Edited by slayerz

AUTOIT[sup] I'm lovin' it![/sup]

Share this post


Link to post
Share on other sites

I have a few questions to ask about libmysql.dll versions and compatibilities. There must be a difference between versions or there wouldn't be a need for multiple files and associated documentation.

Here are my questions then:

1.) What version of libmysql.dll is bundled with your provided download?

2.) What versions of libmysql.dll are compatible with the included "MYSQL.au3"?

Thanks for your awesome work and allowing me to use AutoIt to communicate with projects using MySQL!

Share this post


Link to post
Share on other sites

Hi,

I bundled libmysql 5.0.45 (32bit). This shoud be the first message when you execute test.au3 :idea:

The UDF should work with all versions of libmysql that use the same API. At least, all 5.0 and 6.0-dlls should work, I think. I'm not sure about version 4 since I don't have the function headers for them, but I think, this version should work, too.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

@ProgAndy

I am trying to add function to show to user something like, "SERVER DOWN. SERVICE IS UNAVAILABLE AT THE MOMENT" if the MySQL Server is down. So the users cannot use the program until the server is up again.

Just need some advice from you, can I achieve the above said function using mysql_ping(MYSQL *mysql) ? btw, I set the option to auto reconnect.

Regards,

slayerz


AUTOIT[sup] I'm lovin' it![/sup]

Share this post


Link to post
Share on other sites

First, you should check the connection after _MySQL_Real_Connect. This function fails when the server is not available. Use _MySQL_Errno and _MYSQL_Error to get the error number and message.

_MySQL_Ping checks if the connection is still alive or a reconnect was successful. If this function returns NONZERO, the mysql-server has gone away. Use again errno & error to get the specific error message.

Edit: The error codes that can occur are listed here (section "Errors"):

http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html

http://dev.mysql.com/doc/refman/5.1/en/mysql-ping.html

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Thanks for the reply...After some digging, mysql_ping will attempt to reconnect if the connection is lost, I'm not sure whether this is the right option.

Let say, every 2 minutes:

1 - check the status of the server

2 - if server down, display the message to user, try to reconnect

3 - do #1 to #2 until server is up, remove the message

I will try to work it out. BTW, what is the best practices that you would use for an application that will run indefinitely, but only occasionally needs to make database queries. Should I call mysql_init() and mysql_real_connect() each time of the query OR only once at the beginning of the script for mysql_init() and/or mysql_real_connect()

Regards,

slayerz

Edited by slayerz

AUTOIT[sup] I'm lovin' it![/sup]

Share this post


Link to post
Share on other sites

I think, you should connect when the DB is needed for the first time and include the reconnect option. Then the connection will be autmatically reestablished when a query is sent and it was closed.

It also depends on the interval. If you need MySQL only once an hour then create the connection only for the query and close it afterwards, but you shouldn't close and reopen the connection if you send the next query immediately after the first.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • By RAMzor
      Hello all!
      I got the Acroname Programmable USB Hub based on BrainStem platform. I will use it to manage ports and read current.
      They have development kit (BRAINSTEM DEVELOPMENT KIT) with examples for any languages like C#, C++, LabVIEW and python but no AutoIt.
      The kit include BrainStem2.dll (x32 and x64), BrainStem2_LabVIEW.dll, BrainStem2CLI.dll and many examples.
      Anyone used this dll and implemented it in AutoIt?
      Please share some example for Device Discovering, User LED Flashing or power enable/disable on port to start play with this HUB
      BrainStem Reference 
       
      BrainStem2 lib+example.7z USB HUB User Manual s79-usbhub-3p_v1.10_0.pdf
    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
      Cheers
      https://github.com/matwachich/wkhtmltopdf-au3
    • By Skysnake
      This is relevant
      From here https://stackoverflow.com/questions/3454315/is-it-possible-to-pin-a-dll-in-memory-to-prevent-unloading
      I use several UDFs on the Forum to do various things.  Those UDFs work very well.
      Effectively the UDFs are DLL wrappers, that make it possible to access DLL functions easily without the long hard slog of DLLCall() every time.
      However, I have now run into the issue that multiple UDF DLLCalls are slow. Not mind numbingly slow, but slow enough to become noticeable with a large of repeated function calls.
      So I was wondering, is it possible to "load a DLL into memory" and leave it there for the duration of my script's lifetime, avoid repeated DLL on-disk reads with a persistent in memory DLL?
      From Microsoft
      https://docs.microsoft.com/en-us/windows/desktop/dlls/about-dynamic-link-libraries
      Looks like what I want to do is: load-time dynamic linking,
      So next question, (a) how do I do this with AutoIt (b) How would this impact on standard AutoIt type DLL calls?
       
      The point is speed.  Is there a different approach?
      Or am I barking up the wrong tree?
      Skysnake
    • By bladem2003
      Hello,
      i need help to translate the c code to autoit .
      I don't understand the callback function.
       
      #include <windows.h> #include <stdio.h> // native IR Data by PAnsiChar typedef void CALLBACK CallBackPAnsiChar(char*, char*, char*, char*); typedef int (__stdcall *impInitPAnsiChar)(CallBackPAnsiChar); CALLBACK MyCallBackPAnsiChar(char* Protocol, char* Address, char* Command, char* Flags) { printf("\nIR Data received: Protocol: %s, Address: 0x%s, Command: 0x%s, Flags: 0x%s", Protocol, Address, Command, Flags); fflush(stdout); } int main(int argc, char **argv) { impInitPAnsiChar InitPAnsiChar = NULL; // Load DLL file HINSTANCE hinstLib = LoadLibrary(TEXT("USB_IR_Remote_Receiver.dll")); if (hinstLib == NULL) { printf("\nERROR: unable to load DLL\n"); return 1; } // Get function pointer InitPAnsiChar InitPAnsiChar = (impInitPAnsiChar)GetProcAddress(hinstLib, "InitPAnsiChar"); if (InitPAnsiChar == NULL) { printf("\nERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); return 1; } if (InitPAnsiChar(*MyCallBackPAnsiChar)) { printf("\nInit DLL with InitPAnsiChar successfull"); } else { // Unload DLL file FreeLibrary(hinstLib); return 0; } while(1) { } //return 0; }  
    • By Stacker
      Hi all,
      i want to start a new application that capture a screen or image from webcam an read all barcode inside the picture.
      I have test this code https://www.autoitscript.com/forum/topic/27925-webcam-example/
      Works fine for my webcam.
      Now i need to read all barcodes (code 128 code39, no 2d) inside the picture. I have found this https://www.codeproject.com/Articles/42852/Reading-Barcodes-from-an-Image-III
      It's possible to make a dll from VB source i linked  with this  parameters :  filename, Array of barcode founded, error code and launch from Autoit with function ?
      Anyone can help me to make dll and autoit function, i don't know VB.
      Thanks
×
×
  • Create New...