summaryrefslogtreecommitdiff
path: root/lib/extras.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-12-11 22:04:42 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-12-11 22:06:15 +0000
commit8473209d240bad964630b9b77da7fcc664f61b41 (patch)
tree14026dc89fc65f0d07a3ccc484953f30e6c3d29f /lib/extras.py
parent8606d835074b310bb39fc44e5c954d78988cbf97 (diff)
downloadpsycopg2-8473209d240bad964630b9b77da7fcc664f61b41.tar.gz
Named DictCursor/RealDictCursor honour itersize
Closes ticket #80.
Diffstat (limited to 'lib/extras.py')
-rw-r--r--lib/extras.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/extras.py b/lib/extras.py
index 78f962e..491a390 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -86,18 +86,28 @@ class DictCursorBase(_cursor):
res = _cursor.fetchall(self)
return res
- def next(self):
+ def __iter__(self):
if self._prefetch:
- res = _cursor.fetchone(self)
- if res is None:
- raise StopIteration()
+ res = _cursor.fetchmany(self, self.itersize)
+ if not res:
+ return
if self._query_executed:
self._build_index()
if not self._prefetch:
- res = _cursor.fetchone(self)
- if res is None:
- raise StopIteration()
- return res
+ res = _cursor.fetchmany(self, self.itersize)
+
+ for r in res:
+ yield r
+
+ # the above was the first itersize record. the following are
+ # in a repeated loop.
+ while 1:
+ res = _cursor.fetchmany(self, self.itersize)
+ if not res:
+ return
+ for r in res:
+ yield r
+
class DictConnection(_connection):
"""A connection that uses `DictCursor` automatically."""