Skip to content

Commit d25150c

Browse files
committed
Added capability to read XMLType data in DbObject in Thin mode
1 parent a297fac commit d25150c

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

doc/src/release_notes.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ node-oracledb Release Notes
77

88
For deprecated and desupported features, see :ref:`Deprecations and desupported features <deprecations>`.
99

10-
node-oracledb `v6.6 <https://github.com/oracle/node-oracledb/compare/v6.5.1...v6.6>`__ (TBD)
10+
node-oracledb `v6.6.0 <https://github.com/oracle/node-oracledb/compare/v6.5.1...v6.6.0>`__ (TBD)
1111
---------------------------------------------------------------------------------------------------------
1212

1313
Thin Mode Changes
1414
+++++++++++++++++
1515

16-
#) Fixed bug which throws an error ``NJS-130`` when calling
16+
#) Fixed bug which throws a ``TypeError: objType.attributes is not iterable``
17+
error when :ref:`DbObject Class <dbobjectclass>` instance contains an
18+
attribute of type ``SYS.XMLTYPE``.
19+
20+
#) Fixed bug which throws an ``NJS-130`` error when calling
1721
:meth:`connection.getDbObjectClass()` with an object type name containing
1822
``%ROWTYPE``.
1923

20-
#) Fixed bug which throws an `NJS-112` error during fetching of JSON and
21-
vector columns after table recreation. This is similar to the
22-
fix provided for GitHub issue #1565.
24+
#) Fixed bug which throws an ``NJS-112`` error during fetching of JSON and
25+
vector columns after table recreation. This fix is similar to the one
26+
provided for `Issue #1565 <https://github.com/oracle/node-oracledb/issues/
27+
1565>`__.
2328

2429
node-oracledb `v6.5.1 <https://github.com/oracle/node-oracledb/compare/v6.5.0...v6.5.1>`__ (23 May 2024)
2530
---------------------------------------------------------------------------------------------------------

lib/thin/connection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ class ThinConnectionImpl extends ConnectionImpl {
385385
info.elementType = this._parseTDSAttr(buf, info.elementTypeInfo);
386386
if (info.elementType === types.DB_TYPE_OBJECT) {
387387
await this._getElementTypeObj(info);
388+
if (info.elementTypeClass.isXmlType) {
389+
info.elementType = types.DB_TYPE_XMLTYPE;
390+
}
388391
}
389392
} else {
390393
if (info.attributes) { // skip for XML type as it has no attributes.
@@ -622,6 +625,9 @@ class ThinConnectionImpl extends ConnectionImpl {
622625
attrInfo.oid
623626
);
624627

628+
if (attr.typeClass.isXmlType) {
629+
attr.type = types.DB_TYPE_XMLTYPE;
630+
}
625631
if (attr.typeClass.partial) {
626632
this._partialDbObjectTypes.push(attr.typeClass);
627633
}

lib/thin/dbObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,14 @@ class ThinDbObjectImpl extends DbObjectImpl {
397397
case types.DB_TYPE_BOOLEAN:
398398
return buf.readBool();
399399
case types.DB_TYPE_OBJECT:
400+
case types.DB_TYPE_XMLTYPE:
400401
isNull = buf.getIsAtomicNull();
401402
if (isNull)
402403
return null;
403404
obj = new ThinDbObjectImpl(typeClass);
405+
if (obj._objType.isXmlType) {
406+
return readXML(obj._objType._connection, buf.readBytesWithLength());
407+
}
404408
if (obj._objType.isCollection || this._objType.isCollection) {
405409
obj.packedData = Buffer.from(buf.readBytesWithLength());
406410
} else {

test/dbObject20.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,4 +1218,55 @@ describe('290. dbObject20.js', () => {
12181218
});
12191219
});
12201220

1221+
(oracledb.thin ? describe : describe.skip)(`290.6 db Object tests with XML Value type`, () => {
1222+
let conn;
1223+
const TYPE1 = 'NODB_TEST_XMLTYPE';
1224+
const maxVarCharLen = 40;
1225+
1226+
before(async () => {
1227+
const sql = `CREATE TYPE ${TYPE1} FORCE AS OBJECT ( ID NUMBER,
1228+
XMLDATA sys.xmltype, NAME VARCHAR2(${maxVarCharLen}))`;
1229+
conn = await oracledb.getConnection(dbConfig);
1230+
await testsUtil.createType(conn, TYPE1, sql);
1231+
}); // before()
1232+
1233+
after(async () => {
1234+
if (conn) {
1235+
await testsUtil.dropType(conn, TYPE1);
1236+
await conn.close();
1237+
}
1238+
}); // after()
1239+
1240+
it('290.6.1 Verify XML value and metaData inside object', async () => {
1241+
const testXMLData =
1242+
'<Warehouse>\n ' +
1243+
'<WarehouseId>1</WarehouseId>\n ' +
1244+
'<WarehouseName>Melbourne, Australia</WarehouseName>\n ' +
1245+
'<Building>Owned</Building>\n ' +
1246+
'<Area>2020</Area>\n ' +
1247+
'<Docks>1</Docks>\n ' +
1248+
'<DockType>Rear load</DockType>\n ' +
1249+
'<WaterAccess>false</WaterAccess>\n ' +
1250+
'<RailAccess>N</RailAccess>\n ' +
1251+
'<Parking>Garage</Parking>\n ' +
1252+
'<VClearance>20</VClearance>\n' +
1253+
'</Warehouse>\n';
1254+
const numVal = 234;
1255+
const charVal = 'JOHN';
1256+
const expectedData = { "ID": numVal, "XMLDATA": testXMLData, "NAME": charVal };
1257+
const sql = `select ${TYPE1}(${expectedData.ID}, sys.xmltype('${expectedData.XMLDATA}'),
1258+
'${expectedData.NAME}') from dual`;
1259+
1260+
const result = await conn.execute(sql);
1261+
assert.strictEqual(JSON.stringify(result.rows[0][0]), JSON.stringify(expectedData));
1262+
1263+
// Validate metadata.
1264+
const xmlObjClass = result.metaData[0];
1265+
const pInObj = new xmlObjClass.dbTypeClass();
1266+
assert.strictEqual(pInObj.attributes.XMLDATA.type, oracledb.DB_TYPE_XMLTYPE);
1267+
assert.strictEqual(pInObj.attributes.ID.type, oracledb.DB_TYPE_NUMBER);
1268+
assert.strictEqual(pInObj.attributes.NAME.type, oracledb.DB_TYPE_VARCHAR);
1269+
});
1270+
});
1271+
12211272
});

test/list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5686,6 +5686,8 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
56865686
290.4.4 Verify table of VARCHAR2 with CHAR/BYTE specifier
56875687
290.5 Associative Arrays fetch
56885688
290.5.1 verify associative array outbinds
5689+
290.6 db Object tests with XML Value type
5690+
290.6.1 Verify XML value and metaData inside object
56895691

56905692
291. dbSchema.js
56915693
291.1 dbSchema and Annotations

0 commit comments

Comments
 (0)