Re: Storing zlib compressed data in a BLOB field
Yi Qiang <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
On Mar 20, 2007, at 11:06 AM, Dennis Lee Bieber wrote: > On Tue, 20 Mar 2007 08:17:08 -0700, Yi Qiang > <[email protected]> declaimed the following > in gmane.comp.python.db.pysqlite.user: > >> Hello, >> I am trying to store a cPickled and then zlib compressed object in a >> BLOB field in my sqlite database. >> This is the relevant line: >> cur.execute(query, (tuple_[1], sqlite3.Binary(tuple_ >> [2]))) >> However, when I try to retrieve it back from the database, it appears >> to be of 'NoneType'. Any idea what might be going wrong? If I do >> not wrap it in sqlite3.Binary, it cuts off part of the data. For >> example if what I put in is "'x\x9ck`\x8a-d\xd4\x03\x00\x06\x07\x01 >> \x80'", what I get out is "'x\x9ck`\x8a-d\xd4\x03'" >> > Well, the truncation looks to be simple to explain... C-standard > null-terminated string behavior... <G> > > As for "NoneType"... From "The Definitive Guide to SQLite" > > """ > * If a column's declared type contains the string 'BLOB' (in uppercase > or lowercase), /or if it has no declared type/, then it is assigned > NONE > affinity. > """ > > So that much *looks* right... Though if the data itself is coming > back as None, that may be strange... > > I've been unable to set up a test case -- my select dies with a > UTF-8 decode error... > Hello Dennis, I figured out the problem shortly after emailing the list. I was simply storing the wrong thing :) As for the UTF-8 error, I simply do this to work around it: self.con.text_factory = str # Don't want unicode objects back where self.con = sqlite3.Connection Cheers, Yi