Skip to content

Commit e127923

Browse files
Added support for CLOBs that were originally created in Oracle Database 9i and
tidied up documentation on LOB locator flags as well as encoding names (now using official names instead of aliases).
1 parent b5c8797 commit e127923

6 files changed

Lines changed: 24 additions & 8 deletions

File tree

doc/src/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Thin Mode Changes
2424
(`issue 542 <https://github.com/oracle/python-oracledb/issues/542>`__).
2525
#) Fixed bug writing boolean values to PL/SQL stored procedures and functions
2626
(`issue 568 <https://github.com/oracle/python-oracledb/issues/568>`__).
27+
#) Added support for CLOBs that were originally created in Oracle Database 9i.
2728

2829

2930
Thick Mode Changes

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ cdef str ARRAY_TYPE_CODE_UINT32
217217

218218
cdef const char* ENCODING_UTF8
219219
cdef const char* ENCODING_UTF16
220+
cdef const char* ENCODING_UTF16LE
220221

221222
cdef class ApiType:
222223
cdef:

src/oracledb/base_impl.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ cdef const char* DRIVER_VERSION
138138
cdef const char* DRIVER_INSTALLATION_URL = \
139139
"https://python-oracledb.readthedocs.io/en/" \
140140
"latest/user_guide/initialization.html"
141-
cdef const char* ENCODING_UTF8 = "UTF-8"
142-
cdef const char* ENCODING_UTF16 = "UTF-16BE"
141+
cdef const char* ENCODING_UTF8 = "UTF_8"
142+
cdef const char* ENCODING_UTF16 = "UTF_16_BE"
143+
cdef const char* ENCODING_UTF16LE = "UTF_16_LE"
143144

144145
# variables needed for dates when using pyarrow
145146
cdef cydatetime.datetime EPOCH_DATE = datetime.datetime(1970, 1, 1)

src/oracledb/impl/thin/constants.pxi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,14 @@ cdef enum:
305305
cdef enum:
306306
TNS_LOB_LOC_FLAGS_INIT = 0x08
307307

308+
# LOB locator flags (byte 3)
309+
cdef enum:
310+
TNS_LOB_LOC_FLAGS_VAR_LENGTH_CHARSET = 0x80
311+
308312
# LOB locator flags (byte 4)
309313
cdef enum:
310314
TNS_LOB_LOC_FLAGS_TEMP = 0x01
311-
TNS_LOB_LOC_FLAGS_VAR_LENGTH_CHARSET = 0x80
315+
TNS_LOB_LOC_FLAGS_LITTLE_ENDIAN = 0x40
312316

313317
# other LOB constants
314318
cdef enum:

src/oracledb/impl/thin/lob.pyx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2025, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 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
@@ -198,11 +198,19 @@ cdef class BaseThinLobImpl(BaseLobImpl):
198198

199199
cdef const char* _get_encoding(self):
200200
"""
201-
Return the encoding used by the LOB.
201+
Return the encoding used by the LOB. NCLOB always uses UTF-16. CLOB
202+
uses UTF-16 if the "variable length character set" flag is set, but
203+
uses UTF-16LE if the "little endian" flag is set (this flag is only for
204+
those CLOBs that were originally created in Oracle Database 9i). In all
205+
other cases, the encoding UTF-8 is used.
202206
"""
203-
if self.dbtype._csfrm == CS_FORM_NCHAR \
204-
or self._locator[TNS_LOB_LOC_OFFSET_FLAG_3] & \
207+
if self.dbtype._csfrm == CS_FORM_NCHAR:
208+
return ENCODING_UTF16
209+
elif self._locator[TNS_LOB_LOC_OFFSET_FLAG_3] & \
205210
TNS_LOB_LOC_FLAGS_VAR_LENGTH_CHARSET:
211+
if self._locator[TNS_LOB_LOC_OFFSET_FLAG_4] & \
212+
TNS_LOB_LOC_FLAGS_LITTLE_ENDIAN:
213+
return ENCODING_UTF16LE
206214
return ENCODING_UTF16
207215
return ENCODING_UTF8
208216

src/oracledb/thin_impl.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2025, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 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
@@ -125,6 +125,7 @@ from .base_impl cimport (
125125
DRIVER_VERSION,
126126
ENCODING_UTF8,
127127
ENCODING_UTF16,
128+
ENCODING_UTF16LE,
128129
GrowableBuffer,
129130
PY_TYPE_NUM_FLOAT,
130131
PY_TYPE_NUM_INT,

0 commit comments

Comments
 (0)