Author: phd
Date: 2009-09-28 09:18:51 -0600 (Mon, 28 Sep 2009)
New Revision: 4006
Modified:
SQLObject/trunk/docs/News.txt
SQLObject/trunk/docs/SQLObject.txt
SQLObject/trunk/sqlobject/mssql/mssqlconnection.py
SQLObject/trunk/sqlobject/postgres/pgconnection.py
SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
Log:
The "backend" parameter can be a comma-separated list of backend names.
Modified: SQLObject/trunk/docs/News.txt
===================================================================
--- SQLObject/trunk/docs/News.txt 2009-09-28 14:25:16 UTC (rev 4005)
+++ SQLObject/trunk/docs/News.txt 2009-09-28 15:18:51 UTC (rev 4006)
@@ -17,21 +17,23 @@
.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").
- Default is to test pysqlite2, sqlite3 and sqlite in that order.
+ parameter in DB URI or SQLiteConnection that can be a comma-separated
+ list of backend names. Possible backends are: "pysqlite2" (alias
+ "sqlite2"), "sqlite3", "sqlite" (alias "sqlite1"). Default is to test
+ pysqlite2, sqlite3 and sqlite in that order.
* The user can choose a DB API driver for PostgreSQL by using a "backend"
- parameter in DB URI or PostgresConnection. Possible backends are:
- "psycopg2", "psycopg1", "psycopg" (tries psycopg2 and psycopg1),
- "pygresql". Default is "psycopg".
- WARNING: API change! PostgresConnection's parameter "usePygresql" is now
- replaced with "backend=pygresql".
+ parameter in DB URI or PostgresConnection that can be a comma-separated
+ list of backend names. Possible backends are: "psycopg2", "psycopg1",
+ "psycopg" (tries psycopg2 and psycopg1), "pygresql". Default is
+ "psycopg".
+ WARNING: API change! PostgresConnection's parameter
+ "usePygresql" is now replaced with "backend=pygresql".
* The user can choose a DB API driver for MSSQL by using a "backend"
- parameter in DB URI or MSSQLConnection. Possible backends are: "adodb"
- (alias "adodbapi") and "pymssql". Default is to test adodbapi and pymssql
- in that order.
+ parameter in DB URI or MSSQLConnection that can be a comma-separated list
+ of backend names. Possible backends are: "adodb" (alias "adodbapi") and
+ "pymssql". Default is to test adodbapi and pymssql in that order.
* alternateMethodName is defined for all unique fields, not only alternateID;
this makes SQLObject create .by*() methods for all unique fields.
Modified: SQLObject/trunk/docs/SQLObject.txt
===================================================================
--- SQLObject/trunk/docs/SQLObject.txt 2009-09-28 14:25:16 UTC (rev 4005)
+++ SQLObject/trunk/docs/SQLObject.txt 2009-09-28 15:18:51 UTC (rev 4006)
@@ -1734,9 +1734,9 @@
PostgresConnection supports transactions and all other features.
The user can choose a DB API driver for PostgreSQL by using a "backend"
-parameter in DB URI or PostgresConnection. Possible backends are:
-"psycopg2", "psycopg1", "psycopg" (tries psycopg2 and psycopg1),
-"pygresql". Default is "psycopg".
+parameter in DB URI or PostgresConnection that can be a comma-separated
+list of backend names. Possible backends are: "psycopg2", "psycopg1",
+"psycopg" (tries psycopg2 and psycopg1), "pygresql". Default is "psycopg".
SQLite
------
@@ -1753,9 +1753,10 @@
multi-threaded environment.
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"). Default is to
-test pysqlite2, sqlite3 and sqlite in that order.
+parameter in DB URI or SQLiteConnection that can be a comma-separated list
+of backend names. Possible backends are: "pysqlite2" (alias "sqlite2"),
+"sqlite3", "sqlite" (alias "sqlite1"). Default is to test pysqlite2,
+sqlite3 and sqlite in that order.
Firebird
--------
@@ -1846,9 +1847,9 @@
.. _adodbapi: http://adodbapi.sourceforge.net/
The user can choose a DB API driver for MSSQL by using a "backend"
-parameter in DB URI or MSSQLConnection. Possible backends are: "adodb"
-(alias "adodbapi") and "pymssql". Default is to test adodbapi and pymssql
-in that order.
+parameter in DB URI or MSSQLConnection that can be a comma-separated list
+of backend names. Possible backends are: "adodb" (alias "adodbapi") and
+"pymssql". Default is to test adodbapi and pymssql in that order.
Events (signals)
================
Modified: SQLObject/trunk/sqlobject/mssql/mssqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mssql/mssqlconnection.py 2009-09-28 14:25:16 UTC (rev 4005)
+++ SQLObject/trunk/sqlobject/mssql/mssqlconnection.py 2009-09-28 15:18:51 UTC (rev 4006)
@@ -10,18 +10,24 @@
def __init__(self, db, user, password='', host='localhost',
autoCommit=0, **kw):
- backend = kw.pop('backend', None)
- if backend is None:
+ backends = kw.pop('backend', None) or 'adodb,pymssql'
+ for backend in backends.split(','):
+ backend = backend.strip()
+ if not backend:
+ continue
try:
- import adodbapi as sqlmodule
+ if backend in ('adodb', 'adodbapi'):
+ import adodbapi as sqlmodule
+ elif backend == 'pymssql':
+ import pymssql as sqlmodule
+ else:
+ raise ValueError('Unknown MSSQL backend "%s", expected adodb or pymssql' % backend)
except ImportError:
- import pymssql as sqlmodule
- elif backend in ('adodb', 'adodbapi'):
- import adodbapi as sqlmodule
- elif backend == 'pymssql ':
- import pymssql as sqlmodule
+ pass
+ else:
+ break
else:
- raise ValueError('Unknown MSSQL backend "%s", expected adodb or pymssql' % backend)
+ raise ImportError('Cannot find an MSSQL backend, tried %s' % backends)
self.module = sqlmodule
if sqlmodule.__name__ == 'adodbapi':
Modified: SQLObject/trunk/sqlobject/postgres/pgconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/postgres/pgconnection.py 2009-09-28 14:25:16 UTC (rev 4005)
+++ SQLObject/trunk/sqlobject/postgres/pgconnection.py 2009-09-28 15:18:51 UTC (rev 4006)
@@ -13,21 +13,32 @@
def __init__(self, dsn=None, host=None, port=None, db=None,
user=None, password=None, backend='psycopg', unicodeCols=False,
**kw):
- self.backend = backend
- if backend == 'psycopg2':
- import psycopg2 as psycopg
- elif backend == 'psycopg1':
- import psycopg
- elif backend == 'psycopg':
+ backends = kw.pop('backend', None) or 'psycopg'
+ for backend in backends.split(','):
+ backend = backend.strip()
+ if not backend:
+ continue
try:
- import psycopg2 as psycopg
+ if backend == 'psycopg2':
+ import psycopg2 as psycopg
+ elif backend == 'psycopg1':
+ import psycopg
+ elif backend == 'psycopg':
+ try:
+ import psycopg2 as psycopg
+ except ImportError:
+ import psycopg
+ elif backend == 'pygresql':
+ import pgdb
+ self.module = pgdb
+ else:
+ raise ValueError('Unknown PostgreSQL backend "%s", expected psycopg2, psycopg1 or pygresql' % backend)
except ImportError:
- import psycopg
- elif backend == 'pygresql':
- import pgdb
- self.module = pgdb
+ pass
+ else:
+ break
else:
- raise ValueError('Unknown PostgreSQL backend "%s", expected psycopg2, psycopg1 or pygresql' % backend)
+ raise ImportError('Cannot find a PostgreSQL backend, tried %s' % backends)
if backend.startswith('psycopg'):
self.module = psycopg
# Register a converter for psycopg Binary type.
Modified: SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2009-09-28 14:25:16 UTC (rev 4005)
+++ SQLObject/trunk/sqlobject/sqlite/sqliteconnection.py 2009-09-28 15:18:51 UTC (rev 4006)
@@ -22,29 +22,29 @@
schemes = [dbName]
def __init__(self, filename, autoCommit=1, **kw):
- backend = kw.pop('backend', None)
- if backend is None:
+ backends = kw.pop('backend', None) or 'pysqlite2,sqlite3,sqlite'
+ for backend in backends.split(','):
+ backend = backend.strip()
+ if not backend:
+ continue
try:
- from pysqlite2 import dbapi2 as sqlite
- self.using_sqlite2 = True
+ if 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
+ elif backend in ('sqlite', 'sqlite1'):
+ import sqlite
+ self.using_sqlite2 = False
+ else:
+ raise ValueError('Unknown SQLite backend "%s", expected pysqlite2, sqlite3 or sqlite' % backend)
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
- elif backend in ('sqlite', 'sqlite1'):
- import sqlite
- self.using_sqlite2 = False
+ pass
+ else:
+ break
else:
- raise ValueError('Unknown SQLite backend "%s", expected pysqlite2, sqlite3 or sqlite' % backend)
+ raise ImportError('Cannot find an SQLite backend, tried %s' % backends)
if self.using_sqlite2:
sqlite.encode = base64.encodestring
sqlite.decode = base64.decodestring
|