[Twisted-Python] patch implementing 'fetchmany' from enterprise.adbapi
Clark C. Evans
cce at clarkevans.com
Tue Mar 4 04:01:09 EST 2003
On Tue, Mar 04, 2003 at 02:55:16AM -0500, andrewextra at puzzling.org wrote:
| >
| > The patch also tests for "threadsaftey", for some reason
| > mxODBC has an apilevel of "2.0" yet they are missing this
| > attribute (they call it threadlevel). I'm not fond of
| > this part of the patch, but it is included since this
| > is what I tested with (I don't have permissions to change
| > mxODBC).
|
| Of course you have permissions to change mxODBC:
| import mxODBC
| mxODBC.threadsafety = mxODBC.threadlevel
|
I tried that before I hacked. However, the threadsaftey attribute
doesn't seem to be picked up within the ConnectionPool constructor,
which is passed the fully qualified class as a string. I'm sure
there is another way to do it... in any case, that part of the
patch can be easily dropped. Following is the modified patch
without the threadsaftey hack. ;) Clark
--- adbapi.py.orig Fri Feb 28 16:51:08 2003
+++ adbapi.py Tue Mar 4 02:01:36 2003
@@ -99,6 +101,21 @@
curs.close()
return result
+ def _runQueryChunked(self, args, kw):
+ conn = self.connect()
+ curs = conn.cursor()
+ apply(curs.execute, args, kw)
+ class fetchChunk:
+ def __init__(self,curs):
+ self.curs = curs
+ def next(self):
+ ret = self.curs.fetchmany()
+ if not ret:
+ self.curs.close()
+ raise StopIteration
+ return ret
+ return fetchChunk(curs)
+
def _runOperation(self, args, kw):
"""This is used for non-query operations that don't want "fetch*" to be called
"""
@@ -121,6 +138,10 @@
threads.deferToThread(self._runQuery, args, kw).addCallbacks(
callback, errback)
+ def queryChunked(self, callback, errback, *args, **kw):
+ threads.deferIterationToThread(self._runQueryChunked, args, kw
+ ).addCallbacks(callback, errback)
+
def operation(self, callback, errback, *args, **kw):
threads.deferToThread(self._runOperation, args, kw).addCallbacks(
callback, errback)
@@ -229,6 +250,11 @@
apply(self.dbpool.query, (d.callback, d.errback)+args, kw)
return d
+ def runQueryChunked(self, *args, **kw):
+ d = defer.MultiCallDeferred()
+ apply(self.dbpool.queryChunked, (d.callback, d.errback)+args, kw)
+ return d
+
def runOperation(self, *args, **kw):
d = defer.Deferred()
apply(self.dbpool.operation, (d.callback,d.errback)+args, kw)
More information about the Twisted-Python
mailing list