BLOBS and python

sp00fD sp00fd at my-deja.com
Thu May 4 15:28:21 EDT 2000


I'm trying to insert an image as a blob, but unless I escape any quotes
("') within it, it seems to puke.  The problem is, it's an image and if
I escape the quotes, I change the image.  How can I do this?

import cgi
import MySQLdb
query = cgi.FieldStorag()
image = query["filename"].value

c = MySQLdb.connect(...)
con = c.cursor()
con.execute("INSERT INTO foo (myblob) VALUES ('%s')" % image)

The above doesn't work unless I do something like this first:
import re
matchstr = re.compile(r"""["\']""")
image = matchstr.sub(r"\\1", image)

Thanks


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list