Skip to content

Commit 0a55f37

Browse files
Fixed bug with incorrect values of Cursor.rowcount when fetching data
(#147).
1 parent f8dce4f commit 0a55f37

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Thin Mode Changes
2727
(`issue 132 <https://github.com/oracle/python-oracledb/issues/132>`__).
2828
#) Fixed bug when binding data of type TIMESTAMP WITH TIME ZONE but with
2929
zero fractional seconds.
30+
#) Fixed bug with incorrect values of :data:`Cursor.rowcount` when fetching
31+
data
32+
(`issue 147 <https://github.com/oracle/python-oracledb/issues/147>`__).
3033

3134
Thick Mode Changes
3235
++++++++++++++++++

src/oracledb/impl/thin/messages.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ cdef class MessageWithData(Message):
729729
object exc_type
730730
Message._process_error_info(self, buf)
731731
cursor_impl._statement._cursor_id = self.error_info.cursor_id
732-
if not cursor_impl._statement._is_plsql:
732+
if not cursor_impl._statement._is_plsql and not self.in_fetch:
733733
cursor_impl.rowcount = self.error_info.rowcount
734734
cursor_impl._lastrowid = self.error_info.rowid
735735
cursor_impl._batcherrors = self.error_info.batcherrors

tests/test_4300_cursor_other.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,5 +870,23 @@ def test_4367_plsql_with_executemany_and_increasing_sizes(self):
870870
[(var, "five"), (var, "six"), (var, "end")])
871871
self.assertEqual(var.values, [4, 3, 3])
872872

873+
def test_4368_cursor_rowcount_for_queries(self):
874+
"4368 - test cursor.rowcount values for queries"
875+
max_rows = 93
876+
sql = f"select rownum as id from dual connect by rownum <= {max_rows}"
877+
self.cursor.arraysize = 10
878+
self.cursor.execute(sql)
879+
self.assertEqual(self.cursor.rowcount, 0)
880+
batch_num = 1
881+
while True:
882+
rows = self.cursor.fetchmany()
883+
if not rows:
884+
break
885+
expected_value = min(max_rows, batch_num * self.cursor.arraysize)
886+
self.assertEqual(self.cursor.rowcount, expected_value)
887+
batch_num += 1
888+
self.cursor.fetchall()
889+
self.assertEqual(self.cursor.rowcount, max_rows)
890+
873891
if __name__ == "__main__":
874892
test_env.run_test_cases()

0 commit comments

Comments
 (0)