Skip to content

Commit 3a12a06

Browse files
committed
Fix the length property to work properly with DbObject collection types
1 parent 7ecfcf2 commit 3a12a06

13 files changed

+75
-37
lines changed

doc/src/release_notes.rst

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ For deprecated and desupported features, see
1111
node-oracledb `v6.8.0 <https://github.com/oracle/node-oracledb/compare/v6.7.1...v6.8.0>`__ (TBD)
1212
---------------------------------------------------------------------------------------------------------
1313

14+
Common Changes
15+
++++++++++++++
16+
17+
#) Fixed :attr:`~dbObject.length` property for the database object
18+
collection types, which was broken from node-oracledb 6.0.
19+
1420
Thin Mode Changes
1521
+++++++++++++++++
1622

examples/plsqlarray.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2016, 2024, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2016, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -175,6 +175,7 @@ async function run() {
175175
);
176176
console.log("Binds returned:");
177177
console.log(result.outBinds);
178+
console.log("No.of beaches:", result.outBinds.beach_out.length);
178179

179180
//
180181
// PL/SQL array bind IN OUT parameters:
@@ -200,6 +201,7 @@ async function run() {
200201
);
201202
console.log("Binds returned:");
202203
console.log(result.outBinds);
204+
console.log("No.of beaches:", result.outBinds.beach_inout.length);
203205

204206
} catch (err) {
205207
console.error(err);

lib/dbObject.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2025, Oracle and/or its affiliates.
22

33
//----------------------------------------------------------------------------
44
//
@@ -253,6 +253,17 @@ class BaseDbObject {
253253
return this._objType.fqn;
254254
}
255255

256+
//---------------------------------------------------------------------------
257+
// length
258+
//
259+
// Length of the database object type, if it is a collection. Else it
260+
// returns undefined.
261+
//---------------------------------------------------------------------------
262+
get length() {
263+
if (this.isCollection)
264+
return this._impl.getLength();
265+
return undefined;
266+
}
256267
//---------------------------------------------------------------------------
257268
// getElement()
258269
//

lib/thin/dbObject.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2023, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2023, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -610,6 +610,20 @@ class ThinDbObjectImpl extends DbObjectImpl {
610610
return result;
611611
}
612612

613+
//---------------------------------------------------------------------------
614+
// getLength
615+
//
616+
// Gets the size of the database object if it is a collection. Else returns
617+
// undefined.
618+
//---------------------------------------------------------------------------
619+
getLength() {
620+
this._ensureUnpacked();
621+
if (this.unpackedArray)
622+
return this.unpackedArray.length;
623+
if (this.unpackedAssocArray)
624+
return this.unpackedAssocArray.size;
625+
}
626+
613627
//---------------------------------------------------------------------------
614628
// hasElement()
615629
//

test/dbObject1.js

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2024, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -113,6 +113,7 @@ describe('200. dbObject1.js', () => {
113113
};
114114
const objClass = await conn.getDbObjectClass(TYPE);
115115
const testObj = new objClass(objData);
116+
assert.equal(testObj.length, undefined);
116117
const seq = 101;
117118

118119
let result = await conn.execute(sql, [seq, testObj]);
@@ -439,7 +440,7 @@ describe('200. dbObject1.js', () => {
439440

440441
const result = await runPlSQL(sql, TYPE_SMALL_PRECISION);
441442
assert.strictEqual(result.outBinds.arg.TESTNUMBER, retVal);
442-
}); // 202.2.1
443+
}); // 200.2.1
443444

444445
it('200.2.2 using Large Precision', async () => {
445446
const retVal = 560;
@@ -448,7 +449,7 @@ describe('200. dbObject1.js', () => {
448449

449450
const result = await runPlSQL(sql, TYPE_LARGE_PRECISION);
450451
assert.strictEqual(result.outBinds.arg.TESTNUMBER, retVal);
451-
}); // 202.2.2
452+
}); // 200.2.2
452453
});
453454

454455
describe('200.3 Binary Float property', function() {
@@ -496,7 +497,7 @@ describe('200. dbObject1.js', () => {
496497
const query = `SELECT * FROM ${TABLE_BINARY_FLOAT} WHERE ID = :id`;
497498
const fetchedResult = await conn.execute(query, [id]);
498499
assert.strictEqual(fetchedResult.rows[0][1].TESTFLOAT, 123.44999694824219);
499-
}); // 202.3.1
500+
}); // 200.3.1
500501

