summaryrefslogtreecommitdiff
path: root/lib/extras.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-02-23 22:58:58 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-02-23 22:58:58 +0000
commitb8597dc1d369d69788a446f65d1f8741d09e064a (patch)
tree6a25a00fca6c98e974aad97fc959747231cf962b /lib/extras.py
parentebec522a07bc6ad091df2cf8f9d7892760423266 (diff)
downloadpsycopg2-b8597dc1d369d69788a446f65d1f8741d09e064a.tar.gz
Fixed NamedTupleCursor rownumber during iteration.
The correction is similar to the other one for the other subclasses. Also added tests for rowcount and rownumber during different fetch styles. Just in case.
Diffstat (limited to 'lib/extras.py')
-rw-r--r--lib/extras.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/extras.py b/lib/extras.py
index aa7bc87..870b5ca 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -310,14 +310,17 @@ class NamedTupleCursor(_cursor):
return [nt(*t) for t in ts]
def __iter__(self):
- # Invoking _cursor.__iter__(self) goes to infinite recursion,
- # so we do pagination by hand
+ it = _cursor.__iter__(self)
+ t = it.next()
+
+ nt = self.Record
+ if nt is None:
+ nt = self.Record = self._make_nt()
+
+ yield nt(*t)
+
while 1:
- recs = self.fetchmany(self.itersize)
- if not recs:
- return
- for rec in recs:
- yield rec
+ yield nt(*it.next())
try:
from collections import namedtuple