-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathbinding_functionBindOut.js
361 lines (295 loc) · 15.5 KB
/
binding_functionBindOut.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* Copyright (c) 2017, 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
* 97. binding_functionBindOut.js
*
* DESCRIPTION
* This suite tests the data binding, including:
* Test cases get oracledb type STRING/BUFFER from all db column types using plsql function
* The cases take small/null bind values.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js');
describe('97.binding_functionBindOut.js', function() {
let connection = null;
const executeSql = async function(sql) {
await connection.execute(sql);
};
before(async function() {
connection = await oracledb.getConnection(dbConfig);
});
after(async function() {
await connection.close();
});
const doTest = async function(table_name, proc_name, bindType, dbColType, content, sequence, nullBind) {
let bindVar = {
i: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { type: bindType, dir: oracledb.BIND_OUT, maxSize: 1000 },
output: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxSize: 1000 }
};
await inBind(table_name, proc_name, sequence, dbColType, bindVar, bindType, nullBind);
bindVar = [ { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxSize: 1000 }, sequence, { type: bindType, dir: oracledb.BIND_OUT, maxSize: 1000 } ];
await inBind(table_name, proc_name, sequence, dbColType, bindVar, bindType, nullBind);
};
const getInsertVal = function(element, nullBind) {
const insertValue = [];
if (element.indexOf("CHAR") > -1 || element === "CLOB") {
insertValue[0] = (nullBind === true) ? null : "abcsca";
insertValue[1] = oracledb.STRING;
}
if (element === "BINARY_DOUBLE" || element.indexOf("FLOAT") > -1 || element === "NUMBER") {
insertValue[0] = (nullBind === true) ? null : 1;
insertValue[1] = oracledb.NUMBER;
}
if (element === "TIMESTAMP" || element === "DATE") {
insertValue[0] = (nullBind === true) ? null : new Date(0);
insertValue[1] = oracledb.DATE;
}
if (element === "BLOB" || element.indexOf("RAW") > -1) {
insertValue[0] = (nullBind === true) ? null : assist.createBuffer(100);
insertValue[1] = oracledb.BUFFER;
}
return insertValue;
};
const inBind = async function(table_name, fun_name, sequence, dbColType, bindVar, bindType, nullBind) {
const createTable = await sql.createTable(table_name, dbColType);
const drop_table = "DROP TABLE " + table_name + " PURGE";
const proc = "CREATE OR REPLACE FUNCTION " + fun_name + " (ID IN NUMBER, inValue OUT " + dbColType + ") RETURN NUMBER\n" +
"IS \n" +
" tmpvar NUMBER; \n" +
"BEGIN \n" +
" select id, content into tmpvar, inValue from " + table_name + " where id = ID; \n" +
" RETURN tmpvar; \n" +
"END ; ";
const sqlRun = "BEGIN :output := " + fun_name + " (:i, :c); END;";
const proc_drop = "DROP FUNCTION " + fun_name;
const inserted = getInsertVal(dbColType, nullBind);
const insertSql = "insert into " + table_name + " (id, content) values (:c1, :c2)";
await executeSql(createTable);
const bind = {
c1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c2: { val: inserted[0], type: inserted[1], dir: oracledb.BIND_IN }
};
await connection.execute(insertSql, bind);
await executeSql(proc);
let err;
try {
await connection.execute(sqlRun, bindVar);
} catch (e) {
err = e;
}
if (bindType === oracledb.STRING) {
compareErrMsgForString(dbColType, err);
} else {
compareErrMsgForRAW(nullBind, dbColType, err);
}
await executeSql(proc_drop);
await executeSql(drop_table);
};
var compareErrMsgForString = function(element, err) {
if (element === "BLOB") {
// ORA-06550: line 1, column 7:
// PLS-00306: wrong number or types of arguments in call to 'NODB_INBIND_12'
// ORA-06550: line 1, column 7:
// PL/SQL: Statement ignored
assert.equal(err.message.substring(0, 10), "ORA-06550:");
}
};
var compareErrMsgForRAW = function(nullBind, element, err) {
if (element === "NUMBER" || element.indexOf("FLOAT") > -1 || element === "BINARY_DOUBLE" || element === "DATE" || element === "TIMESTAMP" || element === "CLOB") {
// ORA-06550: line 1, column 7:
// PLS-00306: wrong number or types of arguments in call to 'NODB_INBIND_XX'
// ORA-06550: line 1, column 7:
// PL/SQL: Statement ignored
assert.equal(err.message.substring(0, 10), "ORA-06550:");
}
if (element.indexOf("RAW") > -1 || element === "BLOB") {
assert.ifError(err);
}
if (element.indexOf("CHAR") > -1) {
if (nullBind === true) {
assert.ifError(err);
} else {
// ORA-06502: PL/SQL: numeric or value error: hex to raw conversion error
assert.equal(err.message.substring(0, 10), "ORA-06502:");
}
}
};
const tableNamePre = "table_97";
const procName = "proc_97";
let index = 1;
describe('97.1 PLSQL function: bind out small value to oracledb.STRING/BUFFER', function() {
it('97.1.1 oracledb.STRING <--> DB: NUMBER', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NUMBER", "small string", index++, false);
});
it('97.1.2 oracledb.STRING <--> DB: CHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CHAR", "small string", index++, false);
});
it('97.1.3 oracledb.STRING <--> DB: NCHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NCHAR", "small string", index++, false);
});
it('97.1.4 oracledb.STRING <--> DB: VARCHAR2', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "VARCHAR2", "small string", index++, false);
});
it('97.1.5 oracledb.STRING <--> DB: FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "FLOAT", "small string", index++, false);
});
it('97.1.6 oracledb.STRING <--> DB: BINARY_FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_FLOAT", "small string", index++, false);
});
it('97.1.7 oracledb.STRING <--> DB: BINARY_DOUBLE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_DOUBLE", "small string", index++, false);
});
it('97.1.8 oracledb.STRING <--> DB: DATE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "DATE", "small string", index++, false);
});
it('97.1.9 oracledb.STRING <--> DB: TIMESTAMP', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "TIMESTAMP", "small string", index++, false);
});
it('97.1.10 oracledb.STRING <--> DB: RAW', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "RAW", "small string", index++, false);
});
it('97.1.11 oracledb.STRING <--> DB: CLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CLOB", "small string", index++, false);
});
it('97.1.12 oracledb.STRING <--> DB: BLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BLOB", "small string", index++, false);
});
it('97.1.13 oracledb.BUFFER <--> DB: NUMBER', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NUMBER", assist.createBuffer(100), index++, false);
});
it('97.1.14 oracledb.BUFFER <--> DB: CHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CHAR", assist.createBuffer(100), index++, false);
});
it('97.1.15 oracledb.BUFFER <--> DB: NCHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NCHAR", assist.createBuffer(100), index++, false);
});
it('97.1.16 oracledb.BUFFER <--> DB: VARCHAR2', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "VARCHAR2", assist.createBuffer(100), index++, false);
});
it('97.1.17 oracledb.BUFFER <--> DB: FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "FLOAT", assist.createBuffer(100), index++, false);
});
it('97.1.18 oracledb.BUFFER <--> DB: BINARY_FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_FLOAT", assist.createBuffer(100), index++, false);
});
it('97.1.19 oracledb.BUFFER <--> DB: BINARY_DOUBLE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_DOUBLE", assist.createBuffer(100), index++, false);
});
it('97.1.20 oracledb.BUFFER <--> DB: DATE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "DATE", assist.createBuffer(100), index++, false);
});
it('97.1.21 oracledb.BUFFER <--> DB: TIMESTAMP', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "TIMESTAMP", assist.createBuffer(100), index++, false);
});
it('97.1.22 oracledb.BUFFER <--> DB: RAW', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "RAW", assist.createBuffer(100), index++, false);
});
it('97.1.23 oracledb.BUFFER <--> DB: CLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CLOB", assist.createBuffer(100), index++, false);
});
it('97.1.24 oracledb.BUFFER <--> DB: BLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BLOB", assist.createBuffer(100), index++, false);
});
});
describe('97.2 PLSQL function: bind out small value to oracledb.STRING/BUFFER', function() {
it('97.2.1 oracledb.STRING <--> DB: NUMBER', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NUMBER", null, index++, true);
});
it('97.2.2 oracledb.STRING <--> DB: CHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CHAR", null, index++, true);
});
it('97.2.3 oracledb.STRING <--> DB: NCHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NCHAR", null, index++, true);
});
it('97.2.4 oracledb.STRING <--> DB: VARCHAR2', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "VARCHAR2", null, index++, true);
});
it('97.2.5 oracledb.STRING <--> DB: FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "FLOAT", null, index++, true);
});
it('97.2.6 oracledb.STRING <--> DB: BINARY_FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_FLOAT", null, index++, true);
});
it('97.2.7 oracledb.STRING <--> DB: BINARY_DOUBLE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_DOUBLE", null, index++, true);
});
it('97.2.8 oracledb.STRING <--> DB: DATE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "DATE", null, index++, true);
});
it('97.2.9 oracledb.STRING <--> DB: TIMESTAMP', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "TIMESTAMP", null, index++, true);
});
it('97.2.10 oracledb.STRING <--> DB: RAW', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "RAW", null, index++, true);
});
it('97.2.11 oracledb.STRING <--> DB: CLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CLOB", null, index++, true);
});
it('97.2.12 oracledb.STRING <--> DB: BLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BLOB", null, index++, true);
});
it('97.2.13 oracledb.BUFFER <--> DB: NUMBER', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NUMBER", null, index++, true);
});
it('97.2.14 oracledb.BUFFER <--> DB: CHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CHAR", null, index++, true);
});
it('97.2.15 oracledb.BUFFER <--> DB: NCHAR', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "NCHAR", null, index++, true);
});
it('97.2.16 oracledb.BUFFER <--> DB: VARCHAR2', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "VARCHAR2", null, index++, true);
});
it('97.2.17 oracledb.BUFFER <--> DB: FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "FLOAT", null, index++, true);
});
it('97.2.18 oracledb.BUFFER <--> DB: BINARY_FLOAT', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_FLOAT", null, index++, true);
});
it('97.2.19 oracledb.BUFFER <--> DB: BINARY_DOUBLE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BINARY_DOUBLE", null, index++, true);
});
it('97.2.20 oracledb.BUFFER <--> DB: DATE', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "DATE", null, index++, true);
});
it('97.2.21 oracledb.BUFFER <--> DB: TIMESTAMP', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "TIMESTAMP", null, index++, true);
});
it('97.2.22 oracledb.BUFFER <--> DB: RAW', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "RAW", null, index++, true);
});
it('97.2.23 oracledb.BUFFER <--> DB: CLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "CLOB", null, index++, true);
});
it('97.2.24 oracledb.BUFFER <--> DB: BLOB', async function() {
await doTest(tableNamePre + index, procName + index, oracledb.BUFFER, "BLOB", null, index++, true);
});
});
});