blob problems in pysqlite

A

aldonnelley

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
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

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. [...]

It seems to me that you're using pysqlite correctly. Where exactly is
the problem? Is the fetchall() not delivering what you think it should?
If so, please explain what exactly it yields, and what you expect it to
yield.

-- Gerhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top