storing binary files to mySQL ???

fritz steindl fritz at floSoft.net
Tue Dec 17 07:16:49 EST 2002


On Mon, 16 Dec 2002 19:58:08 +0000, Fredrik Lundh wrote:

> "steindl fritz" <python at floSoft.org> wrote:
> 
>> i try to store pictures in a blob field of mySQL
>>
>>
>>     file = open("c:\\picture.jpg", 'rb')
>>     picture = file.read()
>>
>>     SQL ='INSERT INTO tbl_BLOB (attrName, attrValue) VALUES
>> ("nameOfPicture", ' + picture + ')'
>>
>>     conn = CompatMysqldb.Connection("host", "username", "password",
>>     "db") curs = conn.cursor()
>>     curs.execute(SQL)
> 
> what MySQL module are you using?
> 
> ("python CompatMysql" (without the quotes) is a googlewhack on
> groups.google.com, and returns no hits at all on other parts of google.)
> 
> anyway, in case this is Andy Dustman's version, and nothing else helps,
> you can always import _mysql and use the escape_string function:
> 
>     import _mysql
> 
>     file = open("c:\\picture.jpg", 'rb')
>     picture = _mysql.escape_string(file.read())
> 
> I'm pretty sure there's a better way, but I just un- installed MySQL on
> this box, so I'll have to leave it to someone else to tell you what it
> is.
> 
> </F>


the mySQL module i use is CompatMysqldb.py
sorry for losing the last 2 chars in my text

thx for the rest of hints so far

because i find only _mysql.pyd on the machine, which is not readable, i
will search for any docs on the net, and come back hopefully with the
solution or maybe more questions ...


fritz
(-:fs)



More information about the Python-list mailing list