Changeset 846 for trunk


Ignore:
Timestamp:
Feb 9, 2016, 2:20:10 AM (4 years ago)
Author:
cito
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/pgdb.py

    r844 r846  
    853853        """Close the cursor object."""
    854854        self._src.close()
    855         self._description = None
    856         self.rowcount = -1
    857         self.lastrowid = None
    858855
    859856    def execute(self, operation, parameters=None):
  • trunk/tests/test_dbapi20.py

    r844 r846  
    495495            self.assertRaises(pgdb.IntegrityError, cur.execute,
    496496                "insert into %s values (1)" % table)
     497        finally:
     498            con.close()
     499
     500    def test_update_rowcount(self):
     501        table = self.table_prefix + 'booze'
     502        con = self._connect()
     503        try:
     504            cur = con.cursor()
     505            cur.execute("create table %s (i int)" % table)
     506            cur.execute("insert into %s values (1)" % table)
     507            cur.execute("update %s set i=2 where i=2 returning i" % table)
     508            self.assertEqual(cur.rowcount, 0)
     509            cur.execute("update %s set i=2 where i=1 returning i" % table)
     510            self.assertEqual(cur.rowcount, 1)
     511            cur.close()
     512            # keep rowcount even if cursor is closed (needed by SQLAlchemy)
     513            self.assertEqual(cur.rowcount, 1)
    497514        finally:
    498515            con.close()
Note: See TracChangeset for help on using the changeset viewer.