Re: problem with upgrade 1.1 -> 2.3

Gerhard Häring <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Niki Spahiev wrote:
> Hello,
> 
> I can't find proper way of handling BLOB records saved with pysqlite
> 1.1.7. When i read them with 2.3.2 i got garbage.
> 
> Attached test shows the problem. [...]

Attached is a solution for your problem.

-- Gerhard

_______________________________________________
pysqlite mailing list
pysqlite-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/pysqlite
upgradeblob.py (text/x-python, 850 B)
import sqlite as sqlite1
from pysqlite2 import dbapi2 as sqlite2
import os

sqlite2.enable_callback_tracebacks(True)

DBFILE = "db"

TESTDATA = "foo" + chr(0) + "bar"

def pysqlite1bin_to_pysqlite2_bin(x):
    return buffer(sqlite1.decode(str(x)))

# Create test data with pysqlite 1.1
if os.path.exists(DBFILE):
    os.remove(DBFILE)
con = sqlite1.connect(DBFILE)
cur = con.cursor()
cur.execute("create table test(b)")
cur.execute("insert into test(b) values (%s)", (sqlite1.Binary(TESTDATA),))
con.commit()
con.close()

# Connect with pysqlite2 and upgrade BLOB column
con = sqlite2.connect(DBFILE)
con.create_function("convert", 1, pysqlite1bin_to_pysqlite2_bin)
cur = con.cursor()
cur.execute("update test set b=convert(cast(b as blob))")

# Test the upgrade procedure
cur.execute("select b from test")
assert str(cur.fetchone()[0]) == TESTDATA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.