Support for sqlite and sqlite3

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

 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) 
+4
source share
1 answer

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

Since this is the same package, there are no differences in the API, and you only need to use the try except ImportError :

 try: import sqlite3 except ImportError: from pysqlite2 import dbapi2 as sqlite3 
+6
source

Source: https://habr.com/ru/post/1444152/


All Articles