Skip to content

Commit 0489c7e

Browse files
Added support for explicitly specifying whether to fetch LOBs or decimal
values when performing queries.
1 parent d349d84 commit 0489c7e

36 files changed

+629
-149
lines changed

doc/src/api_manual/async_connection.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ AsyncConnection Methods
8787

8888
.. automethod:: AsyncConnection.fetchall
8989

90+
.. versionchanged:: 3.4.0
91+
92+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
93+
9094
.. automethod:: AsyncConnection.fetch_df_all
9195

9296
See :ref:`dataframeformat` for the supported data types and examples.
@@ -96,6 +100,10 @@ AsyncConnection Methods
96100
The data frame support in python-oracledb 3.3 is a pre-release and may
97101
change in a future version.
98102

103+
.. versionchanged:: 3.4.0
104+
105+
The ``fetch_decimals`` parameter was added.
106+
99107
.. versionadded:: 3.0.0
100108

101109
.. automethod:: AsyncConnection.fetch_df_batches
@@ -107,12 +115,24 @@ AsyncConnection Methods
107115
The data frame support in python-oracledb 3.3 is a pre-release and may
108116
change in a future version.
109117

118+
.. versionchanged:: 3.4.0
119+
120+
The ``fetch_decimals`` parameter was added.
121+
110122
.. versionadded:: 3.0.0
111123

112124
.. automethod:: AsyncConnection.fetchmany
113125

126+
.. versionchanged:: 3.4.0
127+
128+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
129+
114130
.. automethod:: AsyncConnection.fetchone
115131

132+
.. versionchanged:: 3.4.0
133+
134+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
135+
116136
.. automethod:: AsyncConnection.gettype
117137

118138
.. automethod:: AsyncConnection.is_healthy

doc/src/api_manual/async_cursor.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ AsyncCursor Methods
6868

6969
.. automethod:: AsyncCursor.execute
7070

71+
.. versionchanged:: 3.4.0
72+
73+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
74+
7175
.. versionchanged:: 3.3.0
7276

7377
The ``suspend_on_success`` parameter was added.

doc/src/api_manual/connection.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ Connection Methods
9090

9191
.. dbapimethodextension::
9292

93+
.. versionchanged:: 3.4.0
94+
95+
The ``fetch_decimals`` parameter was added.
96+
9397
.. versionadded:: 3.0.0
9498

9599
.. automethod:: Connection.fetch_df_batches
@@ -103,6 +107,10 @@ Connection Methods
103107

104108
.. dbapimethodextension::
105109

110+
.. versionchanged:: 3.4.0
111+
112+
The ``fetch_decimals`` parameter was added.
113+
106114
.. versionadded:: 3.0.0
107115

108116
.. automethod:: Connection.getSodaDatabase

doc/src/api_manual/cursor.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Cursor Methods
6969

7070
.. automethod:: Cursor.execute
7171

72+
.. versionchanged:: 3.4.0
73+
74+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
75+
7276
.. versionchanged:: 3.3.0
7377

7478
The ``suspend_on_success`` parameter was added.

doc/src/api_manual/module.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,12 +1405,12 @@ Also see the table :ref:`supporteddbtypes`.
14051405
.. data:: DB_TYPE_LONG_NVARCHAR
14061406

14071407
This constant can be used in output type handlers when fetching NCLOB
1408-
columns as a string. (Note a type handler is not needed if
1409-
:ref:`oracledb.defaults.fetch_lobs <defaults>` is set to False). For IN
1410-
binds, this constant can be used to create a bind variable in
1411-
:meth:`Cursor.var()` or via :meth:`Cursor.setinputsizes()`. The
1412-
``DB_TYPE_LONG_NVARCHAR`` value won't be shown in query metadata since it
1413-
is not a database type.
1408+
columns as a string. (Note a type handler is not needed if
1409+
:ref:`oracledb.defaults.fetch_lobs <defaults>`, or the equivalent execution
1410+
parameter, is set to *False*). For IN binds, this constant can be used to
1411+
create a bind variable in :meth:`Cursor.var()` or via
1412+
:meth:`Cursor.setinputsizes()`. The ``DB_TYPE_LONG_NVARCHAR`` value won't
1413+
be shown in query metadata since it is not a database type.
14141414

14151415
It will compare equal to the DB API type :data:`STRING`.
14161416

doc/src/api_manual/pipeline.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,26 @@ Pipeline Methods
4848

4949
.. automethod:: Pipeline.add_fetchall
5050

51+
.. versionchanged:: 3.4.0
52+
53+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
54+
5155
.. automethod:: Pipeline.add_fetchmany
5256

57+
.. versionchanged:: 3.4.0
58+
59+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
60+
5361
.. seealso::
5462

5563
:ref:`roundtrips`, and :ref:`rowlimit`
5664

5765
.. automethod:: Pipeline.add_fetchone
5866

