Again: MYSQL and use of blobs. HELP!!

Raaijmakers, Vincent (GE Infrastructure) Vincent.Raaijmakers at ge.com
Fri Jul 30 08:53:53 EDT 2004


Using the latest MySQLdb, python 2.3.4 on Linux, I just can't get the behavior I want.
I can store my  jpg image in the blob  using the SQL "INSERT INTO aTable image VALUES %r"
Reading out is also not the problem, I get an array {'c', 'xffxadx0d......}
 
However, the array.tostring() still show the chars xffx0d..... This whole string doesn't look like the original image data that I stored into the blob.
 
Please help. What step is missing here?
My Java friends are already laughing at me. They got it all working, grrrrr...
 
Vincent
 

-----Original Message-----
From: Jaco Smuts [mailto:JSmuts at clover.co.za]
Sent: Thursday, July 29, 2004 10:02 AM
To: Raaijmakers, Vincent (GE Infrastructure)
Cc: python-list at python.org; python-list-bounces+jsmuts=clover.co.za at python.org
Subject: Re: MYSQL and use of blobs



Hello there 

I've recently done this. Using the latest version of mysqldb really simplified this. 

had to go back to google to find this:--------------------------------------------------------------------- 


Depending on your version of MySQLdb, you can do this on newer versions:

sql = "INSERT INTO sometable (col1, col2) VALUES (%s, %s)"
cursor.execute(sql, (val1, val2))


On older versions of MySQLdb, you have to use escape_string() to properly escape the string.

sql = "INSERT INTO sometable (col1, col2) VALUES (%s, %s)"
cursor.execute(sql, (MySQLdb.escape_string(val1), MySQLdb.escape_string(val2)) 

---------------------------------------------------------------------------------------------------------------------------------- 
on the followingn link... 

http://forums.devshed.com/archive/t-116913 


jaco 







	"Raaijmakers, Vincent (GE Infrastructure)" <Vincent.Raaijmakers at ge.com> 
Sent by: python-list-bounces+jsmuts=clover.co.za at python.org 


07/29/2004 03:48 PM 

        
        To:        <python-list at python.org> 
        cc:         
        Subject:        MYSQL and use of blobs



It is the first time that I use blobs in mysql.
Please help me out here.....

Using MSSQLdb and python 2.3.4 I was surprised to see how my information was stored in the blob.
My goal is to store JPG images in the blob. Well, it stores it but as a string of bytes:
'x0dx0fxffxa3......'

So, when reading back that information into my python environment, it seems that I need to translate the value back to the original binary format?

Sniffed for an hour in the asciibin, binhex and other modules...

Somebody with experience to help me out here?
Is there something fundamentally that I do wrong here? In storage, retreiving...

Any help would be very appreciated.
Vincent
-- 
http://mail.python.org/mailman/listinfo/python-list



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040730/d21acbd7/attachment.html>


More information about the Python-list mailing list