MYSQL and use of blobs

Jaco Smuts JSmuts at clover.co.za
Thu Jul 29 10:01:54 EDT 2004


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/20040729/8ce9de4d/attachment.html>


More information about the Python-list mailing list