how to store binary file data to a database blob

David Stockwell winexpert at hotmail.com
Thu May 27 10:56:40 EDT 2004


Hi,

I'd like to read the contents of a file into memory.  The problem is that 
this file is binary.  I then want to store the whole thing in memory to a 
database as a blob.
I have no problem reading from a file:  I did this:

import os
f = open('/bin/ls' , 'r+b')
data = f.read()
f.close()

How do I place that in a blob?   If I concatenate this to a sql string, how 
will the database sql parser know where my data string ends, knowing that my 
data string could contain lots of ' and " and other little things in it. ???

storeString = "insert into mytable (filedata) values ( %s ) " % data

Does that look right?  I don't think it would execute correctly.

Thanks


David Stockwell
-------
Cell: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE 
download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/





More information about the Python-list mailing list