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