Skip to content

Commit 801fe07

Browse files
Fixed bug when a query is re-executed with the setting
"oracledb.defaults.fetch_lobs = False" after a table underlying the query is dropped and recreated.
1 parent 7fe0a8e commit 801fe07

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
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
#) Fixed bug when SQL is executed after first being parsed with Oracle
1717
Database 23c.
18+
#) Fixed bug when a query is re-executed with the setting
19+
``oracledb.defaults.fetch_lobs = False`` after a table underlying the query
20+
is dropped and recreated.
1821
#) Fixed bug when warning message is encountered during connect
1922
(`issue 171 <https://github.com/oracle/python-oracledb/issues/171>`__).
2023

src/oracledb/impl/thin/cursor.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023, 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
@@ -96,6 +96,7 @@ cdef class ThinCursorImpl(BaseCursorImpl):
9696
if typ_impl.is_xml_type:
9797
var_impl.outconverter = \
9898
lambda v: v if isinstance(v, str) else v.read()
99+
self._statement._always_full_execute = self._statement._requires_define
99100

100101
cdef int _fetch_rows(self, object cursor) except -1:
101102
"""

src/oracledb/impl/thin/messages.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,8 +2000,11 @@ cdef class ExecuteMessage(MessageWithData):
20002000
"""
20012001
cdef:
20022002
Statement stmt = self.cursor_impl._statement
2003-
if stmt._cursor_id != 0 and not stmt._requires_full_execute \
2004-
and not self.parse_only and not stmt._is_ddl \
2003+
if stmt._cursor_id != 0 \
2004+
and not stmt._requires_full_execute \
2005+
and not stmt._always_full_execute \
2006+
and not self.parse_only \
2007+
and not stmt._is_ddl \
20052008
and not self.batcherrors:
20062009
if stmt._is_query and not stmt._requires_define \
20072010
and self.cursor_impl.prefetchrows > 0:

src/oracledb/impl/thin/statement.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ cdef class Statement:
8888
object _last_output_type_handler
8989
uint32_t _num_columns
9090
bint _requires_full_execute
91+
bint _always_full_execute
9192
bint _requires_define
9293
bint _return_to_cache
9394
bint _in_use

tests/test_4300_cursor_other.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,5 +913,37 @@ def test_4369_bind_order_for_plsql(self):
913913
fetched_rows = self.cursor.fetchall()
914914
self.assertEqual(fetched_rows, rows)
915915

916+
def test_4370_rebuild_table_with_lob_in_cached_query(self):
917+
"4370 - test rebuild of table with LOB in cached query"
918+
table_name = "test_4370"
919+
drop_sql = f"drop table {table_name} purge"
920+
create_sql = f"""
921+
create table {table_name} (
922+
Col1 number(9) not null,
923+
Col2 clob not null
924+
)"""
925+
insert_sql = f"insert into {table_name} values (:1, :2)"
926+
query_sql = f"select * from {table_name} order by Col1"
927+
data = [
928+
(1, "CLOB value 1"),
929+
(2, "CLOB value 2")
930+
]
931+
try:
932+
self.cursor.execute(drop_sql)
933+
except:
934+
pass
935+
with test_env.FetchLobsContextManager(False):
936+
self.cursor.execute(create_sql)
937+
self.cursor.executemany(insert_sql, data)
938+
self.cursor.execute(query_sql)
939+
self.assertEqual(self.cursor.fetchall(), data)
940+
self.cursor.execute(query_sql)
941+
self.assertEqual(self.cursor.fetchall(), data)
942+
self.cursor.execute(drop_sql)
943+
self.cursor.execute(create_sql)
944+
self.cursor.executemany(insert_sql, data)
945+
self.cursor.execute(query_sql)
946+
self.assertEqual(self.cursor.fetchall(), data)
947+
916948
if __name__ == "__main__":
917949
test_env.run_test_cases()

0 commit comments

Comments
 (0)