From ed23aeb37ca705c398078d5a40c1cddd7524811a Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Tue, 25 Oct 2005 15:35:11 +0000 Subject: [PATCH] named cursors are working. --- ChangeLog | 2 +- examples/fetch.py | 3 ++- sandbox/named.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 sandbox/named.py diff --git a/ChangeLog b/ChangeLog index 7f516e94..ef8cf6b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2005-10-22 Federico Di Gregorio +2005-10-22 Federico Di Gregorio * psycopg/cursor_type.c: added support for named cursors: - .fetchXXX() methods now execute a FETCH if the cursor is named diff --git a/examples/fetch.py b/examples/fetch.py index 67818d28..dab0a412 100644 --- a/examples/fetch.py +++ b/examples/fetch.py @@ -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()) diff --git a/sandbox/named.py b/sandbox/named.py new file mode 100644 index 00000000..d21a0cf9 --- /dev/null +++ b/sandbox/named.py @@ -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