Sign in to follow this  
Followers 0
billym

MySQL & Blob Help!

4 posts in this topic

Can someone please help... I am having problems determining where the problem is in my code...

(MyODBC is required)

The problem I am having is the adding of the files to the db. It throws errors and adds the record without the binary data.

I have tested the ability to both read and write and everything seems to work but the binary part.

1) Created MySQL db called 'testdb'

2) Created db user name: joe pass: blo

3) Logged in as joe and executed this script against the testdb:

CREATE TABLE files(

file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,

file_name VARCHAR(64) NOT NULL,

file_size MEDIUMINT UNSIGNED NOT NULL,

file MEDIUMBLOB NOT NULL);

4) Created script to add record to db:

CreateRecord.au3

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

$ado = ObjCreate( "ADODB.Connection" )

$adoRS = ObjCreate( "ADODB.RecordSet" )

$ado.Open( "DRIVER={MySQL ODBC 3.51 Driver};SERVER=SERVERIPGOESHERE;DATABASE=testdb;USER=joe;PASSWORD=blo;OPTION=1 + 2 + 8 + 32 + 2048 + 16384;" )

$adoRS.CursorType = 2

$adoRS.LockType = 3

$adoRS.Open( " Select * from files", $ado )

$oStream = ObjCreate( "ADODB.Stream")

$adoRS.AddNew

$oStream.Type=1

$oStream.Open

$var = FileOpenDialog("Locate Image", "C:\", "Images (*.jpg;*.bmp;*.tif)", 1)

$oStream.LoadFromFile = $var

$adoRS.Fields("file_name").Value = 'filenametest.tif'

$adoRS.Fields("file_size").Value = $oStream.size

$adoRS.Fields("file").Value = $oStream.read

$adoRS.Update

$adoRS.Close

$ado.Close

Func MyErrFunc()

$HexNumber=hex($oMyError.number,8)

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

"err.description is: " & @TAB & $oMyError.description & @CRLF & _

"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _

"err.number is: " & @TAB & $HexNumber & @CRLF & _

"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _

"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _

"err.source is: " & @TAB & $oMyError.source & @CRLF & _

"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _

"err.helpcontext is: " & @TAB & $oMyError.helpcontext _

)

SetError(1) ; to check for after this function returns

Endfunc

5) Created script to read records from db:

ReadRecords.au3

$ado = ObjCreate( "ADODB.Connection" )

$adoRS = ObjCreate( "ADODB.RecordSet" )

$ado.Open( "DRIVER={MySQL ODBC 3.51 Driver};SERVER=SERVERIPGOESHERE;DATABASE=testdb;USER=joe;PASSWORD=blo;OPTION=1 + 2 + 8 + 32 + 2048 + 16384;" )

$adoRS.CursorType = 2

$adoRS.LockType = 3

$adoRS.Open( " Select * from files", $ado )

While not $adoRS.EOF

MsgBox(4096, "Database", $adors.Fields( "file_size" ).Value, 5)

$adoRS.MoveNext

WEnd

Share this post


Link to post
Share on other sites



Any help would be appreciated...(Anxiously want to figure out!)

Share this post


Link to post
Share on other sites

bump :">

Share this post


Link to post
Share on other sites

bump :">

Sorry I don't know the syntax for this SQL;

You could use the workaround in AoutIT, example in last link in my signature. [uses binary string udf too, so you can dislay that field as text in GUI without resorting t binary save]

SQLcreateTableInsertRecord.au3

best, Randall!

(I'll be interested to hear if you work out the syntax...)

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