Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I save raw, binary data to MySQL

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a long string of 15,000 characters. Rather than save this to the MySQL DB, I have a VB routine which uses ZLib compression to compact it down to 1,000 (approx) bytes. My problem is, is that the compression result is NOT an ascii character string, but raw binary data. How can I save this to the MySQL DB?

If I compress it to a string...

Dim str as String
str = CompressToString(strLongString)

... then the SQL Insert statement doesn't work. I believe it's because it must have some strange characters that distrupt the SQL string since I can't even display the "str" variable fully to a textbox. So after doing some research, I found that maybe I need to compress it to a Byte array (which holds raw binary data) and insert that into a BLOB field type. So at this point, I've got the array with...

Dim ByteArray() As Byte
ByteArray = CompressToByteArray(strLongString)

... however, I can't figure out the SQL query syntax necessary for inserting this Byte Array into the BLOB field in the MySQL DB. (Much less retrieve it, which I need to do also). So can anyone tell me if I'm on the right track? If so, how can I insert that ByteArray into the DB?

If anyone can help me out, I'll buy you a Porshe. Well, OK, maybe not since I can only afford a Taurus, but you'll have the satisfaction of being my new hero if you can help me out with this! :)
 
please excuse me if I am wrong, but I am still learning the ins and outs of storing binaries in MySQL also.

It appears to me that a binary is stored as a string (either TEXT or BLOB). Before you can store a sting into the database, you have to mark all of the escape characters with a backslash '\'. In PHP this is accomplished with the function addslashes(). You may have to do the same within VB. I am not aware of any preset VB function that allows you to do this, but I rarely use VB and consider myself a novice on this language.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top