Skip to content

Commit

Permalink
Fixed bug with re-execution of SQL that requires a define, such as
Browse files Browse the repository at this point in the history
occurs when setting oracledb.defaults.fetch_lobs to the value False
(#41).
  • Loading branch information
anthony-tuininga committed Jul 29, 2022
1 parent 47c3b2c commit 2359c85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Thin Mode Changes
(`issue 26 <https://github.com/oracle/python-oracledb/issues/26>`__).
#) Fixed bug with handling of redirect data returned by some SCAN listeners
(`issue 39 <https://github.com/oracle/python-oracledb/issues/39>`__).
#) Fixed bug with re-execution of SQL that requires a define, such as occurs
when setting `oracledb.defaults.fetch_lobs` to the value `False`
(`issue 41 <https://github.com/oracle/python-oracledb/issues/41>`__).
#) Internally, before a connection is returned from a pool, check for control
packets from the server (which may inform the client that the connection
needs to be closed and a new one established).
Expand Down
11 changes: 8 additions & 3 deletions src/oracledb/impl/thin/messages.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1657,13 +1657,18 @@ cdef class ExecuteMessage(MessageWithData):
Runs after the database response has been processed. If the statement
executed requires define and is not a REF cursor (which would already
have performed the define during its execute), then mark the message as
needing to be resent.
needing to be resent. If this is after the second time the message has
been sent, mark the statement as no longer needing a define (since this
only needs to happen once).
"""
MessageWithData._postprocess(self)
cdef Statement stmt = self.cursor_impl._statement
if stmt._requires_define and stmt._sql is not None:
stmt._requires_full_execute = True
self.resend = True
if self.resend:
stmt._requires_define = False
else:
stmt._requires_full_execute = True
self.resend = True

cdef int _write_execute_message(self, WriteBuffer buf) except -1:
"""
Expand Down
18 changes: 18 additions & 0 deletions tests/test_4300_cursor_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,23 @@ def test_4361_rowcount_after_close(self):
self.assertEqual(cursor.rowcount, 1)
self.assertEqual(cursor.rowcount, -1)

def test_4362_change_of_bind_type_with_define(self):
"4362 - changing bind type with define needed"
self.cursor.execute("truncate table TestClobs")
row_for_1 = (1, "Short value 1")
row_for_56 = (56, "Short value 56")
for data in (row_for_1, row_for_56):
self.cursor.execute("""
insert into TestClobs (IntCol, ClobCol)
values (:1, :2)""", data)
sql = "select IntCol, ClobCol from TestClobs where IntCol = :int_col"
with test_env.FetchLobsContextManager(False):
self.cursor.execute(sql, int_col="1")
self.assertEqual(self.cursor.fetchone(), row_for_1)
self.cursor.execute(sql, int_col="56")
self.assertEqual(self.cursor.fetchone(), row_for_56)
self.cursor.execute(sql, int_col=1)
self.assertEqual(self.cursor.fetchone(), row_for_1)

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

0 comments on commit 2359c85

Please sign in to comment.