Author: phd
Date: 2009-08-26 10:27:28 -0600 (Wed, 26 Aug 2009)
New Revision: 3967
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
Log:
The user can choose a DB API driver for SQLite by using a "backend" parameter
in DB URI or SQLiteConnection. Possible backends are:
"pysqlite2" (alias "sqlite2"), "sqlite3", "sqlite" (alias "sqlite1").
Modified: SQLObject/trunk/docs/News.txt
===================================================================
--- SQLObject/trunk/docs/News.txt 2009-08-26 16:11:20 UTC (rev 3966)
+++ SQLObject/trunk/docs/News.txt 2009-08-26 16:27:28 UTC (rev 3967)
@@ -16,14 +16,16 @@
* SET client_encoding for PostgreSQL to the value of '?charset=' parameter
in DB URI.
-* Removed deprecated attribute and functions.
-
* alternateMethodName defined for all unique fields, not only alternateID;
this makes SQLObject create by*() methods for all unique fields.
* .selectBy(), .deleteBy() and .by*() methods pass all values through
.from_python(), not only unicode.
+* The user can choose a DB API driver for SQLite by using a "backend"
+ parameter in DB URI or SQLiteConnection. Possible backends are:
+ "pysqlite2" (alias "sqlite2"), "sqlite3", "sqlite" (alias "sqlite1").
+
Small Features
--------------
@@ -31,6 +33,8 @@
in global variables; this allows to use different DB API drivers at the
same time; for example, PySQLite2 and sqlite3.
+* Removed all deprecated attribute and functions.
+
SQLObject 0.11
==============
Modified: SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2009-08-26 16:11:20 UTC (rev 3966)
+++ SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2009-08-26 16:27:28 UTC (rev 3967)
@@ -22,26 +22,37 @@
schemes = [dbName]
def __init__(self, filename, autoCommit=1, **kw):
- try:
- from pysqlite2 import dbapi2 as sqlite
- self.using_sqlite2 = True
- except ImportError:
+ backend = kw.pop('backend', None)
+ if backend is None:
try:
+ from pysqlite2 import dbapi2 as sqlite
+ self.using_sqlite2 = True
+ except ImportError:
+ try:
+ import sqlite3 as sqlite
+ self.using_sqlite2 = True
+ except ImportError:
+ import sqlite
+ self.using_sqlite2 = False
+ elif backend in ('sqlite2', 'pysqlite2'):
+ from pysqlite2 import dbapi2 as sqlite
+ self.using_sqlite2 = True
+ elif backend == 'sqlite3':
import sqlite3 as sqlite
self.using_sqlite2 = True
- except ImportError:
+ elif backend in ('sqlite', 'sqlite1'):
import sqlite
self.using_sqlite2 = False
+ else:
+ raise ValueError('Unknown SQLite backend "%s", expected pysqlite2, sqlite3 or sqlite')
if self.using_sqlite2:
sqlite.encode = base64.encodestring
sqlite.decode = base64.decodestring
self.module = sqlite
self.filename = filename # full path to sqlite-db-file
self._memory = filename == ':memory:'
- if self._memory:
- if not self.using_sqlite2:
- raise ValueError(
- "You must use sqlite2 to use in-memory databases")
+ if self._memory and not self.using_sqlite2:
+ raise ValueError("You must use sqlite2 to use in-memory databases")
# connection options
opts = {}
if self.using_sqlite2:
|