Skip to content

Commit 36a2951

Browse files
Fixed bug when decoding PL/SQL booleans in Oracle Database 12.1 (#565).
1 parent 6072f01 commit 36a2951

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ oracledb `3.4.2 <https://github.com/oracle/python-oracledb/compare/v3.4.1...v3.4
1919
Thin Mode Changes
2020
+++++++++++++++++
2121

22+
#) Fixed bug when decoding PL/SQL booleans in Oracle Database 12.1
23+
(`issue 565 <https://github.com/oracle/python-oracledb/issues/565>`__).
2224
#) Fixed bug when a :ref:`DbObject <dbobject>` instance contains an attribute
2325
of type ``SYS.XMLTYPE``.
2426

src/oracledb/impl/base/buffer.pyx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,17 @@ cdef class Buffer:
183183
elif ora_type_num == ORA_TYPE_NUM_BINARY_FLOAT:
184184
decode_binary_float(ptr, num_bytes, &data.buffer)
185185
elif ora_type_num == ORA_TYPE_NUM_BOOLEAN:
186-
decode_bool(ptr, num_bytes, &data.buffer)
186+
# inside a database object, the boolean is represented as a
187+
# big endian 32-bit integer (either 0 or 1)
188+
if from_dbobject:
189+
data.buffer.as_bool = ptr[num_bytes - 1] == 1
190+
# outside a database object, the boolean is represented as an
191+
# encoded integer (0x00 for false and 0x0101 for true); older
192+
# versions like 12.1 also return 0x8101 (-1) for null values
193+
# but this can safely be ignored as the null indicator is sent
194+
# as a separate field afterwards anyways
195+
else:
196+
data.buffer.as_bool = ptr[0] == 1
187197
elif ora_type_num in (
188198
ORA_TYPE_NUM_CHAR,
189199
ORA_TYPE_NUM_LONG,

src/oracledb/impl/base/decoders.pyx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2024, Oracle and/or its affiliates.
2+
# Copyright (c) 2024, 2026, 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
@@ -84,14 +84,6 @@ cdef int decode_binary_float(const uint8_t *ptr, ssize_t num_bytes,
8484
memcpy(&buffer.as_float, &all_bits, 4)
8585

8686

87-
cdef int decode_bool(const uint8_t* ptr, ssize_t num_bytes,
88-
OracleDataBuffer *buffer) except -1:
89-
"""
90-
Decode a boolean value from raw bytes.
91-
"""
92-
buffer.as_bool = (ptr[num_bytes - 1] == 1)
93-
94-
9587
cdef int decode_date(const uint8_t* ptr, ssize_t num_bytes,
9688
OracleDataBuffer *buffer) except -1:
9789
"""

0 commit comments

Comments
 (0)