WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Write BLOB to MySQL

 Keywords:  Read Write BLOB Binary MySQL Collect Stream Open Write Read BinaryAllocArray

Question:

I have a 90KB binary string I need to write to a MySQL database. Apparently the "Collect" method that I normally use for text, numbers and dates will not work for BLOBs. How do I go about writing (and later reading) a BLOB?

The BLOB is in the binary buffer FaceTemplate.

 RS5.AddNew()
 RS5.Collect("idImage") = idImage
 RS5.Collect("FaceNumber") = 1
 RS5.Collect("FaceTemplate") = ??????
 RS5.Update()

Answer:

Collect() should work with an ADO Stream. I mostly work with Images but should work the same. I will assume you will do the opening of the recordset for the read...I've used "myREC" and the field name is "blobject". The Read will leave you with a Binary Buffer so you can do what you want with that. The Write ends with the SQLText. I'll leave the execution of that to you.

The Read:

 AStream.Open()
 AStream.Write( myREC.Collect("blobject") )
 AStream.Position=0
 ssize = AStream.Size 
 btxt = AStream.Read(-1)
 bb = BinaryAllocArray(btxt)
 bbh = IntControl(42,bb,0,0,0)
 AStream.close()

The Write:

 fs=Filesize(sfile)
 ;binary data is converted to HEX for inserts
 binbuf = BinaryAlloc(fs+1000)
 BinaryRead(binbuf, sfile)
 stxt=BinaryPeekHex( binbuf, 0, BinaryEodGet(binbuf))
 BinaryFree(binbuf)

 SQLText = "update images set blobject = X'":stxt:"' where isbn = '":isbn:"';"
Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP/ADO~DAO+ADO~Stream~to~Binary~Buffer.txt

Hope this helps.


Article ID:   W18043
Filename:   Write BLOB to MySQL.txt
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38