[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/RDB - IDBITypeInfo.py:1.3 IZopeDatabaseAdapter.py:1.4 ZopeConnection.py:1.5 ZopeCursor.py:1.3 ZopeDatabaseAdapter.py:1.6
Albertas Agejevas
alga@codeworks.lt
Mon, 12 Aug 2002 11:07:31 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB
In directory cvs.zope.org:/tmp/cvs-serv12177
Modified Files:
IDBITypeInfo.py IZopeDatabaseAdapter.py ZopeConnection.py
ZopeCursor.py ZopeDatabaseAdapter.py
Log Message:
Changed the type conversion interface, implemented the common infrastructure
=== Zope3/lib/python/Zope/App/RDB/IDBITypeInfo.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/RDB/IDBITypeInfo.py:1.2 Wed Jul 10 19:37:26 2002
+++ Zope3/lib/python/Zope/App/RDB/IDBITypeInfo.py Mon Aug 12 11:07:30 2002
@@ -14,7 +14,8 @@
"""
$Id$
"""
-from Interface import Interface, Attribute
+from Interface import Interface
+from Interface.Attribute import Attribute
class IDBITypeInfo(Interface):
"""Database adapter specific information"""
@@ -46,13 +47,5 @@
variables or other external sources that are beyond your control.
""")
- def getConverter():
- """Return the field type converter."""
-
-
-class IFieldTypeConverter(Interface):
- """Helper object to convert the low-level database output to a meaningful
- type."""
-
- def __getitem__(key):
+ def getConverter(type):
"""Return a converter function for field type matching key"""
=== Zope3/lib/python/Zope/App/RDB/IZopeDatabaseAdapter.py 1.3 => 1.4 ===
--- Zope3/lib/python/Zope/App/RDB/IZopeDatabaseAdapter.py:1.3 Wed Jul 10 19:37:26 2002
+++ Zope3/lib/python/Zope/App/RDB/IZopeDatabaseAdapter.py Mon Aug 12 11:07:30 2002
@@ -14,9 +14,10 @@
"""
$Id$
"""
-from Interface import Interface
+from Zope.App.RDB.IDBITypeInfo import IDBITypeInfo
-class IZopeDatabaseAdapter(Interface):
+
+class IZopeDatabaseAdapter(IDBITypeInfo):
"""Interface for persistent object that returns
volatile IZopeConnections.
=== Zope3/lib/python/Zope/App/RDB/ZopeConnection.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/App/RDB/ZopeConnection.py:1.4 Sat Aug 10 11:58:53 2002
+++ Zope3/lib/python/Zope/App/RDB/ZopeConnection.py Mon Aug 12 11:07:30 2002
@@ -25,9 +25,10 @@
__implements__ = IZopeConnection
- def __init__(self, conn):
+ def __init__(self, conn, typeinfo):
self.conn = conn
self._txn_registered = False
+ self._type_info = typeinfo
def __getattr__(self, key):
# The IDBIConnection interface is hereby implemented
@@ -53,7 +54,7 @@
def getTypeInfo(self):
'See Zope.App.RDB.IDBITypeInfoProvider.IDBITypeInfoProvider'
- # Stubbed for now
+ return self._type_info
#
############################################################
=== Zope3/lib/python/Zope/App/RDB/ZopeCursor.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/RDB/ZopeCursor.py:1.2 Wed Jul 10 19:37:26 2002
+++ Zope3/lib/python/Zope/App/RDB/ZopeCursor.py Mon Aug 12 11:07:30 2002
@@ -37,3 +37,25 @@
def __getattr__(self, key):
return getattr(self.cursor, key)
+
+ def fetchone(self):
+ results = self.cursor.fetchone()
+ return self._convertTypes(results)
+
+ def fetchmany(self, *args, **kw):
+ results = self.cursor.fetchmany(*args, **kw)
+ return self._convertTypes(results)
+
+ def fetchall(self):
+ results = self.cursor.fetchall()
+ return self._convertTypes(results)
+
+ def _convertTypes(self, results):
+ "Perform type conversion on query results"
+ getConverter = self.connection.getTypeInfo().getConverter
+ converters = [getConverter(col_info[1])
+ for col_info in self.cursor.description]
+ def convertRow(row):
+ return map(lambda converter, value: converter(value),
+ converters, row)
+ return map(convertRow, results)
=== Zope3/lib/python/Zope/App/RDB/ZopeDatabaseAdapter.py 1.5 => 1.6 ===
--- Zope3/lib/python/Zope/App/RDB/ZopeDatabaseAdapter.py:1.5 Thu Aug 8 12:55:27 2002
+++ Zope3/lib/python/Zope/App/RDB/ZopeDatabaseAdapter.py Mon Aug 12 11:07:30 2002
@@ -53,7 +53,8 @@
def connect(self):
'See Zope.App.RDB.IZopeDatabaseAdapter.IZopeDatabaseAdapter'
if not self.isConnected():
- self._v_connection = ZopeConnection(self._connection_factory())
+ self._v_connection = ZopeConnection(self._connection_factory(),
+ self)
def disconnect(self):
'See Zope.App.RDB.IZopeDatabaseAdapter.IZopeDatabaseAdapter'
@@ -74,7 +75,20 @@
#
############################################################
+ ############################################################
+ # Implementation methods for interface
+ # Zope.App.RDB.IDBITypeInfo.IDBITypeInfo
+ # Pessimistic defaults
+ paramstyle = 'pyformat'
+ threadsafety = 0
+
+ def getConverter(type):
+ 'See Zope.App.RDB.IDBITypeInfo.IDBITypeInfo'
+ return lambda x: x
+
+ #
+ ############################################################
def parseDSN(dsn):
"""We could have the following cases:
@@ -133,3 +147,9 @@
result['password'] = password
return result
+
+
+
+
+
+