On Dec 14, 5:41 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 14 Dec 2007 12:19:41 -0300, Hans Müller <[EMAIL PROTECTED]> escribió:
>
> > I cannot read a binary file into a mysql database. Everything I tried  
> > did not succeed.
>
> > What I tried (found from various google lookups...) is this:
>
> > con = MySQLdb.connect(to server)
> > cur = con.cursor()
>
> > cur.execute("insert into data values('file1', %s)", (open("test.jpg",  
> > "rb").read(), ))
>
> Try wrapping the file contents with a Binary object (untested):
>
> data = MySQLdb.Binary(open("test.jpg","rb").read())
> cur.execute("insert into data values('file1', %s)", (data,))
>
> --
> Gabriel Genellina

I was suprised at what I could stick into a MySQL database.  Also, you
might wanna compress the binary for database performance.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to