Sign in to follow this  
Followers 0
psychopyro212

Progandy MYSQL udf help

10 posts in this topic

I'm playing with Progandy's MYSQL udf and I'm having issues writing to the database.

Example Code:

#include <array.au3>
#include "mysql.au3"

$SQLAddress = "127.0.0.1"
$SQLUserName = "root"
$SQLPassword = ""
$SQLDatabase = "Testing"

_MySQL_InitLibrary()
$MysqlConn = _MySQL_Init()
_MySQL_Real_Connect($MysqlConn,$SQLAddress,$SQLUserName,$SQLPassword,$SQLDatabase)

If @error Then
    MsgBox("", "", "Error Connecting")
Else
    ;MsgBox("","","Success")
EndIf

;$query = "CREATE TABLE ErrorLog(ErrorNO Int Auto_Increment, Time TIMESTAMP,Error VARCHAR(100) NOT NULL,Sevarity Int(1) NOT NULL, Primary Key(ErrorNO))"
$query = "INSERT INTO errorlog(Error,Sevarity) VALUES ('Test Error',0)"
$result = _MySQL_Query($MysqlConn, $query)
ConsoleWrite($result & @CRLF)
_MySQL_Close($MysqlConn)
_MySQL_EndLibrary()

I'm attempting to use the MYSQL command: "INSERT INTO errorlog(Error,Sevarity) VALUES ('Test Error',0)" 

Reading through the udf a return from the _Mysql_Query function of 0 (which is what im getting) means success.

I then go to check the table in MYSQL workbench and it never wrote to the table. I ran the same command in workbench and it wrote to the table any ideas?

Share this post


Link to post
Share on other sites



Just to clarify this a little the code commented out to create a table worked just fine so it is interfacing with mysql to some extent.

Share this post


Link to post
Share on other sites

Hi,

Please add an error handler to know exactly the error message.

Put this on the top of the script:

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

 

And this anywhere on the script:

Func MyErrFunc()

$hexnum=hex($objErr.number,8)

Msgbox(0,"","We intercepted a COM Error!!"      & @CRLF                & @CRLF & _
             "err.description is: " & $objErr.description   & @CRLF & _
             "err.windescription is: " & $objErr.windescription & @CRLF & _
             "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & $objErr.scriptline    & @CRLF & _
             "err.number is: "       & $hexnum               & @CRLF & _
             "err.source is: "       & $objErr.source        & @CRLF & _
             "err.helpfile is: "       & $objErr.helpfile      & @CRLF & _
             "err.helpcontext is: " & $objErr.helpcontext _
            )
exit
EndFunc

 

And make sure the credential you used for login has a INSERT privillege

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

 

Here is my script with your included code:

#include <array.au3>
#include "mysql.au3"

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

$SQLAddress = "127.0.0.1"
$SQLUserName = "root"
$SQLPassword = ""
$SQLDatabase = "Testing"

_MySQL_InitLibrary()
$MysqlConn = _MySQL_Init()
_MySQL_Real_Connect($MysqlConn,$SQLAddress,$SQLUserName,$SQLPassword,$SQLDatabase)

If @error Then MsgBox("", "", "Error Connecting")

$query = "CREATE TABLE ErrorLog(ErrorNO Int Auto_Increment, Time TIMESTAMP,Error VARCHAR(100) NOT NULL,Sevarity Int(1) NOT NULL, Primary Key(ErrorNO))"
;$query = "INSERT INTO errorlog(Error,Sevarity) VALUES ('Test Error',0)"
$result = _MySQL_Real_Query($MysqlConn, $query)
ConsoleWrite("Return code = " & $result & @crlf & @MON & "/" & @MDAY & "/" & @YEAR & "-" & @hour & ":" & @MIN & ":" & @sec &@CRLF)
_MySQL_Close($MysqlConn)
_MySQL_EndLibrary()

Func MyErrFunc()

$hexnum=hex($objErr.number,8)

Msgbox(0,"","We intercepted a COM Error!!"      & @CRLF                & @CRLF & _
             "err.description is: " & $objErr.description   & @CRLF & _
             "err.windescription is: " & $objErr.windescription & @CRLF & _
             "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & $objErr.scriptline    & @CRLF & _
             "err.number is: "       & $hexnum               & @CRLF & _
             "err.source is: "       & $objErr.source        & @CRLF & _
             "err.helpfile is: "       & $objErr.helpfile      & @CRLF & _
             "err.helpcontext is: " & $objErr.helpcontext _
            )
exit
EndFunc

Here is the _MySQL_Real_Query  function

Func _MySQL_Real_Query($MySQL_ptr, $querystring, $querystringlength = Default)
    If Not $MySQL_ptr Then Return SetError(3, 0, $CR_NULL_POINTER)
    If $querystringlength <= 0 Or $querystringlength = Default Then $querystringlength = StringLen($querystring)
    Local $query = DllCall($ghMYSQL_LIBMYSQL, "int", "mysql_real_query", "ptr", $MySQL_ptr, "str", $querystring, "ulong", $querystringlength)
    If @error Then Return SetError(1, 0, 1)
    Return $query[0]
