Skip to content

Commit 623939f

Browse files
committed
Fix setting collection element directly. Add VARRAY tests
1 parent cb4d990 commit 623939f

File tree

4 files changed

+141
-3
lines changed

4 files changed

+141
-3
lines changed

lib/dbObject.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ const collectionProxyHandler = {
6161
const index = +prop;
6262
if (!isNaN(index)) {
6363
target.setElement(index, value);
64-
return;
64+
return true;
6565
}
6666
}
6767
target[prop] = value;
68+
return true;
6869
}
6970

7071
};

test/dbObject15.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* 214. dbObject15.js
20+
*
21+
* DESCRIPTION
22+
* Test DB Object collection methods.
23+
*
24+
*****************************************************************************/
25+
'use strict';
26+
27+
const oracledb = require('oracledb');
28+
const should = require('should');
29+
const dbconfig = require('./dbconfig.js');
30+
31+
describe('214. dbObject15.js', () => {
32+
33+
let conn, FrisbeeTeam;
34+
35+
const PLAYER_T = 'NODB_TYP_PLAYERTYPE';
36+
const TEAM_T = 'NODB_TYP_TEAMTYPE';
37+
38+
const FrisbeePlayers = [
39+
{ SHIRTNUMBER: 10, NAME: 'Emma' },
40+
{ SHIRTNUMBER: 11, NAME: 'Alex' },
41+
{ SHIRTNUMBER: 12, NAME: 'Dave' },
42+
{ SHIRTNUMBER: 13, NAME: 'Jack' },
43+
{ SHIRTNUMBER: 14, NAME: 'Emmet' }
44+
];
45+
46+
before(async () => {
47+
try {
48+
conn = await oracledb.getConnection(dbconfig);
49+
50+
let plsql =`
51+
CREATE OR REPLACE TYPE ${PLAYER_T} AS OBJECT (
52+
shirtnumber NUMBER,
53+
name VARCHAR2(20)
54+
);
55+
`;
56+
await conn.execute(plsql);
57+
58+
plsql =`
59+
CREATE OR REPLACE TYPE ${TEAM_T} AS VARRAY(10) OF ${PLAYER_T};
60+
`;
61+
await conn.execute(plsql);
62+
63+
const TeamTypeClass = await conn.getDbObjectClass(TEAM_T);
64+
FrisbeeTeam = new TeamTypeClass(FrisbeePlayers);
65+
66+
} catch(err) {
67+
should.not.exist(err);
68+
}
69+
}); // before()
70+
71+
after(async () => {
72+
try {
73+
74+
let sql = `DROP TYPE ${TEAM_T} FORCE`;
75+
await conn.execute(sql);
76+
77+
sql = `DROP TYPE ${PLAYER_T} FORCE`;
78+
await conn.execute(sql);
79+
80+
await conn.close();
81+
} catch(err) {
82+
should.not.exist(err);
83+
}
84+
}); // after()
85+
86+
it('214.1 Getter() - access collection elements directly', async () => {
87+
try {
88+
89+
for(let i = 0, element; i < FrisbeePlayers.length; i++) {
90+
element = FrisbeeTeam[i];
91+
should.strictEqual(element.SHIRTNUMBER, FrisbeePlayers[i].SHIRTNUMBER);
92+
should.strictEqual(element.NAME, FrisbeePlayers[i].NAME);
93+
}
94+
95+
} catch (err) {
96+
should.not.exist(err);
97+
}
98+
}); // 214.1
99+
100+
it('214.2 Setter() - access collection element directly', async () => {
101+
102+
// TypeError: 'set' on proxy: trap returned falsish for property '0'
103+
try {
104+
const substitute = {SHIRTNUMBER: 15, NAME: 'Chris'};
105+
FrisbeeTeam[0] = substitute;
106+
} catch (err) {
107+
should.not.exist(err);
108+
}
109+
}); // 214.2
110+
111+
it('214.3 Negative - delete the collection element directly', async () => {
112+
should.throws(
113+
function() {
114+
delete FrisbeeTeam[1];
115+
},
116+
/OCI-22164/
117+
);
118+
// OCI-22164: delete element operation is not allowed for variable-length array
119+
}); // 214.3
120+
121+
it('214.4 Negative - collection.deleteElement()', async () => {
122+
should.throws(
123+
function() {
124+
let firstIndex = FrisbeeTeam.getFirstIndex();
125+
FrisbeeTeam.deleteElement(firstIndex);
126+
},
127+
/OCI-22164/
128+
);
129+
}); // 214.4
130+
});

test/list.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4571,4 +4571,10 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
45714571
212.1 examples/plsqlvarrayrecord.js
45724572

45734573
213. dbObject14.js
4574-
213.1 examples/selectvarray.js
4574+
213.1 examples/selectvarray.js
4575+
4576+
214. dbObject15.js
4577+
214.1 Getter() - access collection elements directly
4578+
- 214.2 Setter() - access collection element directly
4579+
214.3 Negative - delete the collection element directly
4580+
214.4 Negative - collection.deleteElement()

test/opts/mocha.opts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,5 @@ test/dbObject10.js
237237
test/dbObject11.js
238238
test/dbObject12.js
239239
test/dbObject13.js
240-
test/dbObject14.js
240+
test/dbObject14.js
241+
test/dbObject15.js

0 commit comments

Comments
 (0)