mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
named cursors are working.
This commit is contained in:
parent
ef3430d24f
commit
ed23aeb37c
|
@ -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
29
sandbox/named.py
Normal 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
|
Loading…
Reference in New Issue
Block a user