[z3-checkins] r18713 - z3/sqlos/trunk

andres at codespeak.net andres at codespeak.net
Mon Oct 17 12:19:41 CEST 2005


Author: andres
Date: Mon Oct 17 12:19:40 2005
New Revision: 18713

Modified:
   z3/sqlos/trunk/adapter.py
Log:
Slightly optimized the adapters due not importing the database module every request.
Made a fix to the PostgresAdapter (Use an own BinaryConverter)

Modified: z3/sqlos/trunk/adapter.py
==============================================================================
--- z3/sqlos/trunk/adapter.py	(original)
+++ z3/sqlos/trunk/adapter.py	Mon Oct 17 12:19:40 2005
@@ -14,6 +14,8 @@
 
 from sqlobject.dbconnection import DBAPI
 from sqlobject import _mysql, _postgres, _sybase, _sqlite
+from sqlobject.converters import registerConverter
+
 from sqlos.interfaces import ISQLObject
 from sqlos.transaction import SQLObjectTransactionManager
 
@@ -21,6 +23,7 @@
 from zope.app.container.interfaces import INameChooser
 
 
+
 class SQLObjectNameChooser:
 
     def __init__(self, context):
@@ -70,8 +73,18 @@
         #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
-        import psycopg
-        self.module=psycopg
+        if getattr(self,'module',None) == None:
+            import psycopg
+            self.module=psycopg
+            #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.
+            import sqlobject.postgres.pgconnection
+            registerConverter(type(psycopg.Binary('')),
+                              sqlobject.postgres.pgconnection.PsycoBinaryConverter)
+            
+
         super(PostgresAdapter, self).__init__(connection)
         self.supportTransactions = True
 
@@ -79,7 +92,8 @@
 class SQLiteAdapter(ConnectionAdapter, _sqlite.builder()):
     def __init__(self, connection):
         #see above
-        import sqlite
-        self.module  = sqlite
+        if getattr(self,'module',None) == None:
+            import sqlite
+            self.module  = sqlite
         super(SQLiteAdapter, self).__init__(connection)
         self.supportTransactions = True


More information about the z3-checkins mailing list