blob problems in pysqlite

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Apr 26 10:36:03 EDT 2006


[aldonnelley at gmail.com]

| I'm a long-time lurker and (I think) first time poster.
| Only relatively new to python, and I'm trying to get pysqlite to work
| with binary data, and having a tough time of it.
| I want to set up a table with:
| - a URL,
| - some filenames related to that URL,
| - and some simple generated HTML.
| 
| Problem is, when I try to do this, and query, say, the filenames from
| the filename field 'Images', I'm not getting a result. Just []...
|  I've been googling this one for days (documentation for this seems
| really scant), and I've tried a whole bunch of things, but my code as
| it is now is attached.

Just to confirm, I slightly reformatted your
code so that it would run without your data,
guessing from your comments what the input
data would be, and it ran fine. I'm a little
bemused at the way you're doing things, but as
Gerhard said elsewhere, you don't seem to be
doing anything wrong.

<code>
import cPickle
from pysqlite2 import dbapi2 as sqlite

#
# TJG: Added sample inputs, hopefully representative
#

# outputHTML is a standard html page
OutputHTML = "<html><body></body></html>"
#  DBfileList is a list of filenames in the form ['XXX.jpg', 'XXX.jpg'
etc]
DBfilelist = ['xxx.jpg', 'yyy.jpg']

HTMLoutputFile = open('ImageResults.html', 'wb')
cPickle.dump(OutputHTML, HTMLoutputFile)
HTMLoutputFile.close()

DBfilelistFile = open('DBFilesList.txt', 'wb')
cPickle.dump(DBfilelist, DBfilelistFile)   
DBfilelistFile.close()

DBURL = 'http://www.myhomepage.html'
blobdata = open('ImageResults.html', 'rb').read()
blobfiles = open('DBFilesList.txt', 'rb').read()

#
# TJG: Used :memory: db to simplify slightly
#
db = sqlite.connect(":memory:")

c = db.cursor()
c.execute("create table FileURLInfo (URL CHAR(100), Images, HTML)")

c.execute("INSERT INTO FileURLInfo VALUES (?,?,?);", (DBURL,
sqlite.Binary(blobfiles), sqlite.Binary(blobdata)),)
c.execute("select Images from FileURLInfo where URL =
'http://www.myhomepage.html'",)

DBImageResult = c.fetchall()
print DBImageResult  

</code>

gives me:

[(<read-write buffer ptr 0x00AD47D8, size 36 at 0x00AD47B8>,)]

Can you clarify a bit, give some sample of your data, etc?
TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list