Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Object-type variable allowed in a "With" statement in MySql


  • Please log in to reply
13 replies to this topic

#1 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 27 April 2012 - 01:10 PM

Hello forum,

I'm kinda new to this program. I loved it's compatibilities and how you can blend it and combine this program whit other programs to get your results and what your looking for done.

I'm making a program, which in some part of the program it must connect to a remote server and obtain some information from MySQL database running on that server.

i did find this topic very helpful ==> http://www.autoitscript.com/forum/topic/20814-mysql-udfs/

i tested it, and it did what i wanted, but only in my testing script.

If i combine the test script with my original script, i'm getting this error in my console :

==> Only Object-type variables allowed in a "With" statement.:
With $TableContents
With ^ ERROR

the code i'm using in my script ( which runs flawlessly in a separate au3 file )is :

$MYSQLUserName = "root" $MYSQLPassword = "pass" $MYSQLDatabase = "auth" $MySQLServerName = "127.0.0.1" $SQLInstance = _MySQLConnect($MYSQLUserName,$MYSQLPassword,$MYSQLDatabase,$MySQLServerName) $SQLCode = "SELECT * FROM realmlist" $TableContents = _Query($SQLInstance,$SQLCode) With $TableContents While Not .EOF $NameList = .Fields ("id").value & " " & .Fields ("name").value & @CRLF .MoveNext WEnd EndWith MsgBox(0,"Guest List",$NameList)


i'm assuming there is a conflict in my script with this code. so i'm adding all my includes :

#include <FTPEx.au3>
#include <Process.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>
#include <GUICtrlOnHover.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MySQL.au3>


and i did reinstall my ODBC, as "oshaker" mentioned in this topic :

http://www.autoitscript.com/forum/topic/...e-variables-allowed-in-a-with-

Thanks for your help.

Edited by Siwa, 27 April 2012 - 01:13 PM.








#2 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 27 April 2012 - 09:44 PM

i do appreciate it if any one skilled or experienced can help me find the problem.

Thanks.

#3 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,988 posts

Posted 27 April 2012 - 11:00 PM

I haven't used this udf, but looked at mysql.au3 briefly... so, what is _Query()? it is not a function in the UDF. Assuming you mean _mysql_query(), it doeasn't return an object
;Function Name:   _MySQL_Query ; Description:: Executes an SQL statement. Normally, the string must consist ;                   of a single SQL statement and you should not add a terminating ;                   semicolon (“;”) or g to the statement. If multiple-statement ;                   execution has been enabled, the string can contain several ;                   statements separated by semicolons. ; Parameter(s): $MySQL_ptr - Pointer to the MySQL struct ;                 $query     - Query to execute MUST NOT contain Chr(0) ;                              For binary data use _MySQL_Real_Query ; Requirement(s):  libmysql.dll ; Return Value(s): Zero if the statement was successful. Non-zero if an error occurred. ; Author(s):       [email="Prog@ndy"]Prog@ndy[/email]


see the example in the distribution for how to access the return.

Dale

Edited by DaleHohm, 27 April 2012 - 11:02 PM.

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

 

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

 

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y
Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble


#4 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 28 April 2012 - 05:12 AM

I haven't used this udf, but looked at mysql.au3 briefly... so, what is _Query()? it is not a function in the UDF. Assuming you mean _mysql_query(), it doeasn't return an object

;Function Name:   _MySQL_Query ; Description:: Executes an SQL statement. Normally, the string must consist ;                   of a single SQL statement and you should not add a terminating ;                   semicolon (“;”) or g to the statement. If multiple-statement ;                   execution has been enabled, the string can contain several ;                   statements separated by semicolons. ; Parameter(s): $MySQL_ptr - Pointer to the MySQL struct ;                 $query     - Query to execute MUST NOT contain Chr(0) ;                              For binary data use _MySQL_Real_Query ; Requirement(s):  libmysql.dll ; Return Value(s): Zero if the statement was successful. Non-zero if an error occurred. ; Author(s):       [email="Prog@ndy"]Prog@ndy[/email]


see the example in the distribution for how to access the return.

Dale

Thanks for your reply.

But i did follow the author's guide on how to connect to the database.

I don't know which file you looked at, but here is the _Query section from "mysql.au3" file :

#cs Function name: _Query Description:     Send a query to the database Parameter(s):  $oConnectionObj - As returned by _MySQLConnect. $query - The query to execute Return Value(s):On success returns the query result. On failure returns 0 and sets @error to 1 Requirement(s):Autoit3 with COM support Author(s):      cdid #ce Func _Query($oConnectionObj, $sQuery) If IsObj($oConnectionObj) Then   Return $oConnectionobj.execute ($sQuery) EndIf If @error Then   SetError(1)   Return 0 EndIf EndFunc   ;==>_Query

And as i mentioned earlier i can connect to my database in a separate script file ( another au3 file which only contains the code that connects to my database and i did write it in the first post of this topic ). But when i insert this code to my project, i get this error.

Edited by Siwa, 28 April 2012 - 05:18 AM.


#5 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 28 April 2012 - 05:33 AM

i'm guessing i got two ( or three ) options here :

1 - Change the "With" function to something similar, but not as restrictive as "With".

2 - Force my variable to be an objective-type variable.

or 3 - Find really what is causing my problem. ;)

#6 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 28 April 2012 - 07:15 AM

3 is the way to go. By the way, there is also an UDF that does not require ODBC here. It doesn't use objects.

Edited by ProgAndy, 28 April 2012 - 07:17 AM.

  • Siwa likes this
