Hi
2010/6/15 Roger Binns <[email protected]>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 06/15/2010 01:46 PM, Fabio Spadaro wrote:
> > I am developing an interface to Python 's SQLite and would it be
> > you can store files in the sqlite database. To do this
> > obviously need to create a blob field but how to store image files?
>
> If you are using Python 2 then use the buffer type. If using Python 3 then
> use bytes.
>
> Py2:
>
> cursor.execute("insert into foo(image) values(?)",
> (buffer(open(".../foo.jpg", "rb").read()), ))
>
> Py3:
>
> cursor.execute("insert into foo(image) values(?)",
> (open(".../foo.jpg", "rb").read(), ))
>
>
> If you use APSW then you can also use the incremental blob API:
>
> http://apsw.googlecode.com/svn/publish/blob.html
>
> Roger
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkwX7yAACgkQmOOfHg372QSIkQCfej/1Zw7htLxZtVFGsIsxb91m
> YnkAniPp7aScNJITD3xYOmH4MC9e4Asx
> =M6pK
> -----END PGP SIGNATURE-----
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
I created the table:
CREATE TABLE blobber(file BLOB)
I inserted 2 records:
1. gestdb.cur.execute("insert into blobber(file) values(?)",
(buffer(open('..\conf\img\file1.gif','rb').read()), ))
2. gestdb.cur.execute("insert into blobber(file) values(?)",
(buffer(open('..\conf\img\file2.gif','rb').read()), ))
But the next time I select a single line instead of two:
fetchall [(<read-write buffer ptr 0x0000000002CC2A68, size 1311 at
0x0000000002CC2A30>,)]
What's wrong.
--
Fabio Spadaro
www.fabiospadaro.com
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users