Skip to content

Commit 373ea9d

Browse files
Fixed bug when fetching LOBs after an exception has been raised (#338).
1 parent 9acd9d2 commit 373ea9d

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Thin Mode Changes
2020
#) Fixed bug when a :ref:`DbObject <dbobject>` instance contains an attribute
2121
of type ``SYS.XMLTYPE``
2222
(`issue 336 <https://github.com/oracle/python-oracledb/issues/336>`__).
23+
#) Fixed bug when fetching LOBs after an exception has been raised
24+
(`issue 338 <https://github.com/oracle/python-oracledb/issues/338>`__).
2325
#) Fixed bug in statement cache when the maximum number of cursors is unknown
2426
due to the database not being open.
2527
#) Fixed bug in handling redirect data with small SDU sizes.

src/oracledb/impl/thin/messages.pyx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,10 @@ cdef class MessageWithData(Message):
738738
if prev_fetch_var_impls is not None \
739739
and i < len(prev_fetch_var_impls):
740740
self._adjust_fetch_info(prev_fetch_var_impls[i], fetch_info)
741-
if not stmt._no_prefetch and \
742-
fetch_info.dbtype._ora_type_num in (TNS_DATA_TYPE_BLOB,
743-
TNS_DATA_TYPE_CLOB,
744-
TNS_DATA_TYPE_JSON,
745-
TNS_DATA_TYPE_VECTOR):
741+
if fetch_info.dbtype._ora_type_num in (TNS_DATA_TYPE_BLOB,
742+
TNS_DATA_TYPE_CLOB,
743+
TNS_DATA_TYPE_JSON,
744+
TNS_DATA_TYPE_VECTOR):
746745
stmt._requires_define = True
747746
stmt._no_prefetch = True
748747
cursor_impl._create_fetch_var(conn, self.cursor, type_handler,
@@ -773,6 +772,8 @@ cdef class MessageWithData(Message):
773772
cursor_impl._statement._cursor_id = self.error_info.cursor_id
774773
if not cursor_impl._statement._is_plsql and not self.in_fetch:
775774
cursor_impl.rowcount = self.error_info.rowcount
775+
elif self.in_fetch and self.row_index > 0:
776+
cursor_impl._statement._requires_define = False
776777
cursor_impl._lastrowid = self.error_info.rowid
777778
cursor_impl._batcherrors = self.error_info.batcherrors
778779
if self.batcherrors and cursor_impl._batcherrors is None:
@@ -781,6 +782,7 @@ cdef class MessageWithData(Message):
781782
self.error_info.num = 0
782783
cursor_impl._more_rows_to_fetch = False
783784
cursor_impl._last_row_index = 0
785+
cursor_impl._statement._requires_define = False
784786
self.error_occurred = False
785787
elif self.error_info.num == TNS_ERR_ARRAY_DML_ERRORS:
786788
self.error_info.num = 0

tests/test_4300_cursor_other.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,20 @@ def test_4365(self):
977977
with self.assertRaisesFullCode("DPY-2045"):
978978
self.cursor.arraysize = "not valid"
979979

980+
def test_4366(self):
981+
"4366 - test fetching LOBs after an error"
982+
sql = """
983+
select
984+
to_clob(:val),
985+
1 / (dbms_lob.getlength(to_clob(:val)) - 1)
986+
from dual"""
987+
with self.assertRaisesFullCode("ORA-01476"):
988+
self.cursor.execute(sql, val="a")
989+
self.cursor.execute(sql, val="bb")
990+
lob, num_val = self.cursor.fetchone()
991+
self.assertEqual(lob.read(), "bb")
992+
self.assertEqual(num_val, 1)
993+
980994

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

tests/test_6300_cursor_other_async.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,20 @@ async def test_6347(self):
844844
}
845845
self.assertEqual(column_2.annotations, expected_annotations)
846846

847+
async def test_6348(self):
848+
"6348 - test fetching LOBs after an error"
849+
sql = """
850+
select
851+
to_clob(:val),
852+
1 / (dbms_lob.getlength(to_clob(:val)) - 1)
853+
from dual"""
854+
with self.assertRaisesFullCode("ORA-01476"):
855+
await self.cursor.execute(sql, val="a")
856+
await self.cursor.execute(sql, val="bb")
857+
lob, num_val = await self.cursor.fetchone()
858+
self.assertEqual(await lob.read(), "bb")
859+
self.assertEqual(num_val, 1)
860+
847861

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

0 commit comments

Comments
 (0)