Skip to content

Commit 21e4a2d

Browse files
Fixed issue where unconstrained numbers containing integer values would be
fetched as floats when oracledb.defaults.fetch_lobs was set to `False`.
1 parent 2068d83 commit 21e4a2d

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ oracledb 1.0.1 (TBD)
2828
#) Thin: if an OS error occurs during the creation of a connection to the
2929
database, the error is wrapped by DPY-6005 as an instance of
3030
oracledb.ConnectionError.
31+
#) Fixed issue where unconstrained numbers containing integer values would be
32+
fetched as floats when oracledb.defaults.fetch_lobs was set to `False`.
3133

3234

3335
oracledb 1.0.0 (May 2022)

src/oracledb/impl/base/cursor.pyx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ cdef class BaseCursorImpl:
140140
"""
141141
cdef:
142142
BaseVarImpl var_impl
143+
uint32_t db_type_num
143144
object var
144145

145146
# if an output type handler is specified, call it; the output type
@@ -172,19 +173,20 @@ cdef class BaseCursorImpl:
172173

173174
# adjust the variable based on the defaults specified by the user, if
174175
# applicable
175-
if defaults.fetch_decimals and var_impl.dbtype is DB_TYPE_NUMBER:
176-
var_impl._preferred_num_type = NUM_TYPE_DECIMAL
176+
db_type_num = var_impl.dbtype.num
177+
if db_type_num == DB_TYPE_NUM_NUMBER:
178+
if defaults.fetch_decimals:
179+
var_impl._preferred_num_type = NUM_TYPE_DECIMAL
180+
elif var_impl.scale == 0 \
181+
or (var_impl.scale == -127 and var_impl.precision == 0):
182+
var_impl._preferred_num_type = NUM_TYPE_INT
177183
elif not defaults.fetch_lobs:
178-
if var_impl.dbtype is DB_TYPE_BLOB:
184+
if db_type_num == DB_TYPE_NUM_BLOB:
179185
var_impl.dbtype = DB_TYPE_LONG_RAW
180-
elif var_impl.dbtype is DB_TYPE_CLOB:
186+
elif db_type_num == DB_TYPE_NUM_CLOB:
181187
var_impl.dbtype = DB_TYPE_LONG
182-
elif var_impl.dbtype is DB_TYPE_NCLOB:
188+
elif db_type_num == DB_TYPE_NUM_NCLOB:
183189
var_impl.dbtype = DB_TYPE_LONG_NVARCHAR
184-
elif var_impl.dbtype is DB_TYPE_NUMBER:
185-
if var_impl.scale == 0 \
186-
or (var_impl.scale == -127 and var_impl.precision == 0):
187-
var_impl._preferred_num_type = NUM_TYPE_INT
188190

189191
# finalize variable and store in arrays
190192
var_impl._finalize_init()

tests/test_2200_number_var.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,16 @@ def test_2236_out_bind_binary_int_with_large_value(self):
464464
self.cursor.execute(statement, [simple_var])
465465
self.assertEqual(simple_var.getvalue(), -2**31 - 1)
466466

467+
def test_2237_fetch_number_with_lobs_default_false(self):
468+
"2237 - fetch a number with oracledb.defaults.fetch_lobs = False"
469+
orig_fetch_lobs = oracledb.defaults.fetch_lobs
470+
oracledb.defaults.fetch_lobs = False
471+
try:
472+
self.cursor.execute("select 1 from dual")
473+
result, = self.cursor.fetchone()
474+
self.assertEqual(type(result), int)
475+
finally:
476+
oracledb.defaults.fetch_lobs = orig_fetch_lobs
477+
467478
if __name__ == "__main__":
468479
test_env.run_test_cases()

0 commit comments

Comments
 (0)