dabo Commit
Revision 3106
Date: 2007-05-07 11:24:32 -0700 (Mon, 07 May 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3106
Changed:
U trunk/dabo/db/dBackend.py
U trunk/dabo/db/dConnectInfo.py
U trunk/dabo/db/dConnection.py
U trunk/dabo/db/dbFirebird.py
U trunk/dabo/db/dbMsSQL.py
U trunk/dabo/db/dbMySQL.py
U trunk/dabo/db/dbOracle.py
U trunk/dabo/db/dbPostgreSQL.py
U trunk/dabo/db/dbSQLite.py
U trunk/dabo/db/dbTemplate.py
Log:
Added the option of passing additional keyword arguments to the connection. It
has been tested with MySQL enough to know that existing apps will not crash due
to these changes. I haven't tested the behavior when passing in additional
parameters, so please test ASAP.
Diff:
Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dBackend.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -52,7 +52,7 @@
return False
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
""" override in subclasses """
return None
Modified: trunk/dabo/db/dConnectInfo.py
===================================================================
--- trunk/dabo/db/dConnectInfo.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dConnectInfo.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -94,8 +94,8 @@
raise TypeError, "Property '%s' invalid." % k
- def getConnection(self):
- return self._backendObject.getConnection(self)
+ def getConnection(self, **kwargs):
+ return self._backendObject.getConnection(self, **kwargs)
def getDictCursorClass(self):
Modified: trunk/dabo/db/dConnection.py
===================================================================
--- trunk/dabo/db/dConnection.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dConnection.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -28,20 +28,24 @@
self._connectInfo = dConnectInfo(connInfo=connectInfo)
else:
raise TypeError, "dConnectInfo instance or kwargs not
sent."
- self._connection = self._openConnection()
+ self._connection = self._openConnection(**kwargs)
def getConnection(self):
return self._connection
+
def close(self):
self._connection.close()
+
def getDictCursorClass(self):
return self._connectInfo.getDictCursorClass()
+
def getCursor(self, cursorClass):
return self.getBackendObject().getCursor(cursorClass)
+
def getDaboCursor(self, cursorClass=None):
""" Accepts a backend-specific cursor class, mixes in the Dabo
@@ -64,9 +68,10 @@
return crs
- def _openConnection(self):
+ def _openConnection(self, **kwargs):
""" Open a connection to the database and store it for future
use. """
- return self._connectInfo.getConnection()
+ return self._connectInfo.getConnection(**kwargs)
+
def getBackendObject(self):
""" Return a reference to the connectInfo's backend-specific
@@ -74,18 +79,26 @@
"""
return self._connectInfo.getBackendObject()
+
def _getConnInfo(self):
return self._connectInfo
+
def _getName(self):
try:
return self.ConnectInfo.Name
except:
return "?"
+
- ConnectInfo = property(_getConnInfo, None, None, _("The connectInfo for
the connection. (class)"))
- Name = property(_getName, None, None, _("The name of the connection."))
+ ConnectInfo = property(_getConnInfo, None, None,
+ _("The connectInfo for the connection.
(dConnectInfo)"))
+
+ Name = property(_getName, None, None,
+ _("The name of the connection. (str)"))
+
+
if __name__ == "__main__":
from dConnectInfo import dConnectInfo
ci = dConnectInfo(DbType="MySQL")
Modified: trunk/dabo/db/dbFirebird.py
===================================================================
--- trunk/dabo/db/dbFirebird.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbFirebird.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -38,7 +38,7 @@
self.dbapi = kinterbasdb
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
port = connectInfo.Port
if not port:
port = 3050
@@ -49,7 +49,7 @@
database = str(connectInfo.Database)
self._connection = self.dbapi.connect(host=host, user=user,
- password=password, database=database)
+ password=password, database=database, **kwargs)
return self._connection
Modified: trunk/dabo/db/dbMsSQL.py
===================================================================
--- trunk/dabo/db/dbMsSQL.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbMsSQL.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -15,7 +15,7 @@
import pymssql
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
"""The pymssql module requires the connection be created for
the FreeTDS libraries first. Therefore, the
DSN is really the name of the connection for FreeTDS
__init__(self, dsn, user, passwd, database = None, strip =
0)"""
@@ -32,7 +32,8 @@
# hack to make this work. I am sure there is a better way.
self.database = database
- self._connection = pymssql.connect(host=host,
user=user,password=password, database=database)
+ self._connection = pymssql.connect(host=host, user=user,
password=password,
+ database=database, **kwargs)
return self._connection
Modified: trunk/dabo/db/dbMySQL.py
===================================================================
--- trunk/dabo/db/dbMySQL.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbMySQL.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -20,7 +20,7 @@
self.dbModuleName = "MySQLdb"
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
import MySQLdb as dbapi
port = connectInfo.Port
@@ -45,10 +45,8 @@
try:
self._connection = dbapi.connect(host=connectInfo.Host,
- user = connectInfo.User,
- passwd = connectInfo.revealPW(),
- db=connectInfo.Database,
- port=port, **kwargs)
+ user = connectInfo.User, passwd =
connectInfo.revealPW(),
+ db=connectInfo.Database, port=port,
**kwargs)
except Exception, e:
if "access denied" in str(e).lower():
raise dException.DBNoAccessException(e)
Modified: trunk/dabo/db/dbOracle.py
===================================================================
--- trunk/dabo/db/dbOracle.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbOracle.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -34,7 +34,7 @@
self.dbModuleName = "???"
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
#### TODO: replace 'ZZZ' with dbapi module name
import ZZZ as dbapi
@@ -45,10 +45,8 @@
#### TODO: Customize to make correct connect string
self._connection = dbapi.connect(host=connectInfo.Host,
- user = connectInfo.User,
- passwd = connectInfo.revealPW(),
- db=connectInfo.Database,
- port=port)
+ user = connectInfo.User, passwd =
connectInfo.revealPW(),
+ db=connectInfo.Database, port=port, **kwargs)
return self._connection
Modified: trunk/dabo/db/dbPostgreSQL.py
===================================================================
--- trunk/dabo/db/dbPostgreSQL.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbPostgreSQL.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -17,7 +17,7 @@
self.conn_user = ''
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
import psycopg2 as dbapi
#from pyPgSQL import PgSQL as dbapi
self.conn_user = connectInfo.User
@@ -28,6 +28,8 @@
DSN = "host=%s port=%s dbname=%s user=%s password=%s" %
(connectInfo.Host,
port, connectInfo.Database, connectInfo.User,
connectInfo.revealPW())
+ for kw, val in kwargs:
+ DSN += " %s=%s" % (kw, val)
self._connection = dbapi.connect(DSN)
return self._connection
Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbSQLite.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -20,7 +20,7 @@
self._alreadyCorrectedFieldTypes = True
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
## Mods to sqlite to return DictCursors by default, so that
dCursor doesn't
## need to do the conversion:
dbapi = self.dbapi
Modified: trunk/dabo/db/dbTemplate.py
===================================================================
--- trunk/dabo/db/dbTemplate.py 2007-05-07 17:03:23 UTC (rev 3105)
+++ trunk/dabo/db/dbTemplate.py 2007-05-07 18:24:32 UTC (rev 3106)
@@ -35,7 +35,7 @@
self.dbModuleName = "???"
- def getConnection(self, connectInfo):
+ def getConnection(self, connectInfo, **kwargs):
#### TODO: replace 'ZZZ' with dbapi module name
import ZZZ as dbapi
@@ -46,10 +46,8 @@
#### TODO: Customize to make correct connect string
self._connection = dbapi.connect(host=connectInfo.Host,
- user = connectInfo.User,
- passwd = connectInfo.revealPW(),
- db=connectInfo.Database,
- port=port)
+ user=connectInfo.User,
passwd=connectInfo.revealPW(),
+ db=connectInfo.Database, port=port, **kwargs)
return self._connection
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]