Skip to content

Commit b811089

Browse files
committed
Improve validation of executeMany() arguments
1 parent e4b90e1 commit b811089

File tree

3 files changed

+83
-38
lines changed

3 files changed

+83
-38
lines changed

src/njsConnection.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,15 @@ bool njsConnection::ProcessExecuteManyBinds(Local<Array> binds,
920920
if (!mval.ToLocal (&bindDefs))
921921
return false;
922922
}
923-
if (!bindDefs->IsUndefined() && !bindDefs->IsArray())
923+
924+
// bindDefs must be an array or object
925+
if (!bindDefs->IsUndefined() && !bindDefs->IsArray()) {
926+
if (!bindDefs->IsObject()) {
927+
baton->error = njsMessages::Get(errInvalidParameterValue, 2);
928+
return false;
929+
}
924930
bindNames = bindDefs.As<Object>()->GetOwnPropertyNames();
931+
}
925932

926933
// initialize variables; if there are no variables, nothing further to do!
927934
if (!InitBindVars(bindDefs.As<Object>(), bindNames, baton))

test/executeMany2.js

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -31,58 +31,95 @@
3131
*****************************************************************************/
3232
'use strict';
3333

34-
var oracledb = require('oracledb');
35-
var should = require('should');
36-
var dbconfig = require('./dbconfig.js');
34+
const oracledb = require('oracledb');
35+
const should = require('should');
36+
const dbconfig = require('./dbconfig.js');
37+
const sodaUtil = require('./sodaUtil.js');
3738

3839
describe('172. executeMany2.js', function() {
3940

40-
before(function() {
41-
if (!dbconfig.test.DBA_PRIVILEGE) this.skip();
42-
});
43-
44-
// Currently skipped for
45-
// Segmentation fault: 11
46-
it.skip('172.1 Negative - incorrect parameters', async () => {
41+
it('172.1 Negative - incorrect parameters', async () => {
4742

4843
let conn;
44+
let schema = dbconfig.user.toUpperCase();
45+
4946
try {
50-
const connectionDetails = {
51-
user : dbconfig.test.DBA_user,
52-
password : dbconfig.test.DBA_password,
53-
connectString : dbconfig.connectString,
54-
privilege : oracledb.SYSDBA
55-
};
56-
const schema = 'T_APPDEV4DB';
57-
const password = 'oracle';
47+
conn = await oracledb.getConnection(dbconfig);
48+
await conn.execute(
49+
`BEGIN EXECUTE IMMEDIATE 'DROP TABLE "${schema}"."NODB_TAB_SALES"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
50+
);
51+
await conn.execute(
52+
`create table "${schema}"."NODB_TAB_SALES" ("AMOUNT_SOLD" NUMBER(10,2))`
53+
);
54+
55+
} catch(err) {
56+
should.not.exist(err);
57+
}
5858

59-
conn = await oracledb.getConnection(connectionDetails);
59+
await sodaUtil.assertThrowsAsync(
60+
async () => {
61+
await conn.executeMany(
62+
`insert into "${schema}"."NODB_TAB_SALES" ("AMOUNT_SOLD") values (:1)`,
63+
[ 48, 33, 3, 999, 1, 13.13 ]
64+
);
65+
},
66+
/NJS-005:/
67+
);
68+
// NJS-005: invalid value for parameter %d
6069

70+
try {
6171
await conn.execute(
62-
`DROP USER ${schema} CASCADE`
72+
`BEGIN EXECUTE IMMEDIATE 'DROP TABLE "${schema}"."NODB_TAB_SALES"'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
6373
);
74+
await conn.close();
75+
} catch(err) {
76+
should.not.exist(err);
77+
}
78+
}); // 172.1
79+
80+
it('172.2 binding by position and by name cannot be mixed', async () => {
81+
let conn;
82+
try {
83+
conn = await oracledb.getConnection(dbconfig);
84+
6485
await conn.execute(
65-
`GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE TO ${schema} identified by ${password}`
86+
`BEGIN EXECUTE IMMEDIATE 'DROP TABLE nodb_tab_emp'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
6687
);
6788
await conn.execute(
68-
`create table "${schema}"."SALES" ("AMOUNT_SOLD" NUMBER(10,2))`
89+
`create table nodb_tab_emp (id NUMBER, name VARCHAR2(100))`
6990
);
70-
71-
await conn.executeMany(
72-
`insert into "${schema}"."SALES" ("AMOUNT_SOLD") values (:1)`,
73-
[ 48, 33, 3, 999, 1, 13.13 ]
91+
92+
} catch(err) {
93+
should.not.exist(err);
94+
}
95+
96+
try {
97+
const bindVars = [
98+
[1, "John Smith"],
99+
{ a: 2, b: "Changjie" },
100+
];
101+
await sodaUtil.assertThrowsAsync(
102+
async () => {
103+
await conn.executeMany(
104+
`insert into nodb_tab_emp values (:a, :b)`,
105+
bindVars
106+
);
107+
},
108+
/NJS-055:/
74109
);
110+
// NJS-055: binding by position and name cannot be mixed
111+
} catch(err) {
112+
should.not.exist(err);
113+
}
75114

115+
try {
116+
await conn.execute(
117+
`BEGIN EXECUTE IMMEDIATE 'DROP TABLE nodb_tab_emp'; EXCEPTION WHEN OTHERS THEN IF SQLCODE <> -942 THEN RAISE; END IF; END; `
118+
);
119+
await conn.commit();
120+
await conn.close();
76121
} catch(err) {
77122
should.not.exist(err);
78-
} finally {
79-
if (conn) {
80-
try {
81-
await conn.close();
82-
} catch(err) {
83-
should.not.exist(err);
84-
}
85-
}
86123
}
87-
}); // 172.1
88-
});
124+
}); // 172.2
125+
});

test/list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,6 +4234,7 @@ Overview of node-oracledb functional tests
42344234

42354235
172. executeMany2.js
42364236
172.1 Negative - incorrect parameters
4237+
172.2 binding by position and by name cannot be mixed
42374238

42384239
173. soda5.js
42394240
173.1 create index, basic case

0 commit comments

Comments
 (0)