[z3-checkins] r32625 - z3/sqlos/branch/kobold-sqlos/src/sqlos

kobold at codespeak.net kobold at codespeak.net
Mon Sep 25 12:20:14 CEST 2006


Author: kobold
Date: Mon Sep 25 12:20:14 2006
New Revision: 32625

Modified:
   z3/sqlos/branch/kobold-sqlos/src/sqlos/adapter.py
Log:
Added adapter for psycopg2.


Modified: z3/sqlos/branch/kobold-sqlos/src/sqlos/adapter.py
==============================================================================
--- z3/sqlos/branch/kobold-sqlos/src/sqlos/adapter.py	(original)
+++ z3/sqlos/branch/kobold-sqlos/src/sqlos/adapter.py	Mon Sep 25 12:20:14 2006
@@ -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):


More information about the z3-checkins mailing list