501502
it('200.3.2 insert an object with a negative float value', async () => {
502503
const objClass = await conn.getDbObjectClass(TYPE_BINARY_FLOAT);
@@ -512,7 +513,7 @@ describe('200. dbObject1.js', () => {
512513
const query = `SELECT * FROM ${TABLE_BINARY_FLOAT} WHERE ID = :id`;
513514
const fetchedResult = await conn.execute(query, [id]);
514515
assert.strictEqual(fetchedResult.rows[0][1].TESTFLOAT, -987.6500244140625);
515-
}); // 202.3.2
516+
}); // 200.3.2
516517

517518
it('200.3.3 insert an object with null float value', async () => {
518519
const objClass = await conn.getDbObjectClass(TYPE_BINARY_FLOAT);
@@ -528,7 +529,7 @@ describe('200. dbObject1.js', () => {
528529
const query = `SELECT * FROM ${TABLE_BINARY_FLOAT} WHERE ID = :id`;
529530
const fetchedResult = await conn.execute(query, [id]);
530531
assert.strictEqual(fetchedResult.rows[0][1].TESTFLOAT, null);
531-
}); // 202.3.3
532+
}); // 200.3.3
532533

533534
it('200.3.4 handle extreme float values (Infinity)', async () => {
534535
const objClass = await conn.getDbObjectClass(TYPE_BINARY_FLOAT);
@@ -544,7 +545,7 @@ describe('200. dbObject1.js', () => {
544545
const query = `SELECT * FROM ${TABLE_BINARY_FLOAT} WHERE ID = :id`;
545546
const fetchedResult = await conn.execute(query, [id]);
546547
assert.strictEqual(fetchedResult.rows[0][1].TESTFLOAT, Infinity);
547-
}); // 202.3.4
548+
}); // 200.3.4
548549

549550
it('200.3.5 handle extreme float values (-Infinity)', async () => {
550551
const objClass = await conn.getDbObjectClass(TYPE_BINARY_FLOAT);
@@ -560,7 +561,7 @@ describe('200. dbObject1.js', () => {
560561
const query = `SELECT * FROM ${TABLE_BINARY_FLOAT} WHERE ID = :id`;
561562
const fetchedResult = await conn.execute(query, [id]);
562563
assert.strictEqual(fetchedResult.rows[0][1].TESTFLOAT, -Infinity);
563-
}); // 202.3.5
564+
}); // 200.3.5
564565

565566
it('200.3.6 handle NaN (Not-a-Number)', async () => {
566567
const objClass = await conn.getDbObjectClass(TYPE_BINARY_FLOAT);
@@ -576,7 +577,7 @@ describe('200. dbObject1.js', () => {
576577
const query = `SELECT * FROM ${TABLE_BINARY_FLOAT} WHERE ID = :id`;
577578
const fetchedResult = await conn.execute(query, [id]);
578579
assert.ok(Number.isNaN(fetchedResult.rows[0][1].TESTFLOAT));
579-
}); // 202.3.6
580+
}); // 200.3.6
580581

581582
it('200.3.7 handle undefined and default values', async () => {
582583
const objClass = await conn.getDbObjectClass(TYPE_BINARY_FLOAT);
@@ -610,7 +611,7 @@ describe('200. dbObject1.js', () => {
610611
const fetchedResultEmpty = await conn.execute(queryEmpty, [idEmpty]);
611612

612613
assert.strictEqual(fetchedResultEmpty.rows[0][1].TESTFLOAT, null);
613-
}); // 202.3.7
614+
}); // 200.3.7
614615
});
615616

616617
describe('200.4 Binary Double property', function() {
@@ -658,7 +659,7 @@ describe('200. dbObject1.js', () => {
658659
const query = `SELECT * FROM ${TABLE_BINARY_DOUBLE} WHERE ID = :id`;
659660
const fetchedResult = await conn.execute(query, [id]);
660661
assert.strictEqual(fetchedResult.rows[0][1].TESTDOUBLE, 123456.7890123);
661-
}); // 202.4.
662+
}); // 200.4.1
662663

