Sign in to follow this  
Followers 0

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

14 posts in this topic

Posted (edited)

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 ==>

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 :

Thanks for your help.

Edited by Siwa

Share this post


Link to post
Share on other sites



Posted

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

Thanks.

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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. ;)

Share this post


Link to post
Share on other sites

Posted (edited)

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
Siwa likes this

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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 :

#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 ?

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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 ?

Share this post


Link to post
Share on other sites

Posted

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.

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