4

I have an application that needs to support Python 2.4 and 2.6. With 2.6, sqlite3 replaces sqlite. Is there much else I need to worry about other than paramstyle differences? Is this a decent way of handling that?

try:
    import sqlite3 as sqlite
except ImportError:
    import sqlite

...

if sqlite.paramstyle == 'qmark':
    query = 'SELECT foo FROM bar where baz = ?'
else:
    query = 'SELECT foo FROM bar where baz = %s'
cursor.execute(query, params)

1 Answer 1

7

On python 2.4, use the pysqlite package. This is the exact same package that was added to the Python standard library in version 2.5, when it was renamed to sqlite3.

As it is the same package, there are no differences in the API, and you only have to use a try except ImportError test:

try:
    import sqlite3
except ImportError:
    from pysqlite2 import dbapi2 as sqlite3
Sign up to request clarification or add additional context in comments.

1 Comment

That certainly makes it a bit simpler to maintain. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.