Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itersize not honored when using named cursor with RealDictCursor #80

Closed
psycoteam opened this issue Dec 2, 2011 · 2 comments
Closed

Comments

@psycoteam
Copy link

Originally submitted by: Jean-Baptiste Quenot

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"
@dvarrazzo
Copy link
Member

Fixed in my devel branch, thank you for the report.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants