Skip to content

Commit 0c129d3

Browse files
committed
Add DB_TYPE_XMLTYPE for XMLTYPE db column
1 parent dc792ad commit 0c129d3

File tree

9 files changed

+28
-3
lines changed

9 files changed

+28
-3
lines changed

doc/src/api_manual/oracledb.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ instead of ``result.metadata[0].fetchType == 2001``.
178178
* - ``oracledb.DB_TYPE_VARCHAR``
179179
- 2001
180180
- VARCHAR2
181+
* - ``oracledb.DB_TYPE_XMLTYPE``
182+
- 2032
183+
- XMLTYPE
181184

182185
Note that the values for these constants changed in node-oracledb 4.0.
183186

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ node-oracledb `v6.3.0 <https://github.com/oracle/node-oracledb/compare/v6.2.0...
1313
Common Changes
1414
++++++++++++++
1515

16+
#) Added constant ``oracledb.DB_TYPE_XMLTYPE`` to represent data of type
17+
``SYS.XMLTYPE`` in metadata ``fetchType`` and ``dbType`` attributes.
18+
Previously the constant used was ``oracledb.DB_TYPE_LONG`` in Thick mode.
19+
1620
#) Added support for using the Azure and Oracle Cloud Infrastructure (OCI)
1721
Software Development Kits (SDKs) to generate
1822
:ref:`authentication tokens <tokenbasedauthentication>`.

doc/src/user_guide/appendix_a.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ when binding numeric values.
763763
- DB_TYPE_OBJECT
764764
- Thick mode only
765765
* - XMLType
766-
- Not applicable
767-
- No
766+
- DB_TYPE_XMLTYPE
767+
- Thick mode only
768768

769769
.. _testingmode:
770770

lib/oracledb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ module.exports = {
867867
DB_TYPE_TIMESTAMP_LTZ: types.DB_TYPE_TIMESTAMP_LTZ,
868868
DB_TYPE_TIMESTAMP_TZ: types.DB_TYPE_TIMESTAMP_TZ,
869869
DB_TYPE_VARCHAR: types.DB_TYPE_VARCHAR,
870+
DB_TYPE_XMLTYPE: types.DB_TYPE_XMLTYPE,
870871

871872
// fetchInfo type defaulting
872873
DEFAULT: constants.DEFAULT,

lib/types.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ const DB_TYPE_UROWID = new DbType(2030,
196196
const DB_TYPE_VARCHAR = new DbType(2001,
197197
"DB_TYPE_VARCHAR", "VARCHAR2",
198198
{ oraTypeNum: 1, csfrm: constants.CSFRM_IMPLICIT, bufferSizeFactor: 4 });
199+
const DB_TYPE_XMLTYPE = new DbType(2032,
200+
"DB_TYPE_XMLTYPE", "XMLTYPE",
201+
{ oraTypeNum: 109, csfrm: constants.CSFRM_IMPLICIT, bufferSizeFactor: 2147483647 });
199202

200203
// database type conversion map: the top level key refers to the database
201204
// type being fetched and the value is another map; this map's key is the
@@ -304,7 +307,8 @@ const DB_TYPE_FETCH_TYPE_MAP = new Map([
304307
[DB_TYPE_TIMESTAMP_LTZ, DB_TYPE_TIMESTAMP_TZ],
305308
[DB_TYPE_TIMESTAMP_TZ, DB_TYPE_TIMESTAMP_TZ],
306309
[DB_TYPE_UROWID, DB_TYPE_UROWID],
307-
[DB_TYPE_VARCHAR, DB_TYPE_VARCHAR]
310+
[DB_TYPE_VARCHAR, DB_TYPE_VARCHAR],
311+
[DB_TYPE_XMLTYPE, DB_TYPE_XMLTYPE]
308312
]);
309313

310314
// additional aliases for types by column type name
@@ -351,6 +355,7 @@ module.exports = {
351355
DB_TYPE_VARCHAR,
352356
DB_TYPE_CONVERSION_MAP,
353357
DB_TYPE_FETCH_TYPE_MAP,
358+
DB_TYPE_XMLTYPE,
354359
getTypeByColumnTypeName,
355360
getTypeByNum,
356361
getTypeByOraTypeNum

src/njsResultSet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ static bool njsResultSet_setFetchTypes(napi_env env, njsResultSet *rs,
334334
case DPI_ORACLE_TYPE_LONG_NVARCHAR:
335335
case DPI_ORACLE_TYPE_LONG_VARCHAR:
336336
case DPI_ORACLE_TYPE_LONG_RAW:
337+
case DPI_ORACLE_TYPE_XMLTYPE:
337338
var->maxSize = (uint32_t) -1;
338339
break;
339340
case DPI_ORACLE_TYPE_DATE:

src/njsVariable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bool njsVariable_createBuffer(njsVariable *var, njsConnection *conn,
6262
case DPI_ORACLE_TYPE_LONG_NVARCHAR:
6363
case DPI_ORACLE_TYPE_LONG_VARCHAR:
6464
case DPI_ORACLE_TYPE_LONG_RAW:
65+
case DPI_ORACLE_TYPE_XMLTYPE:
6566
var->nativeTypeNum = DPI_NATIVE_TYPE_BYTES;
6667
break;
6768
case DPI_ORACLE_TYPE_NATIVE_FLOAT:

test/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('18. constants.js', function() {
7979
assert.strictEqual(2014, oracledb.DB_TYPE_TIMESTAMP_LTZ.num);
8080
assert.strictEqual(2013, oracledb.DB_TYPE_TIMESTAMP_TZ.num);
8181
assert.strictEqual(2001, oracledb.DB_TYPE_VARCHAR.num);
82+
assert.strictEqual(2032, oracledb.DB_TYPE_XMLTYPE.num);
8283

8384
});
8485

test/dataTypeXML.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,19 @@ describe('181. dataTypeXML.js', function() {
106106
it('181.1 basic case, insert XML data and query back', async () => {
107107
const conn = await oracledb.getConnection(dbConfig);
108108
const sql = "select content from " + tableName + " where num = :id";
109+
const expectedMetadata = {
110+
name: 'CONTENT',
111+
dbType: oracledb.DB_TYPE_XMLTYPE,
112+
nullable: false,
113+
isJson: false,
114+
dbTypeName: 'XMLTYPE',
115+
fetchType: oracledb.DB_TYPE_XMLTYPE
116+
};
109117
const bindVar = { id: testRowID };
110118
const options = { outFormat: oracledb.OUT_FORMAT_OBJECT };
111119
const result = await conn.execute(sql, bindVar, options);
112120
assert.strictEqual(result.rows[0].CONTENT, testXMLData);
121+
assert.deepStrictEqual(result.metaData[0], expectedMetadata);
113122
await conn.close();
114123
}); // 181.1
115124

0 commit comments

Comments
 (0)