-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathfetchArraySize7.js
399 lines (339 loc) · 12.6 KB
/
fetchArraySize7.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/* 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
* 154. fetchArraySize7.js
*
* DESCRIPTION
* Fetching data from database with different execute() option fetchArraySize when resultSet=true
* Tests including:
* getRow() tests
* getRows() tests
* interleaved calls to getRow() and getRows() tests
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
describe("154. fetchArraySize7.js", function() {
let connection = null;
const default_maxRows = oracledb.maxRows;
const tableName = "nodb_fetchArraySize_154";
const tableSize = 1000;
const create_table = "BEGIN \n" +
" DECLARE \n" +
" e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
" BEGIN \n" +
" EXECUTE IMMEDIATE('DROP TABLE " + tableName + " PURGE'); \n" +
" EXCEPTION \n" +
" WHEN e_table_missing \n" +
" THEN NULL; \n" +
" END; \n" +
" EXECUTE IMMEDIATE (' \n" +
" CREATE TABLE " + tableName + " ( \n" +
" id NUMBER, \n" +
" content VARCHAR(2000) \n" +
" ) \n" +
" '); \n" +
" FOR i IN 1.." + tableSize + " LOOP \n" +
" EXECUTE IMMEDIATE (' \n" +
" insert into " + tableName + " values (' || i || ',' || to_char(i) ||') \n" +
" '); \n" +
" END LOOP; \n" +
" commit; \n" +
"END; ";
const drop_table = "DROP TABLE " + tableName + " PURGE";
before(async function() {
connection = await oracledb.getConnection(dbConfig);
assert.strictEqual(default_maxRows, 0);
});
after(async function() {
await connection.close();
});
describe("154.1 getRows() of resultSet = true", function() {
before(async function() {
await connection.execute(create_table);
});
after(async function() {
await connection.execute(drop_table);
});
afterEach(function() {
oracledb.maxRows = default_maxRows;
});
const testGetRow = async function(fetchArraySizeVal, numRowsVal) {
const result = await connection.execute(
"select * from " + tableName + " order by id",
[],
{
resultSet: true,
fetchArraySize: fetchArraySizeVal
}
);
const rowCount = 0;
fetchRowsFromRS(result.resultSet, numRowsVal, rowCount);
};
async function fetchRowsFromRS(rs, numRowsVal, rowCount) {
const rows = await rs.getRows(numRowsVal);
assert(rows.length <= numRowsVal);
if (rows.length > 0) {
for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1;
assert.strictEqual(rows[i][0], rowCount);
assert.strictEqual(rows[i][1], rowCount.toString());
}
return await fetchRowsFromRS(rs, numRowsVal, rowCount);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
it("154.1.1 numRows > table size > fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 50;
const numRowsVal = tableSize + 10000;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.2 numRows > fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 1200;
const numRowsVal = tableSize + 10000;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.3 table size > numRows > fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 91;
const numRowsVal = tableSize - 2;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.4 table size > fetchArraySize > maxRow", async function() {
const fetchArraySizeVal = tableSize - 90;
const numRowsVal = tableSize - 150;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.5 numRows = fetchArraySize < table size", async function() {
const fetchArraySizeVal = tableSize - 110;
const numRowsVal = tableSize - 110;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.6 numRows = fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize;
const numRowsVal = tableSize;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.7 numRows = fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 9999;
const numRowsVal = tableSize + 9999;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.8 numRows = fetchArraySize/10", async function() {
const fetchArraySizeVal = tableSize / 10 + 1;
const numRowsVal = tableSize / 10;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.9 numRows = 10 * fetchArraySize", async function() {
const fetchArraySizeVal = 90;
const numRowsVal = 900;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
const fetchArraySizeVal = tableSize / 10;
const numRowsVal = tableSize / 10 + 1;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.11 numRows = (table size - 1), fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize;
const numRowsVal = tableSize - 1;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
it("154.1.12 fetchArraySize = (table size - 1), numRows = table size", async function() {
const fetchArraySizeVal = tableSize - 1;
const numRowsVal = tableSize;
await testGetRow(fetchArraySizeVal, numRowsVal);
});
});
describe("154.2 getRow() of resultSet = true", function() {
before(async function() {
await connection.execute(create_table);
});
after(async function() {
await connection.execute(drop_table);
});
afterEach(function() {
oracledb.maxRows = default_maxRows;
});
const testGetRows = async function(fetchArraySizeVal) {
const result = await connection.execute(
"select * from " + tableName + " order by id",
[],
{
resultSet: true,
fetchArraySize: fetchArraySizeVal
}
);
const rowCount = 0;
// assert.strictEqual(result.rows.length, default_maxRows);
await fetchRowFromRS(result.resultSet, rowCount);
};
async function fetchRowFromRS(rs, rowCount) {
const row = await rs.getRow();
if (row) {
rowCount = rowCount + 1;
// console.log(rows[i][0]);
assert.strictEqual(row[0], rowCount);
assert.strictEqual(row[1], rowCount.toString());
return fetchRowFromRS(rs, rowCount);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
it("154.2.1 fetchArraySize = 1", async function() {
await testGetRows(1);
});
it("154.2.2 fetchArraySize = tableSize/50", async function() {
await testGetRows(tableSize / 50);
});
it("154.2.3 fetchArraySize = tableSize/20", async function() {
await testGetRows(tableSize / 20);
});
it("154.2.4 fetchArraySize = tableSize/10", async function() {
await testGetRows(tableSize / 10);
});
it("154.2.5 fetchArraySize = tableSize/5", async function() {
await testGetRows(tableSize / 5);
});
it("154.2.6 fetchArraySize = tableSize", async function() {
await testGetRows(tableSize);
});
it("154.2.7 fetchArraySize = (table size - 1)", async function() {
await testGetRows(tableSize - 1);
});
});
describe("154.3 interleaved calls to getRow() and getRows()", function() {
let numRowsVal_1, numRowsVal_2;
before(async function() {
await connection.execute(create_table);
});
after(async function() {
await connection.execute(drop_table);
});
afterEach(function() {
oracledb.maxRows = default_maxRows;
});
const testRS = async function(fetchArraySizeVal) {
const result = await connection.execute(
"select * from " + tableName + " order by id",
[],
{
resultSet: true,
fetchArraySize: fetchArraySizeVal
}
);
const rowCount = 0;
fetchRowFromRS(result.resultSet, rowCount);
};
async function fetchRowFromRS(rs, rowCount) {
const row = await rs.getRow();
if (row) {
rowCount = rowCount + 1;
assert.strictEqual(row[0], rowCount);
assert.strictEqual(row[1], rowCount.toString());
return await fetchRowsFromRS_1(rs, rowCount);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
async function fetchRowsFromRS_1(rs, rowCount, cb) {
const rows = await rs.getRows(numRowsVal_1);
assert(rows.length <= numRowsVal_1);
if (rows.length > 0) {
for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1;
assert.strictEqual(rows[i][0], rowCount);
assert.strictEqual(rows[i][1], rowCount.toString());
}
return await fetchRowsFromRS_2(rs, rowCount, cb);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
async function fetchRowsFromRS_2(rs, rowCount, cb) {
const rows = await rs.getRows(numRowsVal_2);
assert(rows.length <= numRowsVal_2);
if (rows.length > 0) {
for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1;
assert.strictEqual(rows[i][0], rowCount);
assert.strictEqual(rows[i][1], rowCount.toString());
}
return await fetchRowFromRS(rs, rowCount, cb);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
it("154.3.1 fetchArraySize = 1", async function() {
const fetchArraySizeVal = 1;
numRowsVal_1 = 2;
numRowsVal_2 = 10;
await testRS(fetchArraySizeVal);
});
it("154.3.2 fetchArraySize = tableSize/50", async function() {
const fetchArraySizeVal = tableSize / 50;
numRowsVal_1 = 5;
numRowsVal_2 = 88;
await testRS(fetchArraySizeVal);
});
it("154.3.3 fetchArraySize = tableSize/20", async function() {
const fetchArraySizeVal = tableSize / 20;
numRowsVal_1 = 50;
numRowsVal_2 = 100;
await testRS(fetchArraySizeVal);
});
it("154.3.4 fetchArraySize = tableSize/10", async function() {
const fetchArraySizeVal = tableSize / 10;
numRowsVal_1 = 30;
numRowsVal_2 = 99;
await testRS(fetchArraySizeVal);
});
it("154.3.5 fetchArraySize = tableSize/5", async function() {
const fetchArraySizeVal = tableSize / 5;
numRowsVal_1 = 5;
numRowsVal_2 = 88;
await testRS(fetchArraySizeVal);
});
it("154.3.6 fetchArraySize = tableSize", async function() {
const fetchArraySizeVal = tableSize;
numRowsVal_1 = 15;
numRowsVal_2 = tableSize;
await testRS(fetchArraySizeVal);
});
it("154.3.7 fetchArraySize = (tableSize - 1)", async function() {
const fetchArraySizeVal = tableSize - 1;
numRowsVal_1 = tableSize - 1;
numRowsVal_2 = tableSize;
await testRS(fetchArraySizeVal);
});
});
});