Sign in to follow this  
Followers 0
Uncle Argyle

MySQL query help

8 posts in this topic

Hi everyone,

I am writing a script where I am making a simple query to a MySQL database on a remote computer.

Regardless of how I structure my query, the result comes back as m`*|-$D (Where * is actually a square, but I didn't know how to post that)

what am I doing wrong?

I am running AutoIT beta 3.1.1.119 and have copied the latest MySQL.au3 into my include directory. I have also install the mysql odbc driver and can successfully query the database from excel.

Thanks,

Mike.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>
#include <String.au3>
#include <MySQL.au3>

; == GUI generated with Koda ==

Opt("TrayIconHide", 1)
Opt("GUICloseOnESC", 0)

$Form1 = GUICreate("Worksheet Login", 270, 142, 450, 271)

$Input1 = GUICtrlCreateInput("", 112, 24, 121, 24, -1, $WS_EX_CLIENTEDGE)
$Input2 = GUICtrlCreateInput("", 112, 56, 121, 24, $ES_PASSWORD, $WS_EX_CLIENTEDGE)

GUICtrlCreateLabel("Username:", 32, 24, 70, 24, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Password:", 32, 56, 67, 24, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Button1 = GUICtrlCreateButton("OK", 48, 104, 75, 25, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("Cancel", 152, 104, 75, 25)

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")
        
$db = _MySQLConnect("admin","pass1234","ssbcrw", "10.1.1.27")

GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE

        ExitLoop

    Case $msg = $Button1

        $user = GUICtrlRead($Input1)
        
        $checkuser = _Query($db,"SELECT authority FROM users WHERE username = '" & $user & "'")
        
        MsgBox(0,"test","checkuser = " & $checkuser)
        
        
        ExitLoop

    EndSelect
WEnd
Exit

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm familiar with AutoIT and MySQL but I haven't used them together.

However...

I'm pretty sure that _Query() is going to return an array (of columns and rows)...not a string even if the result returns 1 field/1 record

Look at the _Query function for it's return value.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

I'm familiar with AutoIT and MySQL but I haven't used them together.

However...

I'm pretty sure that _Query() is going to return an array (of columns and rows)...not a string even if the result returns 1 field/1 record

Look at the _Query function for it's return value.

OK, that makes sense. I'll check into that!

Thanks!

Mike.

Share this post


Link to post
Share on other sites

OK, that makes sense. I'll check into that!

Thanks!

Mike.

It actually returns an object.

You'll ahve to use the following to get your info:

$var = _Query($db,"SELECT authority FROM users WHERE username = '" & $user & "'")
$authority = $var.Fields.("authority").value

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

It actually returns an object.

You'll ahve to use the following to get your info:

$var = _Query($db,"SELECT authority FROM users WHERE username = '" & $user & "'")
$authority = $var.Fields.("authority").value
Thanks to both sshrum and ame1011 for your help.

Share this post


Link to post
Share on other sites

It actually returns an object.

You'll ahve to use the following to get your info:

$var = _Query($db,"SELECT authority FROM users WHERE username = '" & $user & "'")
$authority = $var.Fields.("authority").value
I am getting an the following error

$authority = $var.Fields.("authority").value

$authority = $var.Fields.("authority")^ERROR

Object referenced outside a "with" statement.

So going by the example in MySQL UDF post, I added a with statement...and still now get an error in expression

$authority = .Fields.("authority").value

$authority = ^ERROR

Usually I can figure this stuff out with a little searching...but, this MySQL is kickin' my butt. Thanks to all...

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>
#include <String.au3>
#include <MySQL.au3>

; == GUI generated with Koda ==

Opt("TrayIconHide", 1)
Opt("GUICloseOnESC", 0)

$Form1 = GUICreate("SSB Credit Worksheet Login", 270, 142, 450, 271)

$Input1 = GUICtrlCreateInput("", 112, 24, 121, 24, -1, $WS_EX_CLIENTEDGE)
$Input2 = GUICtrlCreateInput("", 112, 56, 121, 24, $ES_PASSWORD, $WS_EX_CLIENTEDGE)

GUICtrlCreateLabel("Username:", 32, 24, 70, 24, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Password:", 32, 56, 67, 24, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")

$Button1 = GUICtrlCreateButton("OK", 48, 104, 75, 25, $BS_DEFPUSHBUTTON)
$Button2 = GUICtrlCreateButton("Cancel", 152, 104, 75, 25)

$objErr = ObjEvent("AutoIt.Error","MyErrFunc")
        
$db = _MySQLConnect("tcadmin","s9o1u0t3","ssbcrw", "10.206.1.27")

GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE

        ExitLoop

    Case $msg = $Button1

        $user = GUICtrlRead($Input1)
        
        $var = _Query($db,"SELECT authority FROM users WHERE username = '" & $user & "'")


                
                With $var
                $authority = .Fields.("authority").value
                MsgBox(0,"test","checkuser = " & $authority)
                EndWith
            
        
        ExitLoop

    EndSelect
WEnd

_MySQLEnd($sql)

Exit

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

replace

$authority = .Fields.("authority").valueoÝ÷ Û­«­¢+ØÀÌØíÕÑ¡½É¥Ñäô¹¥±Ì ÅÕ½ÐíÕÑ¡½É¥ÑäÅÕ½Ð줹ٱÕoÝ÷ Ø]ب©r§Âäx0ØfÊÊ¥©²êÞ¶­Ê·ö·¢)àjZ-¡÷«®Üç$x(®Ø^±Êâ¦Ü"W+j.¶ò¢áÞ­ë,¢g­)භ*.²Ö«µçZºÚ"µÍÌÍÝÙHÕRPÝXY
    ÌÍÒ[]JBÙØØH[[ÚXÝ ÌÎNÂYÝ[Ú[Ý
    ÌÍÝÙ    ][ÝÉÌÎNÉ][ÝÊH[   ÌÍÝÙHÝ[ÔXÙH
    ÌÍÝÙ    ][ÝÉÌÎNÉ][ÝË ][ÝÉÌLÉÌÎNÉ][ÝÊB[[[ÝHÚ]ÜXÙBÙ]Ë]Ë]Â
Edited by ame1011

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

Thanks so much, that did it! Any idea where I can learn more about the syntax about objects and MySQL.

Mike.

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