67+
.. versionchanged:: 3.4.0
68+
69+
The ``fetch_lobs`` and ``fetch_decimals`` parameters were added.
70+
5971
.. seealso::
6072

6173
:ref:`rowlimit`
@@ -86,6 +98,14 @@ PipelineOp Attributes
8698

8799
:ref:`tuningfetch`
88100

101+
.. autoproperty:: PipelineOp.fetch_decimals
102+
103+
.. versionadded:: 3.4.0
104+
105+
.. autoproperty:: PipelineOp.fetch_lobs
106+
107+
.. versionadded:: 3.4.0
108+
89109
.. autoproperty:: PipelineOp.keyword_parameters
90110

91111
.. autoproperty:: PipelineOp.name

doc/src/release_notes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Thick Mode Changes
2525
Common Changes
2626
++++++++++++++
2727

28+
#) Added ``fetch_lobs`` and ``fetch_decimals`` parameters where applicable to
29+
the methods used for fetching rows or dataframes from the database. Note
30+
that for the creation of pipeline operations, if these parameters are not
31+
specified then the values of
32+
:attr:`oracledb.defaults.fetch_lobs <Defaults.fetch_lobs>` and
33+
:attr:`oracledb.defaults.fetch_decimals <Defaults.fetch_decimals>` are now
34+
stored with the operation and used during pipeline execution.
2835
#) API documentation is now generated from the source code.
2936

3037

doc/src/user_guide/json_data_type.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ for example:
412412

413413
.. code-block:: python
414414
415-
oracledb.defaults.fetch_lobs = False
416-
417415
cursor.execute("""
418416
select
419417
json_arrayagg(
@@ -423,7 +421,8 @@ for example:
423421
departments d
424422
where
425423
department_id < :did""",
426-
[50]);
424+
[50],
425+
fetch_lobs=False)
427426
j, = cursor.fetchone()
428427
print(j)
429428

doc/src/user_guide/lob_data.rst

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,14 @@ Fetching LOBs as Strings and Bytes
7474

7575
CLOBs and BLOBs smaller than 1 GB can queried from the database directly as
7676
strings and bytes. This can be much faster than streaming a :ref:`LOB Object
77-
<lobobj>`. Support is enabled by setting the :ref:`Defaults Object
78-
<defaults>`.
77+
<lobobj>`. Support is enabled by setting :attr:`oracledb.defaults.fetch_lobs
78+
<Defaults.fetch_lobs>`, or by setting the ``fetch_lobs`` parameter at statement
79+
execution:
7980

8081
.. code-block:: python
8182
8283
import oracledb
8384
84-
# returns strings or bytes instead of a locator
85-
oracledb.defaults.fetch_lobs = False
86-
8785
. . .
8886
8987
id_val = 1
@@ -92,7 +90,7 @@ strings and bytes. This can be much faster than streaming a :ref:`LOB Object
9290
cursor.execute("insert into lob_tbl (id, c, b) values (:1, :2, :3)",
9391
[id_val, text_data, binary_data])
9492
95-
cursor.execute("select c, b from lob_tbl where id = :1", [id_val])
93+
cursor.execute("select c, b from lob_tbl where id = :1", [id_val], fetch_lobs=False)
9694
clob_data, blob_data = cursor.fetchone()
9795
print("CLOB length:", len(clob_data))
9896
print("CLOB data:", clob_data)
@@ -106,8 +104,7 @@ This displays::
106104
BLOB length: 16
107105
BLOB data: b'Some binary data'
108106

109-
An older alternative to using ``oracledb.defaults.fetch_lobs`` is to use a type
110-
handler:
107+
An older alternative to using ``fetch_lobs`` is to use a type handler:
111108

112109
.. code-block:: python
113110
@@ -124,8 +121,9 @@ handler:
124121
Streaming LOBs (Read)
125122
=====================
126123

127-
Without setting ``oracledb.defaults.fetch_lobs`` to False, or without using an
128-
output type handler, the CLOB and BLOB values are fetched as :ref:`LOB
124+
Without setting :attr:`oracledb.defaults.fetch_lobs <Defaults.fetch_lobs>` or
125+
equivalent execution parameter to *False*, or without using an output type
126+
handler, then the CLOB and BLOB values are fetched as :ref:`LOB
129127
objects<lobobj>`. The size of the LOB object can be obtained by calling
130128
:meth:`LOB.size()` and the data can be read by calling :meth:`LOB.read()`:
131129

samples/json_blob.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@
105105

106106
# Using JSON_ARRAYAGG to extract a whole relational table as JSON
107107

108-
oracledb.defaults.fetch_lobs = False
109108
sql = """select json_arrayagg(
110109
json_object('key' is c.id,
111110
'name' is c.json_data)
112111
returning clob)
113112
from CustomersAsBlob c"""
114-
for r in cursor.execute(sql):
113+
for r in cursor.execute(sql, fetch_lobs=False):
115114
print(r)

0 commit comments

Comments
 (0)