Skip to content

Commit 3d3feea

Browse files
Fixed bug causing a leading zero to be returned when certain numbers are
converted to strings (one example noted here: sqlalchemy/sqlalchemy#8744 (comment)).
1 parent 884a1ed commit 3d3feea

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Thin Mode Changes
2424
cursor.
2525
#) Fixed bug preventing a cursor from being reused after it was bound as a
2626
REF CURSOR to a PL/SQL block that closes it.
27+
#) Fixed bug causing a leading zero to be returned when certain numbers are
28+
converted to strings.
2729

2830
Thick Mode Changes
2931
++++++++++++++++++

src/oracledb/impl/thin/buffer.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ cdef class Buffer:
570570

571571
# process the first digit; leading zeroes are ignored
572572
digit = <uint8_t> byte // 10
573-
if digit == 0 and i == 0:
573+
if digit == 0 and num_digits == 0:
574574
decimal_point_index -= 1
575575
elif digit == 10:
576576
digits[num_digits] = 1

tests/test_2200_number_var.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def output_type_handler_decimal(self, cursor, name, default_type, size,
4444
return cursor.var(str, 255, outconverter=decimal.Decimal,
4545
arraysize=cursor.arraysize)
4646

47+
def output_type_handler_str(self, cursor, name, default_type, size,
48+
precision, scale):
49+
return cursor.var(str, 255, arraysize=cursor.arraysize)
50+
51+
4752
def setUp(self):
4853
super().setUp()
4954
self.raw_data = []
@@ -471,5 +476,13 @@ def test_2237_fetch_number_with_lobs_default_false(self):
471476
result, = self.cursor.fetchone()
472477
self.assertEqual(type(result), int)
473478

479+
def test_2238_fetch_small_constant_with_decimal_point(self):
480+
"2238 - fetch a small constant with a decimal point"
481+
self.cursor.outputtypehandler = self.output_type_handler_str
482+
self.cursor.execute("select 3 / 2 from dual")
483+
result, = self.cursor.fetchone()
484+
self.assertTrue(len(result) == 3 and result[0] == "1" \
485+
and result[-1] == "5")
486+
474487
if __name__ == "__main__":
475488
test_env.run_test_cases()

0 commit comments

Comments
 (0)