[Checkins] SVN: Products.SQLAlchemyDA/trunk/da.py added logging

Andreas Jung andreas at andreas-jung.com
Tue May 1 06:59:57 EDT 2007


Log message for revision 74959:
  added logging
  

Changed:
  U   Products.SQLAlchemyDA/trunk/da.py

-=-
Modified: Products.SQLAlchemyDA/trunk/da.py
===================================================================
--- Products.SQLAlchemyDA/trunk/da.py	2007-05-01 10:44:09 UTC (rev 74958)
+++ Products.SQLAlchemyDA/trunk/da.py	2007-05-01 10:59:57 UTC (rev 74959)
@@ -6,8 +6,9 @@
 # and ZOPYX Ltd. & Co. KG, Tuebingen, Germany
 ##########################################################################
 
+import logging
+import time
 
-
 from Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
 from AccessControl.Permissions import view, view_management_screens
@@ -18,6 +19,9 @@
 from z3c.sqlalchemy import allSAWrapperNames, getSAWrapper
 
 
+LOG = logging.getLogger('SQLAlchemyDA')
+
+
 class SAWrapper(SimpleItem, PropertyManager):
     """ A shim around z3c.sqlalchemy implementing something DA-ish """
 
@@ -41,23 +45,27 @@
         self.id = id
         self.title = title
 
+
     security.declareProtected(view_management_screens, 'registeredWrappers')
     def registeredWrappers(self):
         """ return a list of registered wrapper names """
         return allSAWrapperNames()
 
+
     security.declareProtected(view, 'getMapper')
     def getMapper(self, name):
         """ return a mapper class """
         wrapper = getSAWrapper(self.sqlalchemy_wrapper_name)
         return wrapper.getMapper(name)
 
+
     security.declareProtected(view, 'getMappers')
     def getMappers(self, *names):
         """ return a mapper class """
         wrapper = getSAWrapper(self.sqlalchemy_wrapper_name)
         return wrapper.getMappers(*names)
 
+
     security.declareProtected(view, 'getSession')
     def getSession(self):
         """ return a session instance """
@@ -73,6 +81,7 @@
         d['DSN'] = wrapper.dsn
         return d
 
+
     def query(self, query_string, max_rows=None, query_data=None):
         """ *the* query() method"""
 
@@ -83,7 +92,11 @@
         nselects = 0
         desc = None
 
+        ts_start = time.time()
+
         for qs in [x for x in query_string.split('\0') if x]:
+
+            LOG.debug(qs)
                
             if query_data:
                 proxy = c.execute(qs, query_data)
@@ -105,6 +118,8 @@
 
                     desc = description  
 
+        LOG.debug('Execution time: %3.3f seconds' % (time.time() - ts_start))
+
         if desc is None:            
             return [], None
 
@@ -115,17 +130,19 @@
                  'type' : 'string',  # fix this
                  'width' : 0,        # fix this
                  'null' : null_ok,
-                }
-            ) 
+                }) 
 
         return items, rows
 
+
     def __call__(self, *args, **kv):
         return self    
 
+
     def sql_quote__(self, s):
         return s
 
+
     def connected(self):
         return True # this is a lie
  



More information about the Checkins mailing list