blob problems in pysqlite

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aldonnelley@gmail.com

    #1

    blob problems in pysqlite

    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('ImageResu lts.html', 'wb')
    cPickle.dump(Ou tputHTML, HTMLoutputFile) # outputHTML is a standard
    html page
    HTMLoutputFile. close()
    DBfilelistFile = open('DBFilesLi st.txt', 'wb')
    cPickle.dump(DB filelist, DBfilelistFile) # DBfileList is a list of
    filenames in the form ['XXX.jpg', 'XXX.jpg' etc]
    DBfilelistFile. close()

    DBURL = 'http://www.myhomepage. html'
    blobdata = open('ImageResu lts.html', 'rb').read()
    blobfiles = open('DBFilesLi st.txt', 'rb').read()

    db = sqlite.connect( "ImageInfoDatab ase.db")

    c = db.cursor()

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

    c.execute("INSE RT INTO FileURLInfo VALUES (?,?,?);", (DBURL,
    sqlite.Binary(b lobfiles), sqlite.Binary(b lobdata)),)
    c.execute("sele ct Images from FileURLInfo where URL =
    'http://www.myhomepage. html'",)

    DBImageResult = c.fetchall()
    print DBImageResult

    #script ends

  • Gerhard Häring

    #2
    Re: blob problems in pysqlite

    aldonnelley@gma il.com wrote:[color=blue]
    > 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. [...][/color]

    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

    Comment

    Working...