update images inside a mysql database

Gabriel Cooper gabriel.cooper at mediapulse.com
Thu Feb 24 13:01:15 EST 2005



Jonas Meurer wrote:

>def i_update(image, imgid):
>        image = "%s" % (image)
>        sql_exec = """UPDATE Images SET Image='%s' WHERE ImgID = '%s'
>                """ % (image, imgid)
>        o = open("/tmp/file.jpg", "w")
>        o.write(image)
>        o.close()
>        db_connect.cursor.execute(sql_exec)
>
I've never tried extensively to use images inside a database (too slow 
for most of my uses), but I thought I'd drop in to point out that you 
should, for security reasons, be using place holders on your sql. It 
might just fix your image problem as well, but I don't know. Also, 
converting a binary image into a string doesn't seem like it would be 
wise, but like I said, I've never tried it. At any rate, your function 
would look like this:

def i_update(image, imgid):
        image = "%s" % (image)
        o = open("/tmp/file.jpg", "w")
        o.write(image)
        o.close()
        db_connect.cursor.execute("""UPDATE Images SET Image=%s WHERE ImgID=%s""", 
				  (image, imgid))





More information about the Python-list mailing list