Skip to content

Commit cbd2fe7

Browse files
Fixed bug when fetch variables contain output converters and a query is
re-executed (#271).
1 parent 4ca0c80 commit cbd2fe7

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Thin Mode Changes
1515

1616
#) Added support for using alternative event loop implementations like uvloop
1717
(`issue 276 <https://github.com/oracle/python-oracledb/issues/276>`__).
18+
#) Fixed bug when fetch variables contain output converters and a query is
19+
re-executed
20+
(`issue 271 <https://github.com/oracle/python-oracledb/issues/271>`__).
1821

1922
Common Changes
2023
++++++++++++++

src/oracledb/impl/thin/messages.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -761,6 +761,7 @@ cdef class MessageWithData(Message):
761761
if self.error_info.num == TNS_ERR_NO_DATA_FOUND:
762762
self.error_info.num = 0
763763
cursor_impl._more_rows_to_fetch = False
764+
cursor_impl._last_row_index = 0
764765
self.error_occurred = False
765766
elif self.error_info.num == TNS_ERR_ARRAY_DML_ERRORS:
766767
self.error_info.num = 0

tests/test_3600_outputtypehandler.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2021, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2021, 2024, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -683,6 +683,44 @@ def type_handler(cursor, name, default_type, size, precision, scale):
683683
cursor.execute("select 1 from dual")
684684
self.assertEqual(cursor.fetchall(), [("1",)])
685685

686+
def test_3676_reexecute_no_rows(self):
687+
"3676 - re-execute query with second fetch returning no rows"
688+
689+
self.cursor.execute("truncate table TestTempTable")
690+
data = [(i + 1,) for i in range(5)]
691+
self.cursor.executemany(
692+
"insert into TestTempTable (IntCol) values (:1)", data
693+
)
694+
self.conn.commit()
695+
696+
def type_handler_1(cursor, metadata):
697+
return cursor.var(
698+
str,
699+
arraysize=cursor.arraysize,
700+
outconverter=lambda x: f"_{x}_",
701+
)
702+
703+
def type_handler_2(cursor, metadata):
704+
return cursor.var(
705+
str,
706+
arraysize=cursor.arraysize,
707+
outconverter=lambda x: f"={x}=",
708+
)
709+
710+
self.cursor.outputtypehandler = type_handler_1
711+
self.cursor.arraysize = 6
712+
self.cursor.prefetchrows = 6
713+
sql = "select IntCol from TestTempTable where rownum <= :1"
714+
self.cursor.execute(sql, [6])
715+
expected_value = [(f"_{x}_",) for x, in data]
716+
self.assertEqual(self.cursor.fetchall(), expected_value)
717+
718+
self.cursor.outputtypehandler = type_handler_2
719+
self.cursor.prefetchrows = 2
720+
self.cursor.arraysize = 2
721+
self.cursor.execute(sql, [0])
722+
self.assertEqual(self.cursor.fetchall(), [])
723+
686724

687725
if __name__ == "__main__":
688726
test_env.run_test_cases()

0 commit comments

Comments
 (0)