From cca02219f764d3533147e9cbbec7317d8fc8bea6 Mon Sep 17 00:00:00 2001 From: baztian Date: Wed, 20 Apr 2011 18:06:26 +0200 Subject: [PATCH] set .rowcount properly --- README.rst | 4 ++++ src/jaydebeapi/dbapi2.py | 4 +++- src/test/integration_test.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 15d2e9d..fb9ed02 100644 --- a/README.rst +++ b/README.rst @@ -155,6 +155,10 @@ distribution for details. Changelog ========= +- 0.1.4 + + - Set ``.rowcount`` properly. + - 0.1.3 - Fixed DB-API_ violation: Use ``curs.execute('foo ?', (bar, baz))`` diff --git a/src/jaydebeapi/dbapi2.py b/src/jaydebeapi/dbapi2.py index 6dbf4c0..cd0067e 100644 --- a/src/jaydebeapi/dbapi2.py +++ b/src/jaydebeapi/dbapi2.py @@ -268,10 +268,12 @@ class Cursor(object): self._prep = self._connection.jconn.prepareStatement(operation) self._set_stmt_parms(self._prep, parameters) is_rs = self._prep.execute() - self.update_count = self._prep.getUpdateCount() if is_rs: self._rs = self._prep.getResultSet() self._meta = self._rs.getMetaData() + self.rowcount = -1 + else: + self.rowcount = self._prep.getUpdateCount() # self._prep.getWarnings() ??? def executemany(self, operation, seq_of_parameters): diff --git a/src/test/integration_test.py b/src/test/integration_test.py index b45e8eb..8bf9f73 100644 --- a/src/test/integration_test.py +++ b/src/test/integration_test.py @@ -224,3 +224,19 @@ class IntegrationTest(TestCase): cursor.close() value = result[0] assert 'abcdef' == value + + def test_execute_different_rowcounts(self): + cursor = self.conn.cursor() + stmt = "insert into ACCOUNT (ACCOUNT_ID, ACCOUNT_NO, BALANCE) " \ + "values (?, ?, ?)" + parms = ( + ( '2009-09-11 14:15:22.123450', 20, 13.1 ), + ( '2009-09-11 14:15:22.123452', 22, 13.3 ), + ) + cursor.executemany(stmt, parms) + assert cursor.rowcount == 2 + parms = ( '2009-09-11 14:15:22.123451', 21, 13.2 ) + cursor.execute(stmt, parms) + assert cursor.rowcount == 1 + cursor.execute("select * from ACCOUNT") + assert cursor.rowcount == -1