Skip to content

Commit d297f8b

Browse files
Fixed bug with re-execution of SQL that requires a define, such as
occurs when setting oracledb.defaults.fetch_lobs to the value False (#41).
1 parent 3a9a296 commit d297f8b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Thin Mode Changes
2020
(`issue 26 <https://github.com/oracle/python-oracledb/issues/26>`__).
2121
#) Fixed bug with handling of redirect data returned by some SCAN listeners
2222
(`issue 39 <https://github.com/oracle/python-oracledb/issues/39>`__).
23+
#) Fixed bug with re-execution of SQL that requires a define, such as occurs
24+
when setting `oracledb.defaults.fetch_lobs` to the value `False`
25+
(`issue 41 <https://github.com/oracle/python-oracledb/issues/41>`__).
2326

2427
Common Changes
2528
++++++++++++++

src/oracledb/impl/thin/messages.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,13 +1657,18 @@ cdef class ExecuteMessage(MessageWithData):
16571657
Runs after the database response has been processed. If the statement
16581658
executed requires define and is not a REF cursor (which would already
16591659
have performed the define during its execute), then mark the message as
1660-
needing to be resent.
1660+
needing to be resent. If this is after the second time the message has
1661+
been sent, mark the statement as no longer needing a define (since this
1662+
only needs to happen once).
16611663
"""
16621664
MessageWithData._postprocess(self)
16631665
cdef Statement stmt = self.cursor_impl._statement
16641666
if stmt._requires_define and stmt._sql is not None:
1665-
stmt._requires_full_execute = True
1666-
self.resend = True
1667+
if self.resend:
1668+
stmt._requires_define = False
1669+
else:
1670+
stmt._requires_full_execute = True
1671+
self.resend = True
16671672

16681673
cdef int _write_execute_message(self, WriteBuffer buf) except -1:
16691674
"""

tests/test_4300_cursor_other.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,5 +784,23 @@ def test_4361_rowcount_after_close(self):
784784
self.assertEqual(cursor.rowcount, 1)
785785
self.assertEqual(cursor.rowcount, -1)
786786

787+
def test_4362_change_of_bind_type_with_define(self):
788+
"4362 - changing bind type with define needed"
789+
self.cursor.execute("truncate table TestClobs")
790+
row_for_1 = (1, "Short value 1")
791+
row_for_56 = (56, "Short value 56")
792+
for data in (row_for_1, row_for_56):
793+
self.cursor.execute("""
794+
insert into TestClobs (IntCol, ClobCol)
795+
values (:1, :2)""", data)
796+
sql = "select IntCol, ClobCol from TestClobs where IntCol = :int_col"
797+
with test_env.FetchLobsContextManager(False):
798+
self.cursor.execute(sql, int_col="1")
799+
self.assertEqual(self.cursor.fetchone(), row_for_1)
800+
self.cursor.execute(sql, int_col="56")
801+
self.assertEqual(self.cursor.fetchone(), row_for_56)
802+
self.cursor.execute(sql, int_col=1)
803+
self.assertEqual(self.cursor.fetchone(), row_for_1)
804+
787805
if __name__ == "__main__":
788806
test_env.run_test_cases()

0 commit comments

Comments
 (0)