I ran into some odd behavior from older versions of SQLite, and I
wonder if anyone can add some details and help me find a good
workaround.

The details are at http://trac.buildbot.net/ticket/1810.  With
apologies for boiling this down to Python:

import os
import sqlite3

print "sqlite.py:", sqlite3.version
print "sqlite itself:", sqlite3.sqlite_version

if os.path.exists("/tmp/my.db"):
        os.unlink("/tmp/my.db")

def combined():
        conn1 = sqlite3.connect("/tmp/my.db")
        curs1 = conn1.cursor()
        print "1: pragma" ## B
        curs1.execute("PRAGMA table_info('foo')")

        conn2 = sqlite3.connect("/tmp/my.db")
        curs2 = conn2.cursor()
        print "2: create"
        curs2.execute("CREATE TABLE foo ( a integer )")
        conn2.commit()
        conn2.close() ## C

        print "1: select"
        # curs1.execute("SELECT * from sqlite_master") ## A
        curs1.execute("SELECT * from foo")

combined()

This script fails for sqlite-3.6.12 and earlier, and works for
sqlite-3.6.17 and higher.  If I add a query of sqlite_master (A),
things work.  Remove the PRAGMA (B) and things work.  Adding or
removing the close() (C) makes no difference.

This is a part of Buildbot (http://buildbot.net), and older versions
of SQLite are still present on lots of common systems, so I can't
substantially change the required version of SQLite without alienating
a lot of users.

My workaround is to run the above at startup, and if I get an
OperationalError, run 'SELECT * from sqlite_master' before each real
query.  Obviously, that's not great for performance, but I don't
understand the underlying problem well enough to invent something
better.

I'd love to have a pointer to the bug that was solved here (I had a
look through the tracker, but didn't see anything related) as well as
the version in which it was solved.  I'd also love to know what's
going on - per-connection caching of schema metadata?  Finally, any
suggestions for a better workaround would be great.

TIA!
Dustin
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to