663664
it('200.4.2 insert an object with a negative double value', async () => {
664665
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -674,7 +675,7 @@ describe('200. dbObject1.js', () => {
674675
const query = `SELECT * FROM ${TABLE_BINARY_DOUBLE} WHERE ID = :id`;
675676
const fetchedResult = await conn.execute(query, [id]);
676677
assert.strictEqual(fetchedResult.rows[0][1].TESTDOUBLE, -987654.321);
677-
}); // 202.4.2
678+
}); // 200.4.2
678679

679680
it('200.4.3 insert an object with null double value', async () => {
680681
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -690,7 +691,7 @@ describe('200. dbObject1.js', () => {
690691
const query = `SELECT * FROM ${TABLE_BINARY_DOUBLE} WHERE ID = :id`;
691692
const fetchedResult = await conn.execute(query, [id]);
692693
assert.strictEqual(fetchedResult.rows[0][1].TESTDOUBLE, null);
693-
}); // 202.4.3
694+
}); // 200.4.3
694695

695696
it('200.4.4 handle extreme double values (Infinity)', async () => {
696697
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -706,7 +707,7 @@ describe('200. dbObject1.js', () => {
706707
const query = `SELECT * FROM ${TABLE_BINARY_DOUBLE} WHERE ID = :id`;
707708
const fetchedResult = await conn.execute(query, [id]);
708709
assert.strictEqual(fetchedResult.rows[0][1].TESTDOUBLE, Infinity);
709-
}); // 202.4.4
710+
}); // 200.4.4
710711

711712
it('200.4.5 handle extreme double values (-Infinity)', async () => {
712713
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -722,7 +723,7 @@ describe('200. dbObject1.js', () => {
722723
const query = `SELECT * FROM ${TABLE_BINARY_DOUBLE} WHERE ID = :id`;
723724
const fetchedResult = await conn.execute(query, [id]);
724725
assert.strictEqual(fetchedResult.rows[0][1].TESTDOUBLE, -Infinity);
725-
}); // 202.4.5
726+
}); // 200.4.5
726727

727728
it('200.4.6 handle NaN (Not-a-Number)', async () => {
728729
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -738,7 +739,7 @@ describe('200. dbObject1.js', () => {
738739
const query = `SELECT * FROM ${TABLE_BINARY_DOUBLE} WHERE ID = :id`;
739740
const fetchedResult = await conn.execute(query, [id]);
740741
assert.ok(Number.isNaN(fetchedResult.rows[0][1].TESTDOUBLE));
741-
}); // 202.4.6
742+
}); // 200.4.6
742743

743744
it('200.4.7 test very large and very small double values', async () => {
744745
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -763,7 +764,7 @@ describe('200. dbObject1.js', () => {
763764
const fetchedResult = await conn.execute(query, [id]);
764765
assert.strictEqual(fetchedResult.rows[0][1].TESTDOUBLE, testValues[i]);
765766
}
766-
}); // 202.4.7
767+
}); // 200.4.7
767768

768769
it('200.4.8 create an object with multiple attributes including binary_double', async () => {
769770
const TYPE_MULTI_DOUBLE = 'NODB_TYP_OBJ_MULTI_DOUBLE';
@@ -811,7 +812,7 @@ describe('200. dbObject1.js', () => {
811812
await conn.execute(testsUtil.sqlDropTable(TABLE_MULTI_DOUBLE));
812813
await conn.execute(`DROP TYPE ${TYPE_MULTI_DOUBLE}`);
813814
}
814-
}); // 202.4.8
815+
}); // 200.4.8
815816

816817
it('200.4.9 handle undefined and default values', async () => {
817818
const objClass = await conn.getDbObjectClass(TYPE_BINARY_DOUBLE);
@@ -845,6 +846,6 @@ describe('200. dbObject1.js', () => {
845846
const fetchedResultEmpty = await conn.execute(queryEmpty, [idEmpty]);
846847

847848
assert.strictEqual(fetchedResultEmpty.rows[0][1].TESTDOUBLE, null);
848-
}); // 202.4.8
849-
}); // 202.4
849+
}); // 200.4.8
850+
}); // 200.4
850851
});

