blob problems in pysqlite
Gerhard Häring
gh at ghaering.de
Thu Apr 27 04:43:42 EDT 2006
aldonnelley at gmail.com wrote:
> Excellent. Got that working. Now, how to get the pickled data out of
> the database?
>
> I'm trying to use cPickle.loads(data) (code attached), and I get a:
> "TypeError: loads() argument 1 must be string, not list" [...]
> [...]
> c.execute("select Images from FileURLInfo where URL= ?;", (DBURL,))
> KnownFilesResult = c.fetchall()
> print KnownFilesResult #where I get a r/w buffer, as expected
No, you actually get a list of 1-tuples and each tuple has one entry: a
read-write buffer. Because of the way you filled the table, the list is
of length 1.
> cPickle.loads(KnownFilesResult) #where I get the error described
> above.
cPickle.loads will only accept a string, not a buffer, so you need to
convert the buffer to a string first.
So, if you want your code to work, you can use
print cPickle.loads(str(KnownFilesResult[0][0]))
FWIW there are certainly much better ways to solve the task you're
solving here. Because right now you're pickling and unpickling data into
a single table in a relational database. Like you're doing this, this
buys you nothing *and* you get the complexity of relational databases
and object (de)marshaling.
If you want to go the relational way, you can create multiple tables and
using foreign-key relations between them instead of stuffing lists into
columns of a single table by pickling them.
I've attached an example script that can perhaps inspire you.
-- Gerhard
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image_schema.py
Type: text/x-python
Size: 1500 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20060427/d9bd2c9e/attachment.py>
More information about the Python-list
mailing list