[z3-checkins] r36219 - z3/sqlos/trunk/src/sqlos

kobold at codespeak.net kobold at codespeak.net
Sun Jan 7 23:16:42 CET 2007


Author: kobold
Date: Sun Jan  7 23:16:41 2007
New Revision: 36219

Modified:
   z3/sqlos/trunk/src/sqlos/adapter.py
   z3/sqlos/trunk/src/sqlos/configure.zcml
Log:
Added support for psycopg2da.


Modified: z3/sqlos/trunk/src/sqlos/adapter.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/adapter.py	(original)
+++ z3/sqlos/trunk/src/sqlos/adapter.py	Sun Jan  7 23:16:41 2007
@@ -148,6 +148,29 @@
         self.supportTransactions = True
 
 
+class Psycopg2Adapter(ConnectionAdapter, _postgres.builder()):
+
+    def __init__(self, connection):
+        #The import is needed, as sqlobject uses self.module.Binary uppon
+        #startup. But until now we dont define .module. There is definitely
+        #need for a better solution. Propably the other adapters need this as
+        #well, but i cant test them, as i dont have them.
+        #Andres Freund - 2005-10-17
+        if getattr(self, 'module', None) == None:
+            import psycopg2
+            self.module = psycopg2
+            #This is needed, because psycopg provides a optimized
+            #Binary() function which sqlobject dont get along with. This is
+            #normally done in sqlobject.postgres.pgconnection __init__ but we
+            #dont call that.
+            from sqlobject.postgres import pgconnection
+            registerConverter(type(psycopg2.Binary('')),
+                              pgconnection.PsycoBinaryConverter)
+
+        super(Psycopg2Adapter, self).__init__(connection)
+        self.supportTransactions = True
+
+
 class SQLiteAdapter(ConnectionAdapter, _sqlite.builder()):
 
     def __init__(self, connection):

Modified: z3/sqlos/trunk/src/sqlos/configure.zcml
==============================================================================
--- z3/sqlos/trunk/src/sqlos/configure.zcml	(original)
+++ z3/sqlos/trunk/src/sqlos/configure.zcml	Sun Jan  7 23:16:41 2007
@@ -105,6 +105,15 @@
         />
   </configure>
 
+  <configure zcml:condition="installed psycopg2da">
+    <adapter
+        provides=".interfaces.IZopeSQLConnection"
+        for="psycopg2da.adapter.IPsycopg2ZopeConnection"
+        permission="zope.Public"
+        factory=".adapter.Psycopg2Adapter"
+        />
+  </configure>
+
   <configure zcml:condition="installed mysqldbda">
     <adapter
         provides=".interfaces.IZopeSQLConnection"


More information about the z3-checkins mailing list