test/dbObject12.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2024, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -128,7 +128,7 @@ describe('211. dbObject12.js', function() {
128128
assert.strictEqual(out.POS, (obj3.POS * 2));
129129
assert.strictEqual(out.FORCE, (obj3.POS * -2));
130130

131-
// Batch exeuction with executeMany()
131+
// Batch execution with executeMany()
132132
const obj4 = [
133133
{ NAME: 'Train', POS: 78 },
134134
{ NAME: 'Bike', POS: 83 },

test/dbObject13.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -115,12 +115,13 @@ describe('212. dbObject13.js', function() {
115115
}
116116
};
117117
const result = await conn.execute(CALL, binds);
118+
assert.strictEqual(result.outBinds.outbv.length, players.length);
118119

119-
for (let i = 0, out = result.outBinds.outbv; i < players.length; i++) {
120-
assert.strictEqual(out[i].NAME, players[i].NAME);
121-
assert.strictEqual(out[i].POSITION, players[i].POSITION);
122-
assert.strictEqual(out[i].SHIRTNUMBER, players[i].SHIRTNUMBER);
123-
assert.strictEqual(out[i].ADDRESS, players[i].ADDRESS);
120+
for (let i = 0; i < players.length; i++) {
121+
assert.strictEqual(result.outBinds.outbv[i].NAME, players[i].NAME);
122+
assert.strictEqual(result.outBinds.outbv[i].POSITION, players[i].POSITION);
123+
assert.strictEqual(result.outBinds.outbv[i].SHIRTNUMBER, players[i].SHIRTNUMBER);
124+
assert.strictEqual(result.outBinds.outbv[i].ADDRESS, players[i].ADDRESS);
124125
}
125126
}); // 212.1
126127

test/dbObject14.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -216,6 +216,7 @@ describe('213.2 Object Collection with BLOB fields', () => {
216216
{ ID: null }
217217
];
218218
const bufTypeCollection = new bufTypeCollectionClass(bufArray);
219+
assert.strictEqual(bufTypeCollection.length, bufArray.length);
219220

220221
// insert data into table
221222
let sql = `BEGIN ${TEST_PROC}(:buff_collection); END;`;

test/dbObject15.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2021, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -86,6 +86,7 @@ describe('214. dbObject15.js', () => {
8686
assert.strictEqual(element.SHIRTNUMBER, FrisbeePlayers[i].SHIRTNUMBER);
8787
assert.strictEqual(element.NAME, FrisbeePlayers[i].NAME);
8888
}
89+
assert.equal(FrisbeeTeam.length, 5);
8990
}); // 214.1
9091

9192
it('214.2 Setter() - access collection element directly', function() {

test/dbObject20.js

+1
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ describe('290. dbObject20.js', () => {
12151215
const res = result.outBinds.ret;
12161216
const outMap = res.toMap();
12171217
assert.deepStrictEqual(JSON.stringify(Object.fromEntries(outMap)), JSON.stringify(inDataobj));
1218+
assert.equal(res.length, 3);
12181219

12191220
// Check if you are able to access the indexes, keys and values across
12201221
// associative arrays in proper order

test/dbObject8.js

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ describe('207. dbObject8.js', () => {
118118
farm2.HARVEST = new HarvestType(['carrots', 'peas']);
119119
farm2.HARVEST.trim(1); // whoops! no peas
120120
farm2.HARVEST.append('tomatoes'); // extend the collection
121+
assert.strictEqual(farm2.HARVEST.length, 2);
121122
crops[1] = farm2.HARVEST.getValues();
122123
assert.deepStrictEqual(crops[1], [ 'carrots', 'tomatoes' ]);
123124

test/dbObject9.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2019, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -53,7 +53,6 @@ describe('208. dbObject9.js', function() {
5353
isRunnable = await testsUtil.checkPrerequisites();
5454
if (!isRunnable) {
5555
this.skip();
56-
return;
5756
} else {
5857
conn = await oracledb.getConnection(dbConfig);
5958

test/dbObjectsNestedTable.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2021, 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2021, 2025, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -78,7 +78,7 @@ describe('197. dbObjectsNestedTable.js', () => {
7878
obj = result.rows[0][1];
7979

8080
const arr = obj.getValues ();
81-
assert.equal (arr.length, 3);
81+
assert.equal (arr.length, obj.length);
8282

8383
assert.strictEqual (arr[0], "Shipping");
8484
assert.strictEqual (arr[1], "Finance");

0 commit comments

Comments
 (0)