diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-02-23 23:05:40 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-02-23 23:05:40 +0000 |
commit | e57f3284ebc9c3a47ed067a2d88a505ecc6be64d (patch) | |
tree | 1e356261e6781f553dc5a9db294f99bc542c254a /lib/extras.py | |
parent | dca6cffd6e687ef171cc70a7de392080f3c05a1b (diff) | |
parent | 1d7e6afcf0fb60c737a91be4ad19f688aa10f548 (diff) | |
download | psycopg2-e57f3284ebc9c3a47ed067a2d88a505ecc6be64d.tar.gz |
Merge branch 'cursors-rownumber' into devel
Diffstat (limited to 'lib/extras.py')
-rw-r--r-- | lib/extras.py | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/lib/extras.py b/lib/extras.py index e1091e2..870b5ca 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -88,25 +88,17 @@ class DictCursorBase(_cursor): def __iter__(self): if self._prefetch: - res = _cursor.fetchmany(self, self.itersize) - if not res: - return + res = _cursor.__iter__(self) + first = res.next() if self._query_executed: self._build_index() if not self._prefetch: - res = _cursor.fetchmany(self, self.itersize) + res = _cursor.__iter__(self) + first = res.next() - for r in res: - yield r - - # the above was the first itersize record. the following are - # in a repeated loop. + yield first while 1: - res = _cursor.fetchmany(self, self.itersize) - if not res: - return - for r in res: - yield r + yield res.next() class DictConnection(_connection): @@ -318,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 |