Jump to content
Sign in to follow this  
SoulA

MySQL Problem

Recommended Posts

SoulA

Need help with this code. I don't think I am adding the records right but I think followed the example posted in the UDF thread pretty perfectly.

I get a $oconnectionobj.execute ($query) error.

#Include <File.au3>
#Include <mysql.au3>

$folder = "C:\test"
$database = "C:\test1"
While 1
    $FileList = _FileListToArray($folder, "*", 1)
    If NOT @error Then
        For $i = 1 to $FileList[0]
            FileMove($folder & "\" & $FileList[$i], $database & "\" & $FileList[$i], 1)
        Next
        addData($FileList)
    EndIf
    sleep(10000)
WEnd

Func addData($FileList)
    Dim $values[$FileList[0] * 2 + 1]
    $sql = _MySQLConnect("root", "", "captured_pictures", "localhost")
    If NOT @error Then
        $index = 1
        For $i = 0 to $FileList[0]
            $values[$i] = @Hour
            $values[$i + 1] = $FileList[$index]
            $i = $i + 2
            $index = $index + 1
        Next
        $values[UBound($values) - 1] = ""
        $error = _AddRecord($sql, 'mytable', $values, $values)
        msgbox(0,"error",$error) ;0 is error 1 is success DEBUG
        _MySQLEnd($sql)
    EndIf
EndFunc
Edited by SoulA

Share this post


Link to post
Share on other sites
PsaltyDS

Need help with this code. I don't think I am adding the records right but I think followed the example posted in the UDF thread pretty perfectly.

I get a $oconnectionobj.execute ($query) error.

#Include <File.au3>
#Include <mysql.au3>

$folder = "C:\test"
$database = "C:\test1"
While 1
    $FileList = _FileListToArray($folder, "*", 1)
    If NOT @error Then
        For $i = 1 to $FileList[0]
            FileMove($folder & "\" & $FileList[$i], $database & "\" & $FileList[$i], 1)
        Next
        addData($FileList)
    EndIf
    sleep(10000)
WEnd

Func addData($FileList)
    Dim $values[$FileList[0] * 2 + 1]
    $sql = _MySQLConnect("root", "", "captured_pictures", "localhost")
    If NOT @error Then
        $index = 1
        For $i = 0 to $FileList[0]
            $values[$i] = @Hour
            $values[$i + 1] = $FileList[$index]
            $i = $i + 2
            $index = $index + 1
        Next
        $values[UBound($values) - 1] = ""
        $error = _AddRecord($sql, 'mytable', $values, $values)
        msgbox(0,"error",$error);0 is error 1 is success DEBUG
        _MySQLEnd($sql)
    EndIf
EndFunc
Either let the For/Next loop increment $i (with Step 2, if necessary) inside the addData() function, or use a While/WEnd loop and increment it yourself, but don't do both. The way you have it, on the first time through the loop $i = 0, you put data in $values[0] and $values[1], then increment $i so it is now 2. On the second loop through, the For/Next loop increments $i = 3, and you set $values[3] and $values[4]. Did you mean to skip $values[2]?

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
SoulA

Yeah I guess not. Let me try and explain further what I'm trying to accomplish. The database has two columns one for a timestamp and the other with picture link. I tried to model my array after the one in this example. here

This code should be much better... but I still don't think I'm doing the add records right.

EDIT: updated some code for more error handling

#Include <File.au3>
#Include <mysql.au3>

Dim $values[3]
$folder = "C:\test"
$database = "C:\test1"

While 1
    $FileList = _FileListToArray($folder, "*", 1)
    If NOT @error Then                              
        $sql = _MySQLConnect("root", "", "captured_pictures", "localhost")
        If NOT @error Then                                              
            For $index = 1 to $FileList[0] step 1
                $values[0] = @Hour
                $values[1] = $FileList[$index]
                $values[2] = ""
                _AddRecord($sql, 'mytable', $values, $values)       ;THIS IS FILE NAME ONLY NOT THE FULL PATH
                If @error Then 
                    ExitLoop
                Else
                    FileMove($folder & "\" & $FileList[$index], $database & "\" & $FileList[$index], 1)
                EndIf
            Next
            _MySQLEnd($sql) 
        EndIf
    EndIf
    sleep(10000)
WEnd
Edited by SoulA

Share this post


Link to post
Share on other sites
SoulA

Any ideas?

Share this post


Link to post
Share on other sites
PsaltyDS

Yeah I guess not. Let me try and explain further what I'm trying to accomplish. The database has two columns one for a timestamp and the other with picture link. I tried to model my array after the one in this example. here

This code should be much better... but I still don't think I'm doing the add records right.

EDIT: updated some code for more error handling

#Include <File.au3>
#Include <mysql.au3>

Dim $values[3]
$folder = "C:\test"
$database = "C:\test1"

While 1
    $FileList = _FileListToArray($folder, "*", 1)
    If NOT @error Then                              
        $sql = _MySQLConnect("root", "", "captured_pictures", "localhost")
        If NOT @error Then                                              
            For $index = 1 to $FileList[0] step 1
                $values[0] = @Hour
                $values[1] = $FileList[$index]
                $values[2] = ""
                _AddRecord($sql, 'mytable', $values, $values);THIS IS FILE NAME ONLY NOT THE FULL PATH
                If @error Then 
                    ExitLoop
                Else
                    FileMove($folder & "\" & $FileList[$index], $database & "\" & $FileList[$index], 1)
                EndIf
            Next
            _MySQLEnd($sql) 
        EndIf
    EndIf
    sleep(10000)
WEnd
I guess that looks OK, but the magic is in the _AddRecord() function, which you didn't post. You could put a MsgBox() or some ConsoleWrite() in there to make sure the right things are passed to that function. After that, it depends on the code in that function.

:P

Edit: I see the MySQL.au3 UDF, which contains _AddRecord(). Your usage matches the example you linked to, but I don't know if that function needs work, and I don't have a MySQL install to test against.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×