Author: cito
Date: Tue Feb 9 02:20:10 2016
New Revision: 846
Log:
Do not reset cursor attributes when cursor is closed
SQLAlchemy for instance checks the rowcount after the cursor is closed.
You will only get an error if you try to fetch rows from a closed cursor.
Modified:
trunk/pgdb.py
trunk/tests/test_dbapi20.py
Modified: trunk/pgdb.py
==============================================================================
--- trunk/pgdb.py Mon Feb 8 18:18:15 2016 (r845)
+++ trunk/pgdb.py Tue Feb 9 02:20:10 2016 (r846)
@@ -852,9 +852,6 @@
def close(self):
"""Close the cursor object."""
self._src.close()
- self._description = None
- self.rowcount = -1
- self.lastrowid = None
def execute(self, operation, parameters=None):
"""Prepare and execute a database operation (query or command)."""
Modified: trunk/tests/test_dbapi20.py
==============================================================================
--- trunk/tests/test_dbapi20.py Mon Feb 8 18:18:15 2016 (r845)
+++ trunk/tests/test_dbapi20.py Tue Feb 9 02:20:10 2016 (r846)
@@ -497,6 +497,23 @@
finally:
con.close()
+ def test_update_rowcount(self):
+ table = self.table_prefix + 'booze'
+ con = self._connect()
+ try:
+ cur = con.cursor()
+ cur.execute("create table %s (i int)" % table)
+ cur.execute("insert into %s values (1)" % table)
+ cur.execute("update %s set i=2 where i=2 returning i" % table)
+ self.assertEqual(cur.rowcount, 0)
+ cur.execute("update %s set i=2 where i=1 returning i" % table)
+ self.assertEqual(cur.rowcount, 1)
+ cur.close()
+ # keep rowcount even if cursor is closed (needed by SQLAlchemy)
+ self.assertEqual(cur.rowcount, 1)
+ finally:
+ con.close()
+
def test_sqlstate(self):
con = self._connect()
cur = con.cursor()
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql