-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathdbObject3.js
219 lines (181 loc) · 6.62 KB
/
dbObject3.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
/* Copyright (c) 2019, 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
* 202. dbObject3.js
*
* DESCRIPTION
* Test the Oracle data type Object on TIMESTAMP WITH TIME ZONE.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('202. dbObject3.js', () => {
let conn;
const TYPE = 'NODB_TYP_OBJ_3';
const TABLE = 'NODB_TAB_OBJ3';
const proc1 =
`create or replace procedure nodb_getDataCursor1(p_cur out sys_refcursor) is
begin
open p_cur for
SELECT
* FROM
${TABLE}
WHERE num >= 100;
end; `;
const proc2 =
`create or replace procedure nodb_getDataCursor2(p_cur out sys_refcursor) is
begin
open p_cur for
SELECT
* FROM
${TABLE}
WHERE num >= 101;
end; `;
const proc3 =
`create or replace procedure nodb_getDataCursor3(
p_cur1 out sys_refcursor,
p_cur2 out sys_refcursor
) is
begin
nodb_getDataCursor1(p_cur1);
nodb_getDataCursor2(p_cur2);
end;`;
before(async () => {
conn = await oracledb.getConnection(dbConfig);
let sql =
`CREATE OR REPLACE TYPE ${TYPE} AS OBJECT (
entry TIMESTAMP WITH TIME ZONE,
exit TIMESTAMP WITH TIME ZONE
);`;
await conn.execute(sql);
sql =
`CREATE TABLE ${TABLE} (
num NUMBER,
person ${TYPE}
)`;
const plsql = testsUtil.sqlCreateTable(TABLE, sql);
await conn.execute(plsql);
}); // before()
after(async () => {
let sql = `DROP TABLE ${TABLE} PURGE`;
await conn.execute(sql);
sql = `DROP TYPE ${TYPE}`;
await conn.execute(sql);
await conn.execute(`DROP PROCEDURE nodb_getDataCursor3`);
await conn.execute(`DROP PROCEDURE nodb_getDataCursor2`);
await conn.execute(`DROP PROCEDURE nodb_getDataCursor1`);
await conn.close();
}); // after()
it.skip('202.1 insert an object with TSZ type attributes', async () => {
const seq = 101;
let sql = `INSERT INTO ${TABLE} VALUES (:1, :2)`;
const date1 = new Date (1986, 8, 18, 12, 14, 27, 0);
const date2 = new Date (1989, 3, 4, 10, 27, 16, 201);
const objData = {
ENTRY: date1,
EXIT: date2
};
const objClass = await conn.getDbObjectClass(TYPE);
const testObj = new objClass(objData);
let result = await conn.execute(sql, [seq, testObj]);
assert.strictEqual(result.rowsAffected, 1);
await conn.commit();
sql = `SELECT * FROM ${TABLE} WHERE num = ${seq}`;
result = await conn.execute(sql);
assert.strictEqual(result.rows[0][1]['ENTRY'].getTime(), date1.getTime());
assert.strictEqual(result.rows[0][1]['EXIT'].getTime(), date2.getTime());
assert.strictEqual(result.rows[0][0], seq);
}); // 202.1
it('202.2 insert null value for TSZ type attribute', async () => {
const seq = 102;
let sql = `INSERT INTO ${TABLE} VALUES (:1, :2)`;
const objData = {
ENTRY: null,
EXIT: null
};
const objClass = await conn.getDbObjectClass(TYPE);
const testObj = new objClass(objData);
let result = await conn.execute(sql, [seq, testObj]);
assert.strictEqual(result.rowsAffected, 1);
await conn.commit();
sql = `SELECT * FROM ${TABLE} WHERE num = ${seq}`;
result = await conn.execute(sql);
assert.strictEqual(result.rows[0][1]['ENTRY'], null);
assert.strictEqual(result.rows[0][1]['EXIT'], null);
assert.strictEqual(result.rows[0][0], seq);
}); // 202.2
it('202.3 insert undefined value for TSZ type attribute', async () => {
const seq = 103;
let sql = `INSERT INTO ${TABLE} VALUES (:1, :2)`;
const objData = {
ENTRY: undefined,
EXIT: undefined
};
const objClass = await conn.getDbObjectClass(TYPE);
const testObj = new objClass(objData);
let result = await conn.execute(sql, [seq, testObj]);
assert.strictEqual(result.rowsAffected, 1);
await conn.commit();
sql = `SELECT * FROM ${TABLE} WHERE num = ${seq}`;
result = await conn.execute(sql);
assert.strictEqual(result.rows[0][1]['ENTRY'], null);
assert.strictEqual(result.rows[0][1]['EXIT'], null);
assert.strictEqual(result.rows[0][0], seq);
}); // 202.3
it('202.4 insert an empty JSON', async () => {
const seq = 104;
let sql = `INSERT INTO ${TABLE} VALUES (:1, :2)`;
const objClass = await conn.getDbObjectClass(TYPE);
const testObj = new objClass({});
let result = await conn.execute(sql, [seq, testObj]);
assert.strictEqual(result.rowsAffected, 1);
await conn.commit();
sql = `SELECT * FROM ${TABLE} WHERE num = ${seq}`;
result = await conn.execute(sql);
assert.strictEqual(result.rows[0][1]['ENTRY'], null);
assert.strictEqual(result.rows[0][1]['EXIT'], null);
}); // 202.4
it('202.5 call procedure with 2 OUT binds of DbObject', async function() {
await conn.execute(proc1);
await conn.execute(proc2);
await conn.execute(proc3);
const result = await conn.execute(
`BEGIN nodb_getDataCursor3(p_cur1 => :p_cur1,
p_cur2 => :p_cur2); end;`,
{
p_cur1: {type: oracledb.CURSOR, dir: oracledb.BIND_OUT},
p_cur2: {type: oracledb.CURSOR, dir: oracledb.BIND_OUT}
}
);
let resultSet = await result.outBinds.p_cur1.getRows();
assert.equal(resultSet.length, 3);
result.outBinds.p_cur1.close();
resultSet = await result.outBinds.p_cur2.getRows();
assert.equal(resultSet.length, 3);
result.outBinds.p_cur2.close();
}); // 200.5;
});