dabo Commit
Revision 2158
Date: 2006-05-16 14:02:41 -0700 (Tue, 16 May 2006)
Author: paul
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/db/dCursorMixin.py
Log:
Added useAuxCursor argument to execute(). Added executeSafe() method to dBizobj
which is just a convenience for execute(useAuxCursor=True).
Modified execute() to return the DataSet, if any, when executing against an
AuxCursor.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2006-05-16 20:11:00 UTC (rev 2157)
+++ trunk/dabo/biz/dBizobj.py 2006-05-16 21:02:41 UTC (rev 2158)
@@ -460,13 +460,29 @@
ret = self.delete(startTransaction)
- def execute(self, expr):
+ def execute(self, expr, useAuxCursor=None):
"""Pass-through method that will take the 'expr' and pass
it to this bizobj's cursor for execution.
+
+ The useAuxCursor argument specifies whether the sql will be
executed
+ using the main cursor or an auxiliary cursor. The possible
values
+ are:
+ None (default): The method will automatically determine
what to do.
+ True: An AuxCursor will be used
+ False: The main cursor will be used (could be dangerous)
"""
- self._CurrentCursor.execute(expr)
+ return self._CurrentCursor.execute(expr,
useAuxCursor=useAuxCursor)
-
+
+ def executeSafe(self, expr):
+ """Execute the passed SQL using an auxiliary cursor.
+
+ This is considered 'safe', because it won't harm the contents
of the
+ main cursor.
+ """
+ return self.execute(expr, useAuxCursor=True)
+
+
def getChangedRecordNumbers(self):
""" Returns a list of record numbers for which isChanged()
returns True. The changes may therefore not be in the record
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2006-05-16 20:11:00 UTC (rev 2157)
+++ trunk/dabo/db/dCursorMixin.py 2006-05-16 21:02:41 UTC (rev 2158)
@@ -142,18 +142,30 @@
return self.sortCase
- def execute(self, sql, params=()):
+ def execute(self, sql, params=(), useAuxCursor=None):
"""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.
+
+ The useAuxCursor argument specifies whether the sql will be
executed
+ using the main cursor or an auxiliary cursor. The possible
values
+ are:
+ None (default): The method will automatically determine
what to do.
+ True: An AuxCursor will be used
+ False: The main cursor will be used (could be dangerous)
"""
#### NOTE: NEEDS TO BE TESTED THOROUGHLY!!!! ####
- if sql.strip().split()[0].lower() == "select":
+ if useAuxCursor is None:
+ if sql.strip().split()[0].lower() == "select":
+ cursorToUse = self
+ else:
+ cursorToUse = self.AuxCursor
+ #cursorToUse.AutoCommit = self.AutoCommit
+ elif useAuxCursor:
+ cursorToUse = self.AuxCursor
+ else:
cursorToUse = self
- else:
- cursorToUse = self.AuxCursor
- #cursorToUse.AutoCommit = self.AutoCommit
# Some backends, notably Firebird, require that fields be
specially
# marked.
@@ -167,9 +179,9 @@
try:
if params is None or len(params) == 0:
- res = cursorToUse.superCursor.execute(self,
sqlEX)
+ res =
cursorToUse.superCursor.execute(cursorToUse, sqlEX)
else:
- res = cursorToUse.superCursor.execute(self,
sqlEX, params)
+ res =
cursorToUse.superCursor.execute(cursorToUse, sqlEX, params)
except Exception, e:
# If this is due to a broken connection, let the user
know.
# Different backends have different messages, but they
@@ -183,8 +195,11 @@
if cursorToUse is not self:
# No need to manipulate the data
- return res
-
+ try:
+ return DataSet(cursorToUse.fetchall())
+ except:
+ return res
+
# Not all backends support 'fetchall' after executing a query
# that doesn't return records, such as an update.
try:
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev