This project is archived and is in readonly mode.
itersize not honored when using named cursor with RealDictCursor
Reported by Jean-Baptiste Quenot | December 2nd, 2011 @ 03:13 PM
Consider the following program with the default implementation
of RealDictCursor
:
import psycopg2.extras
conn = psycopg2.connect('dbname=test', connection_factory=psycopg2.extras.RealDictConnection)
curs = conn.cursor('unique_name')
curs.itersize = 2000
curs.execute("select * from foo limit 25")
curs.fetchone()
The output with PSYCOPG_DEBUG=1
contains the
following lines:
[0x7f603d53c700] FETCH FORWARD 1 FROM "unique_name"
I have to override the Cursor
class like this to
fetch the proper number of rows:
class Cursor(psycopg2.extras.RealDictCursor):
def next(self):
return psycopg2.extras._cursor.next(self)
class Connection(psycopg2.extras._connection):
"""A connection that uses `Cursor` automatically."""
def cursor(self, name=None):
if name is None:
return psycopg2.extras._connection.cursor(self, cursor_factory=Cursor)
else:
return psycopg2.extras._connection.cursor(self, name, cursor_factory=Cursor)
conn = psycopg2.connect('dbname=test', connection_factory=Connection)
...
The debug output is OK:
[0x7f86ba488700] FETCH FORWARD 2000 FROM "unique_name"
Comments and changes to this ticket
-
Daniele Varrazzo December 11th, 2011 @ 09:52 PM
- State changed from new to resolved
Fixed in my devel branch, thank you for the report.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.