Skip to content

Commit dc2365c

Browse files
Added type oracledb.DB_TYPE_XMLTYPE to represent data of type
"SYS.XMLTYPE" in the database.
1 parent 4776da9 commit dc2365c

File tree

11 files changed

+30
-5
lines changed

11 files changed

+30
-5
lines changed

doc/src/api_manual/module.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,12 @@ when binding data.
23472347
type VARCHAR2. It will compare equal to the DB API type :data:`STRING`.
23482348

23492349

2350+
.. data:: DB_TYPE_XMLTYPE
2351+
2352+
Describes columns, attributes or array elements in a database that are of
2353+
type SYS.XMLTYPE.
2354+
2355+
23502356
.. _dbtypesynonyms:
23512357

23522358
Database Type Synonyms

doc/src/release_notes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Common Changes
4444
associated with columns that are being fetched. SQL domains and annotations
4545
require Oracle Database 23c. If using python-oracledb Thick mode, Oracle
4646
Client 23c is also required.
47+
#) Added type :data:`~oracledb.DB_TYPE_XMLTYPE` to represent data of type
48+
``SYS.XMLTYPE`` in the database. Previously the value of
49+
:data:`FetchInfo.type_code` for data of this type was
50+
:data:`~oracledb.DB_TYPE_LONG` in Thick mode and
51+
:data:`~oracledb.DB_TYPE_OBJECT` in Thin mode.
4752
#) Added support for parsing the ``FAILOVER`` clause in full connect
4853
descriptors.
4954
#) Fixed bug with getting unknown attributes from DbObject instances.

src/oracledb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
DB_TYPE_UNKNOWN as DB_TYPE_UNKNOWN,
222222
DB_TYPE_UROWID as DB_TYPE_UROWID,
223223
DB_TYPE_VARCHAR as DB_TYPE_VARCHAR,
224+
DB_TYPE_XMLTYPE as DB_TYPE_XMLTYPE,
224225
# API types
225226
BINARY as BINARY,
226227
DATETIME as DATETIME,

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ cdef enum:
7070
DB_TYPE_NUM_UNKNOWN = 0
7171
DB_TYPE_NUM_UROWID = 2030
7272
DB_TYPE_NUM_VARCHAR = 2001
73+
DB_TYPE_NUM_XMLTYPE = 2032
7374

7475

7576
cdef class ApiType:

src/oracledb/impl/base/types.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ DB_TYPE_UNKNOWN = DbType(DB_TYPE_NUM_UNKNOWN, "DB_TYPE_UNKNOWN", "UNKNOWN")
164164
DB_TYPE_UROWID = DbType(DB_TYPE_NUM_UROWID, "DB_TYPE_UROWID", "UROWID", 208)
165165
DB_TYPE_VARCHAR = DbType(DB_TYPE_NUM_VARCHAR, "DB_TYPE_VARCHAR", "VARCHAR2",
166166
1, 4000, csfrm=1, buffer_size_factor=4)
167+
DB_TYPE_XMLTYPE = DbType(DB_TYPE_NUM_XMLTYPE, "DB_TYPE_XMLTYPE", "XMLTYPE",
168+
109, csfrm=1, buffer_size_factor=2147483647)
167169

168170
# additional aliases
169171
db_type_by_ora_name["DOUBLE PRECISION"] = DB_TYPE_NUMBER

src/oracledb/impl/thick/odpi

Submodule odpi updated from 3102b45 to 3d5bd6f

src/oracledb/impl/thick/odpi.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ cdef extern from "impl/thick/odpi/embed/dpi.c":
130130
DPI_ORACLE_TYPE_TIMESTAMP_LTZ
131131
DPI_ORACLE_TYPE_TIMESTAMP_TZ
132132
DPI_ORACLE_TYPE_VARCHAR
133+
DPI_ORACLE_TYPE_XMLTYPE
133134

134135
# SODA flags
135136
enum:

src/oracledb/impl/thick/utils.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ cdef object _convert_to_python(ThickConnImpl conn_impl, DbType dbtype,
279279
or oracle_type == DPI_ORACLE_TYPE_VARCHAR \
280280
or oracle_type == DPI_ORACLE_TYPE_NVARCHAR \
281281
or oracle_type == DPI_ORACLE_TYPE_LONG_VARCHAR \
282-
or oracle_type == DPI_ORACLE_TYPE_LONG_NVARCHAR:
282+
or oracle_type == DPI_ORACLE_TYPE_LONG_NVARCHAR \
283+
or oracle_type == DPI_ORACLE_TYPE_XMLTYPE:
283284
as_bytes = &dbvalue.asBytes
284285
return as_bytes.ptr[:as_bytes.length].decode()
285286
elif oracle_type == DPI_ORACLE_TYPE_NUMBER:

src/oracledb/impl/thin/messages.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ cdef class MessageWithData(Message):
607607
column_value = buf.read_oson()
608608
elif ora_type_num == TNS_DATA_TYPE_INT_NAMED:
609609
typ_impl = var_impl.objtype
610-
if typ_impl.is_xml_type:
610+
if typ_impl is None:
611611
column_value = buf.read_xmltype(self.conn_impl)
612612
else:
613613
obj_impl = buf.read_dbobject(typ_impl)
@@ -720,7 +720,10 @@ cdef class MessageWithData(Message):
720720
self.type_cache = get_dbobject_type_cache(cache_num)
721721
typ_impl = self.type_cache.get_type_for_info(oid, schema, None,
722722
name)
723-
fetch_info.objtype = typ_impl
723+
if typ_impl.is_xml_type:
724+
fetch_info.dbtype = DB_TYPE_XMLTYPE
725+
else:
726+
fetch_info.objtype = typ_impl
724727
return fetch_info
725728

726729
cdef int _process_describe_info(self, ReadBuffer buf,

src/oracledb/thin_impl.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ from .base_impl cimport ConnectParamsImpl, PoolParamsImpl, BaseDbObjectAttrImpl
8383
from .base_impl cimport BaseDbObjectImpl, BaseDbObjectTypeImpl
8484
from .base_impl import DB_TYPE_BLOB, DB_TYPE_CLOB, DB_TYPE_NCLOB
8585
from .base_impl import DB_TYPE_BINARY_INTEGER, DB_TYPE_CURSOR, DB_TYPE_OBJECT
86+
from .base_impl import DB_TYPE_XMLTYPE
8687

8788
ctypedef unsigned char char_type
8889

tests/test_2500_string_var.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,17 @@ def test_2530_short_xml_as_string(self):
486486
"2530 - test fetching XMLType (< 1K) as a string"
487487
self.cursor.execute(
488488
"""
489-
select XMLElement("string", stringCol)
489+
select XMLElement("string", stringCol) as xml
490490
from TestStrings
491491
where intCol = 1
492492
"""
493493
)
494494
(actual_value,) = self.cursor.fetchone()
495495
self.assertEqual(actual_value, "<string>String 1</string>")
496+
self.assertEqual(
497+
self.cursor.description,
498+
[("XML", oracledb.DB_TYPE_XMLTYPE, None, None, None, None, True)],
499+
)
496500

497501
def test_2531_long_xml_as_string(self):
498502
"2531 - test inserting and fetching XMLType (1K) as a string"

0 commit comments

Comments
 (0)