dabo Commit
Revision 3320
Date: 2007-08-21 18:31:38 -0700 (Tue, 21 Aug 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3320

Changed:
U   trunk/dabo/db/dCursorMixin.py
U   trunk/dabo/db/dbSQLite.py

Log:
Adds the option of passing a known error class to dCursorMixin.execute. If the 
execute call raises an error of that class, it will be re-raised without 
logging a failure, on the assumption that the calling routine will handle it. 
This should correct the problem with dbSQLite causing "FAILED SQL" messages for 
routine COMMIT calls.


Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2007-08-21 22:29:46 UTC (rev 3319)
+++ trunk/dabo/db/dCursorMixin.py       2007-08-22 01:31:38 UTC (rev 3320)
@@ -258,18 +258,15 @@
                return ret
 
 
-       def execute(self, sql, params=(), _fromRequery=False):
+       def execute(self, sql, params=(), _fromRequery=False, errorClass=None):
                """ Execute the sql, and populate the DataSet if it is a select 
statement."""
                # The idea here is to let the super class do the actual work in
                # retrieving the data. However, many cursor classes can only 
return
                # row information as a list, not as a dictionary. This method 
will
                # detect that, and convert the results to a dictionary.
-
-               #### NOTE: NEEDS TO BE TESTED THOROUGHLY!!!!  ####
-
-               # Some backends, notably Firebird, require that fields be 
specially marked.
                if not isinstance(sql, unicode):
                        sql = unicode(sql, self.Encoding)
+               # Some backends, notably Firebird, require that fields be 
specially marked.
                sql = self.processFields(sql)
 
                try:
@@ -282,6 +279,11 @@
                                if not self.IsPrefCursor:
                                        dabo.dbActivityLog.write("SQL: %s, 
PARAMS: %s" % (sql.replace("\n", " "), ", ".join(params)))
                except Exception, e:
+                       # There can be cases where errors are expected. In 
those cases, the 
+                       # calling routine will pass the class of the expected 
error, and will
+                       # handle it appropriately.
+                       if isinstance(e, errorClass):
+                               raise errorClass, e
                        dabo.dbActivityLog.write("FAILED SQL: %s, PARAMS: %s" % 
(sql.replace("\n", " "), ", ".join(params)))
                        # If this is due to a broken connection, let the user 
know.
                        # Different backends have different messages, but they

Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py   2007-08-21 22:29:46 UTC (rev 3319)
+++ trunk/dabo/db/dbSQLite.py   2007-08-22 01:31:38 UTC (rev 3320)
@@ -81,15 +81,16 @@
 
        def commitTransaction(self, cursor):
                """ Commit a SQL transaction."""
+               opError = self.dbapi.OperationalError
                try:
-                       cursor.execute("COMMIT")
+                       cursor.execute("COMMIT", errorClass=opError)
                        dabo.dbActivityLog.write("SQL: commit")
+               except opError, e:
+                       # There is no transaction active in this case, so 
ignore the error.
+                       pass
                except Exception, e:
-                       if "no transaction is active" in str(e):
-                               pass
-                       else:
-                               dabo.dbActivityLog.write("SQL: commit failed: 
%s" % e)
-                               raise dException.DBQueryException, e            
        
+                       dabo.dbActivityLog.write("SQL: commit failed: %s" % e)
+                       raise dException.DBQueryException, e                    
 
 
        def rollbackTransaction(self, cursor):




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to