named cursors are working.

This commit is contained in:
Federico Di Gregorio 2005-10-25 15:35:11 +00:00
parent ef3430d24f
commit ed23aeb37c
3 changed files with 32 additions and 2 deletions

View File

@ -54,8 +54,9 @@ conn.commit()
# (remember to always commit or rollback before a DECLARE)
#
# we don't need to DECLARE ourselves, psycopg now support named
# cursor (but we leave the code here, comments, as an example of
# cursors (but we leave the code here, comments, as an example of
# what psycopg is doing under the hood)
#
#curs.execute("DECLARE crs CURSOR FOR SELECT * FROM test_fetch")
#curs.execute("FETCH 10 FROM crs")
#print "First 10 rows:", flatten(curs.fetchall())

29
sandbox/named.py Normal file
View File

@ -0,0 +1,29 @@
import psycopg2
import psycopg2.extensions
class Portal(psycopg2.extensions.cursor):
def __init__(self, name, curs):
name = '"'+name+'"'
psycopg2.extensions.cursor.__init__(self, curs.connection, name)
CURSOR = psycopg2.extensions.new_type((1790,), "CURSOR", Portal)
psycopg2.extensions.register_type(CURSOR)
conn = psycopg2.connect("dbname=test")
curs = conn.cursor()
curs.execute("SELECT reffunc2()")
portal = curs.fetchone()[0]
print portal.fetchone()
portal.scroll(-1)
print portal.fetchall()
#print curs.rowcount
#print curs.statusmessage
#print curs.fetchone()
#print curs.rowcount
#print curs.statusmessage
#print curs.fetchone()
#print curs.rowcount
#print curs.statusmessage