EndFunc   ;==>_MySQL_Real_Query

Getting this output from the script:

Return code = 0
01/22/2014-21:03:40
 
Here is the timestamp from the last entry into the database:
 
'25', '2014-01-19 20:37:23', 'Test Error', '0'
 
I can run this command in mysql workbench with no issues:
INSERT INTO errorlog(Error,Sevarity) VALUES ('Test Error',0)
 
This is functioning properly in my script and having no issues generating the table in mysql:
$query = "CREATE TABLE ErrorLog(ErrorNO Int Auto_Increment, Time TIMESTAMP,Error VARCHAR(100) NOT NULL,Sevarity Int(1) NOT NULL, Primary Key(ErrorNO))"

 

michaelslamet

Universalist

  • photo-thumb-56983.jpg?_r=1386905961
  • Active Members
  • bullet_black.pngbullet_black.pngbullet_black.pngbullet_black.pngbullet_black.pngbullet_black.png
  • 848 posts

Posted 20 January 2014 - 12:08 AM

Hi,

Please add an error handler to know exactly the error message.

Put this on the top of the script:

 

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")

 

And this anywhere on the script:

 

Func MyErrFunc()

$hexnum=hex($objErr.number,8)

Msgbox(0,"","We intercepted a COM Error!!"      & @CRLF                & @CRLF & _

             "err.description is: " & $objErr.description   & @CRLF & _

             "err.windescription is: " & $objErr.windescription & @CRLF & _

             "err.lastdllerror is: "   & $objErr.lastdllerror   & @CRLF & _

             "err.scriptline is: "   & $objErr.scriptline    & @CRLF & _

             "err.number is: "       & $hexnum               & @CRLF & _

             "err.source is: "       & $objErr.source        & @CRLF & _

             "err.helpfile is: "       & $objErr.helpfile      & @CRLF & _

             "err.helpcontext is: " & $objErr.helpcontext _

            )

exit

EndFunc

 

And make sure the credential you used for login has a INSERT privillege

 

 

 

As I showed in the script I revised I tried this and got no errors.

Root has all privileges. 

Thank you for your prompt reply!

Edited by psychopyro212

Share this post


Link to post
Share on other sites

Just to test this a little further I ran this in MySQL and used its credentials, Same results.

CREATE USER 'TESTACC'@'%' IDENTIFIED BY 'TESTPASS';
GRANT ALL PRIVILEGES ON *.* TO 'TESTACC'@'%';
CREATE USER 'TESTACC'@'localhost' IDENTIFIED BY 'TESTPASS';
GRANT ALL PRIVILEGES ON *.* TO 'TESTACC'@'localhost';

Share this post


Link to post
Share on other sites

Bump

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

dont have mysql.au3 but i used your query code with EzMySql, creater and wroted to DB form your query code with no problems.
 
pls try with >EzMySql, if problem is still there then something is wrong with your db settings or something third and pls check one more time does your root have all privilegies

bavl.png

#include "EzMySql.au3"
#include <Array.au3>

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

$Pass = ""

If Not _EzMySql_Open("", "root", $Pass, "", "3306") Then
    MsgBox(0, "Error opening Database", "Error: " & @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf

;~ If Not _EzMySql_Exec("CREATE DATABASE IF NOT EXISTS Testing") Then
;~  MsgBox(0, "Error opening Database", "Error: " & @error & @CR & "Error string: " & _EzMySql_ErrMsg())
;~  Exit
;~ EndIf

If Not _EzMySql_SelectDB("Testing") Then;change db name if needed
    MsgBox(0, "Error setting Database to use", "Error: " & @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf
;~ If Not _EzMYSql_Query("CREATE TABLE ErrorLog(ErrorNO Int Auto_Increment, Time TIMESTAMP,Error VARCHAR(100) NOT NULL,Sevarity Int(1) NOT NULL, Primary Key(ErrorNO));") Then
;~  MsgBox(0, "Query Error", "Error: " & @error & @CR & "Error string: " & _EzMySql_ErrMsg())
;~  Exit
;~ EndIf
If Not _EzMYSql_Query("INSERT INTO ErrorLog(Error,Sevarity) VALUES ('TextXName',0);") Then
    MsgBox(0, "Query Error", "Error: " & @error & @CR & "Error string: " & _EzMySql_ErrMsg())
    Exit
EndIf
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Do someone please have a good link to the "mysql.au3" by ProgAndi? Can't find it anywhere (not the one from cdkid).

Edited by Maxpilot

Share this post


Link to post
Share on other sites

At the moment looks like his link dont work and information when he was last time online is unknown

His last public post was 22 October 2012 - 08:34 PM

so maybe psychopyro212 can upload it for you if he still have it.


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Today all links work fine! Thanks to ProgAndy, great UDFs and Inspiration sources.

Edited by Maxpilot

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
Sign in to follow this  
Followers 0