mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Fixed interaction between RealDictCursor and named cursors
Closes ticket #67.
This commit is contained in:
parent
29932c488f
commit
d67d50b434
2
NEWS
2
NEWS
|
@ -8,6 +8,8 @@ What's new in psycopg 2.4.3
|
|||
- Lazy import of the slow uuid module, thanks to Marko Kreen.
|
||||
- Fixed NamedTupleCursor.executemany() (ticket #65).
|
||||
- Fixed --static-libpq setup option (ticket #64).
|
||||
- Fixed interaction between RealDictCursor and named cursors
|
||||
(ticket #67).
|
||||
- 'errorcodes' map updated to PostgreSQL 9.1.
|
||||
|
||||
|
||||
|
|
|
@ -237,6 +237,10 @@ class RealDictRow(dict):
|
|||
|
||||
def __init__(self, cursor):
|
||||
dict.__init__(self)
|
||||
# Required for named cursors
|
||||
if cursor.description and not cursor.column_mapping:
|
||||
cursor._build_index()
|
||||
|
||||
self._column_mapping = cursor.column_mapping
|
||||
|
||||
def __setitem__(self, name, value):
|
||||
|
|
|
@ -80,6 +80,21 @@ class ExtrasDictCursorTests(unittest.TestCase):
|
|||
return row
|
||||
self._testWithNamedCursor(getter)
|
||||
|
||||
def testDictCursorRealWithNamedCursorFetchOne(self):
|
||||
self._testWithNamedCursorReal(lambda curs: curs.fetchone())
|
||||
|
||||
def testDictCursorRealWithNamedCursorFetchMany(self):
|
||||
self._testWithNamedCursorReal(lambda curs: curs.fetchmany(100)[0])
|
||||
|
||||
def testDictCursorRealWithNamedCursorFetchAll(self):
|
||||
self._testWithNamedCursorReal(lambda curs: curs.fetchall()[0])
|
||||
|
||||
def testDictCursorRealWithNamedCursorIter(self):
|
||||
def getter(curs):
|
||||
for row in curs:
|
||||
return row
|
||||
self._testWithNamedCursorReal(getter)
|
||||
|
||||
def _testWithPlainCursor(self, getter):
|
||||
curs = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||
curs.execute("SELECT * FROM ExtrasDictCursorTests")
|
||||
|
|
Loading…
Reference in New Issue
Block a user