blob problems in pysqlite

aldonnelley at gmail.com aldonnelley at gmail.com
Wed Apr 26 09:55:08 EDT 2006


Hi there.

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.

Can anyone give me some idea what i'm doing wrong (or if this is indeed
possible)?


Any and all help much appreciated.

Cheers, Al.

#script starts

from pysqlite2 import dbapi2 as sqlite

HTMLoutputFile = open('ImageResults.html', 'wb')
cPickle.dump(OutputHTML, HTMLoutputFile)   # outputHTML is a standard
html page
HTMLoutputFile.close()
DBfilelistFile = open('DBFilesList.txt', 'wb')
cPickle.dump(DBfilelist, DBfilelistFile)   #  DBfileList is a list of
filenames in the form      ['XXX.jpg', 'XXX.jpg' etc]
DBfilelistFile.close()

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

db = sqlite.connect("ImageInfoDatabase.db")

c = db.cursor()

try:
    c.execute("create table FileURLInfo (URL CHAR(100), Images, HTML)")
except:
    print 'database exists'

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  
  
#script ends




More information about the Python-list mailing list