-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathbooleanBind.js
297 lines (252 loc) · 9.72 KB
/
booleanBind.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* Copyright (c) 2020, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
* This software is dual-licensed to you under the Universal Permissive License
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
* either license.
*
* If you elect to accept the software under the Apache License, Version 2.0,
* the following applies:
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NAME
* 224. booleanBind.js
*
* DESCRIPTION
* Test PL/SQL boolean parameters to be bound and to be included in PL/SQL
* records/collections. Based on
* https://github.com/oracle/node-oracledb/pull/1190
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('224. booleanBind.js', function() {
var conn;
var isRunnable = false;
const pkgName = 'NODB_PKG_TEST_BOOLEANS';
before(async function() {
isRunnable = await testsUtil.checkPrerequisites(1200000000, 1200000000);
if (!isRunnable) {
this.skip();
}
const plsqlPkg = `
create or replace package ${pkgName} as
type udt_BooleanList is table of boolean index by binary_integer;
type udt_DemoRecord is record (
NumberValue number,
StringValue varchar2(30),
DateValue date,
BooleanValue boolean
);
function GetStringRep (
a_Value boolean
) return varchar2;
function IsLessThan10 (
a_Value number
) return boolean;
function TestInArrays (
a_Value udt_BooleanList
) return number;
procedure TestOutArrays (
a_NumElements number,
a_Value out nocopy udt_BooleanList
);
procedure DemoRecordsInOut (
a_Value in out nocopy udt_DemoRecord
);
end;
`;
const plsqlPkgBody = `
create or replace package body ${pkgName} as
function GetStringRep (
a_Value boolean
) return varchar2 is
begin
if a_Value is null then
return 'NULL';
elsif a_Value then
return 'TRUE';
end if;
return 'FALSE';
end;
function IsLessThan10 (
a_Value number
) return boolean is
begin
return a_Value < 10;
end;
function TestInArrays (
a_Value udt_BooleanList
) return number is
t_Result pls_integer;
begin
t_Result := 0;
for i in 0..a_Value.count - 1 loop
if a_Value(i) then
t_Result := t_Result + 1;
end if;
end loop;
return t_Result;
end;
procedure TestOutArrays (
a_NumElements number,
a_Value out nocopy udt_BooleanList
) is
begin
for i in 1..a_NumElements loop
a_Value(i) := (mod(i, 2) = 1);
end loop;
end;
procedure DemoRecordsInOut (
a_Value in out nocopy udt_DemoRecord
) is
begin
a_Value.NumberValue := a_Value.NumberValue * 2;
a_Value.StringValue := a_Value.StringValue || ' (Modified)';
a_Value.DateValue := a_Value.DateValue + 5;
a_Value.BooleanValue := not a_Value.BooleanValue;
end;
end;
`;
conn = await oracledb.getConnection(dbConfig);
await conn.execute(plsqlPkg);
await conn.execute(plsqlPkgBody);
}); // before()
after(async function() {
if (!isRunnable) {
return;
}
const plsql = `drop package ${pkgName}`;
await conn.execute(plsql);
await conn.close();
}); // after()
it('224.1 IN bind boolean value', async function() {
if (conn.oracleServerVersion < 1202000000)
this.skip();
const binds = {
inval: true,
outval: { dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 10 }
};
const sql = `begin :outval := ${pkgName}.GetStringRep(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual('TRUE', result.outBinds.outval);
}); // 224.1
it('224.2 IN bind value "false"', async function() {
if (conn.oracleServerVersion < 1202000000)
this.skip();
const binds = {
inval: false,
outval: { dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 10 }
};
const sql = `begin :outval := ${pkgName}.GetStringRep(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual('FALSE', result.outBinds.outval);
}); // 224.2
it('224.3 IN bind value "null"', async function() {
const binds = {
inval: { type: oracledb.DB_TYPE_BOOLEAN, val: null },
outval: { dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 10 }
};
const sql = `begin :outval := ${pkgName}.GetStringRep(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual('NULL', result.outBinds.outval);
}); // 224.3
it('224.4 Negative - IN bind value type mismatch', async function() {
const binds = {
inval: { type: oracledb.DB_TYPE_BOOLEAN, val: 123 },
outval: { dir: oracledb.BIND_OUT, type: oracledb.STRING, maxSize: 10 }
};
const sql = `begin :outval := ${pkgName}.GetStringRep(:inval); end;`;
await assert.rejects(
async function() {
await conn.execute(sql, binds);
},
/NJS-011/
); // 224.4
});
it('224.5 OUT bind value "false"', async function() {
if (conn.oracleServerVersion < 1202000000)
this.skip();
const binds = {
inval: 12,
outval: { dir: oracledb.BIND_OUT, type: oracledb.DB_TYPE_BOOLEAN }
};
const sql = `begin :outval := ${pkgName}.IsLessThan10(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual(false, result.outBinds.outval);
}); // 224.5
it('224.6 OUT bind value "true"', async function() {
if (conn.oracleServerVersion < 1202000000)
this.skip();
const binds = {
inval: 9,
outval: { dir: oracledb.BIND_OUT, type: oracledb.DB_TYPE_BOOLEAN }
};
const sql = `begin :outval := ${pkgName}.IsLessThan10(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual(true, result.outBinds.outval);
}); // 224.6
it('224.7 IN bind array with boolean data', async function() {
const cls = await conn.getDbObjectClass(`${pkgName}.UDT_BOOLEANLIST`);
const arr = new cls([true, false, true, true, false, true, false, true]);
const binds = {
inval: arr,
outval: { dir: oracledb.BIND_OUT, type: oracledb.NUMBER }
};
const sql = `begin :outval := ${pkgName}.TestInArrays(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual(5, result.outBinds.outval);
}); // 224.7
it('224.8 OUT bind array with boolean data', async function() {
const cls = await conn.getDbObjectClass(`${pkgName}.UDT_BOOLEANLIST`);
const arr = new cls([true, false, true, true, false, true, false, true]);
const binds = {
inval: arr,
outval: { dir: oracledb.BIND_OUT, type: oracledb.NUMBER }
};
const sql = `begin :outval := ${pkgName}.TestInArrays(:inval); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual(5, result.outBinds.outval);
}); // 224.8
it('224.9 INOUT bind record with boolean data', async function() {
const cls = await conn.getDbObjectClass(`${pkgName}.UDT_DEMORECORD`);
const obj = new cls();
obj.NUMBERVALUE = 6;
obj.STRINGVALUE = "A string";
obj.DATEVALUE = new Date();
obj.BOOLEANVALUE = false;
const binds = [
{ val: obj, type: cls, dir: oracledb.BIND_INOUT }
];
const sql = `begin ${pkgName}.DemoRecordsInOut(:1); end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual(12, result.outBinds[0].NUMBERVALUE);
assert.strictEqual('A string (Modified)', result.outBinds[0].STRINGVALUE);
//assert.ok(typeof result.outBinds[0].DATEVALUE === 'object');
//(result.outBinds[0].DATEVALUE).should.be.a.Date();
assert.strictEqual(true, result.outBinds[0].BOOLEANVALUE);
}); // 224.9
it('224.10 OUT bind value "null"', async function() {
const binds = {
outval: { dir: oracledb.BIND_OUT, type: oracledb.DB_TYPE_BOOLEAN }
};
const sql = `begin :outval := null; end;`;
const result = await conn.execute(sql, binds);
assert.strictEqual(null, result.outBinds.outval);
}); // 224.10
});