Re: Pysqlite storing file as blob example
- From: Carsten Haese <carsten@xxxxxxxxxxx>
- Date: Tue, 31 Jul 2007 08:49:26 -0400
On Tue, 2007-07-31 at 00:13 -0700, 7stud wrote:
On Jul 30, 6:25 pm, rustyhow...@xxxxxxxxx wrote:
I'm trying to store binary data in a sqlite database and call into the
db using pysqlite 3.
What I've got so far is this:
import sqlite
con = sqlite.connect(DB_PATH)
cur = con.cursor()
query = """create table t1(
ID INTEGER PRIMARY KEY,
data BLOB );"""
cur.execute(query)
con.commit()
b = buffer('/path/to/binary/file')
buffer() ?
Using buffer is not in itself wrong, as some DB-API modules, including
sqlite3, do use buffer objects to encapsulate binary data. However, the
encapsulation should be called in a portable way by using the standard
Binary factory function: b = sqlite3.Binary(contents).
What is wrong, though, is passing the filename into it instead of the
contents. This is in addition to the wrong execute call and using the
wrong version of the sqlite module, as I pointed out in my previous
reply.
--
Carsten Haese
http://informixdb.sourceforge.net
.
- References:
- Pysqlite storing file as blob example
- From: rustyhowell
- Re: Pysqlite storing file as blob example
- From: 7stud
- Pysqlite storing file as blob example
- Prev by Date: Re: Why no maintained wrapper to Win32?
- Next by Date: Re: Why no maintained wrapper to Win32?
- Previous by thread: Re: Pysqlite storing file as blob example
- Next by thread: Where can I get a complete user interface about pylibpcap?
- Index(es):