*GERMAN* Posted Image [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

#7 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 28 April 2012 - 11:39 AM

Thanks ProgAndy, but i did try your way too. But unfortunatlly my script size is more important to me. If i use your magnificent udf, my scripts final size is trippled, and i do not want that. If there is a way to reduce the final size, in anyway, please advise me to do so.

Two things, are very imortant for me : 1 - size, 2 - low internet consumption.

Edited by Siwa, 28 April 2012 - 11:40 AM.


#8 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 28 April 2012 - 01:09 PM

If i use your magnificent udf, my scripts final size is trippled, and i do not want that. If there is a way to reduce the final size, in anyway, please advise me to do so.

The UDF contains a DLL to access mysql. If you use ODBC, the DLL is not needed but you have to install the large ODBC binary. If ODBC is available anyways, the additional DLL is a drawback.

If you want us to help spot the error in your script you have to publish it. Otherwise we cannot provide any useful information.
*GERMAN* Posted Image [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

#9 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 28 April 2012 - 01:42 PM

The UDF contains a DLL to access mysql. If you use ODBC, the DLL is not needed but you have to install the large ODBC binary. If ODBC is available anyways, the additional DLL is a drawback.

If you want us to help spot the error in your script you have to publish it. Otherwise we cannot provide any useful information.


Thank you for your time and replys.

Do i have to publish the whole script ? It's like ~800 lines.

And as for the ODBC, i can easily download it once and istall.

Here is my script. :

and i have to say, as i said in my first post, i just started autoit scripting only for 1 week, and i don't know any language like vb or c or c# or any of them . so if there is any error in my script, or any modification, i'll be glad to know.

thanks.

Edited by Siwa, 09 May 2012 - 08:35 AM.


#10 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 28 April 2012 - 03:31 PM

This seems to be correct. Try it this way:
Global $TableContents = _Query($SQLInstance,$SQLCode) If @error Then     MsgBox(0, "Error SQL", "Error when executing SQL") Elseif IsObj($TableContents) Then     MsgBox(0,"Guest List","sss")     $NameList = ""     With $TableContents     While Not .EOF         $NameList &= .Fields ("id").value & " " & .Fields ("name").value & @CRLF         .MoveNext     WEnd     EndWith     MsgBox(0,"Guest List",$NameList) Else     MsgBox(0, "SQL Error", "Something went wrong without error. Maybe no result?") EndIf

*GERMAN* Posted Image [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

#11 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 28 April 2012 - 04:00 PM

This seems to be correct. Try it this way:

Global $TableContents = _Query($SQLInstance,$SQLCode) If @error Then     MsgBox(0, "Error SQL", "Error when executing SQL") Elseif IsObj($TableContents) Then     MsgBox(0,"Guest List","sss")     $NameList = ""     With $TableContents     While Not .EOF         $NameList &= .Fields ("id").value & " " & .Fields ("name").value & @CRLF         .MoveNext     WEnd     EndWith     MsgBox(0,"Guest List",$NameList) Else     MsgBox(0, "SQL Error", "Something went wrong without error. Maybe no result?") EndIf

i did try it and i get the message : MsgBox(0, "SQL Error", "Something went wrong without error. Maybe no result?")

And i'm sure there is data there.

but if i put the SQL section in another empty script like this one :

Plain Text         
#include <MySQL.au3> $MYSQLUserName = "root" $MYSQLPassword = "ascent" $MYSQLDatabase = "auth" $MySQLServerName = "127.0.0.1" Global $SQLInstance = _MySQLConnect($MYSQLUserName,$MYSQLPassword,$MYSQLDatabase,$MySQLServerName) Global $SQLCode = "SELECT * FROM realmlist" Global $TableContents = _Query($SQLInstance,$SQLCode) If @error Then     MsgBox(0, "Error SQL", "Error when executing SQL") Elseif IsObj($TableContents) Then     MsgBox(0,"Guest List","sss")     $NameList = ""     With $TableContents     While Not .EOF         $NameList &= .Fields ("id").value & " " & .Fields ("name").value & @CRLF         .MoveNext     WEnd     EndWith     MsgBox(0,"Guest List",$NameList) Else     MsgBox(0, "SQL Error", "Something went wrong without error. Maybe no result?") EndIf


i'll get the result i want.

and this is the part, that i don't get. in an empty script, it works, but in my script, it dosen't.

as i mentioned eariler maybe there is a conflict with one of the includes ?

#12 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 28 April 2012 - 04:06 PM

You can try with this user name and password :

$MYSQLUserName = "test" $MYSQLPassword = "123456" $MYSQLDatabase = "auth" $MySQLServerName = "188.245.7.75"


It's a test account. and my ip address is dynamic. So no worries.

Edited by Siwa, 28 April 2012 - 04:07 PM.


#13 Siwa

Siwa

    Seeker

  • Active Members
  • 10 posts

Posted 29 April 2012 - 05:15 AM

I guess my problem is kinda unsolveable ?

What about the other options i talked about :

1 - Change the "With" function to something similar, but not as restrictive as "With".

2 - Force my variable to be an objective-type variable.

===============

progAndy, is there a way to use your script, without using your udf ? Like call the install from the net, get ODBC installed once and for all, then use your script, to call necessary DLLs ?

#14 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 02 May 2012 - 02:41 PM

progAndy, is there a way to use your script, without using your udf ? Like call the install from the net, get ODBC installed once and for all, then use your script, to call necessary DLLs ?

Either use always ODBC or store the DLL somewhere on a server, use InetGet if the DLL is missing, and then load the UDF with the downloaded DLL.
*GERMAN* Posted Image [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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users