node-oracledb/test/fetchArraySize7.js

400 lines
13 KiB
JavaScript
Raw Normal View History

2023-02-21 14:08:24 +08:00
/* 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';
2023-02-21 14:08:24 +08:00
const oracledb = require('oracledb');
2023-03-14 15:07:21 +08:00
const assert = require('assert');
2023-02-21 14:08:24 +08:00
const dbConfig = require('./dbconfig.js');
describe("154. fetchArraySize7.js", function() {
2023-02-21 14:08:24 +08:00
let connection = null;
2023-08-17 16:11:49 +08:00
const default_maxRows = oracledb.maxRows;
2023-03-14 15:07:21 +08:00
const tableName = "nodb_fetchArraySize_154";
const tableSize = 1000;
2023-02-21 14:08:24 +08:00
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" +
2018-02-06 10:22:07 +08:00
" 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; ";
2023-02-21 14:08:24 +08:00
const drop_table = "DROP TABLE " + tableName + " PURGE";
2023-03-14 15:07:21 +08:00
before(async function() {
connection = await oracledb.getConnection(dbConfig);
assert.strictEqual(default_maxRows, 0);
});
2023-03-14 15:07:21 +08:00
after(async function() {
await connection.close();
});
describe("154.1 getRows() of resultSet = true", function() {
2023-03-14 15:07:21 +08:00
before(async function() {
await connection.execute(create_table);
});
2023-03-14 15:07:21 +08:00
after(async function() {
await connection.execute(drop_table);
});
2023-03-14 15:07:21 +08:00
afterEach(function() {
oracledb.maxRows = default_maxRows;
});
2023-03-14 15:07:21 +08:00
const testGetRow = async function(fetchArraySizeVal, numRowsVal) {
2023-03-14 15:07:21 +08:00
const result = await connection.execute(
"select * from " + tableName + " order by id",
[],
{
resultSet: true,
fetchArraySize: fetchArraySizeVal
}
);
2023-08-17 16:11:49 +08:00
const rowCount = 0;
2023-03-14 15:07:21 +08:00
fetchRowsFromRS(result.resultSet, numRowsVal, rowCount);
};
2023-03-14 15:07:21 +08:00
async function fetchRowsFromRS(rs, numRowsVal, rowCount) {
2023-08-17 16:11:49 +08:00
const rows = await rs.getRows(numRowsVal);
2023-03-14 15:07:21 +08:00
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());
}
2023-03-14 15:07:21 +08:00
return await fetchRowsFromRS(rs, numRowsVal, rowCount);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
2023-03-14 15:07:21 +08:00
it("154.1.1 numRows > table size > fetchArraySize", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize - 50;
const numRowsVal = tableSize + 10000;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.2 numRows > fetchArraySize > table size", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize + 1200;
const numRowsVal = tableSize + 10000;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.3 table size > numRows > fetchArraySize", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize - 91;
const numRowsVal = tableSize - 2;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.4 table size > fetchArraySize > maxRow", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize - 90;
const numRowsVal = tableSize - 150;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.5 numRows = fetchArraySize < table size", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize - 110;
const numRowsVal = tableSize - 110;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.6 numRows = fetchArraySize = table size", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize;
const numRowsVal = tableSize;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.7 numRows = fetchArraySize > table size", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize + 9999;
const numRowsVal = tableSize + 9999;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.8 numRows = fetchArraySize/10", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize / 10 + 1;
const numRowsVal = tableSize / 10;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.9 numRows = 10 * fetchArraySize", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = 90;
const numRowsVal = 900;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize / 10;
const numRowsVal = tableSize / 10 + 1;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.11 numRows = (table size - 1), fetchArraySize = table size", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize;
const numRowsVal = tableSize - 1;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
2023-03-14 15:07:21 +08:00
it("154.1.12 fetchArraySize = (table size - 1), numRows = table size", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize - 1;
const numRowsVal = tableSize;
2023-03-14 15:07:21 +08:00
await testGetRow(fetchArraySizeVal, numRowsVal);
});
});
describe("154.2 getRow() of resultSet = true", function() {
2023-03-14 15:07:21 +08:00
before(async function() {
await connection.execute(create_table);
});
2023-03-14 15:07:21 +08:00
after(async function() {
await connection.execute(drop_table);
});
2023-03-14 15:07:21 +08:00
afterEach(function() {
oracledb.maxRows = default_maxRows;
});
2023-03-14 15:07:21 +08:00
const testGetRows = async function(fetchArraySizeVal) {
2023-08-17 16:11:49 +08:00
const result = await connection.execute(
"select * from " + tableName + " order by id",
[],
{
resultSet: true,
fetchArraySize: fetchArraySizeVal
}
);
2023-08-17 16:11:49 +08:00
const rowCount = 0;
2023-03-14 15:07:21 +08:00
// assert.strictEqual(result.rows.length, default_maxRows);
await fetchRowFromRS(result.resultSet, rowCount);
};
2023-03-14 15:07:21 +08:00
async function fetchRowFromRS(rs, rowCount) {
2023-08-17 16:11:49 +08:00
const row = await rs.getRow();
2023-03-14 15:07:21 +08:00
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();
}
}
2023-03-14 15:07:21 +08:00
it("154.2.1 fetchArraySize = 1", async function() {
await testGetRows(1);
});
2023-03-14 15:07:21 +08:00
it("154.2.2 fetchArraySize = tableSize/50", async function() {
await testGetRows(tableSize / 50);
});
2023-03-14 15:07:21 +08:00
it("154.2.3 fetchArraySize = tableSize/20", async function() {
await testGetRows(tableSize / 20);
});
2023-03-14 15:07:21 +08:00
it("154.2.4 fetchArraySize = tableSize/10", async function() {
await testGetRows(tableSize / 10);
});
2023-03-14 15:07:21 +08:00
it("154.2.5 fetchArraySize = tableSize/5", async function() {
await testGetRows(tableSize / 5);
});
2023-03-14 15:07:21 +08:00
it("154.2.6 fetchArraySize = tableSize", async function() {
await testGetRows(tableSize);
});
2023-03-14 15:07:21 +08:00
it("154.2.7 fetchArraySize = (table size - 1)", async function() {
await testGetRows(tableSize - 1);
});
});
describe("154.3 interleaved calls to getRow() and getRows()", function() {
2023-03-14 15:07:21 +08:00
let numRowsVal_1, numRowsVal_2;
before(async function() {
await connection.execute(create_table);
});
2023-03-14 15:07:21 +08:00
after(async function() {
await connection.execute(drop_table);
});
2023-03-14 15:07:21 +08:00
afterEach(function() {
oracledb.maxRows = default_maxRows;
});
2023-03-14 15:07:21 +08:00
const testRS = async function(fetchArraySizeVal) {
2023-08-17 16:11:49 +08:00
const result = await connection.execute(
"select * from " + tableName + " order by id",
[],
{
resultSet: true,
fetchArraySize: fetchArraySizeVal
}
);
2023-08-17 16:11:49 +08:00
const rowCount = 0;
2023-03-14 15:07:21 +08:00
fetchRowFromRS(result.resultSet, rowCount);
};
2023-03-14 15:07:21 +08:00
async function fetchRowFromRS(rs, rowCount) {
2023-08-17 16:11:49 +08:00
const row = await rs.getRow();
2023-03-14 15:07:21 +08:00
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();
}
}
2023-03-14 15:07:21 +08:00
async function fetchRowsFromRS_1(rs, rowCount, cb) {
2023-08-17 16:11:49 +08:00
const rows = await rs.getRows(numRowsVal_1);
2023-03-14 15:07:21 +08:00
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());
}
2023-03-14 15:07:21 +08:00
return await fetchRowsFromRS_2(rs, rowCount, cb);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
2023-03-14 15:07:21 +08:00
async function fetchRowsFromRS_2(rs, rowCount, cb) {
2023-08-17 16:11:49 +08:00
const rows = await rs.getRows(numRowsVal_2);
2023-03-14 15:07:21 +08:00
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());
}
2023-03-14 15:07:21 +08:00
return await fetchRowFromRS(rs, rowCount, cb);
} else {
assert.strictEqual(rowCount, tableSize);
await rs.close();
}
}
2023-03-14 15:07:21 +08:00
it("154.3.1 fetchArraySize = 1", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = 1;
numRowsVal_1 = 2;
numRowsVal_2 = 10;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
2023-03-14 15:07:21 +08:00
it("154.3.2 fetchArraySize = tableSize/50", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize / 50;
numRowsVal_1 = 5;
numRowsVal_2 = 88;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
2023-03-14 15:07:21 +08:00
it("154.3.3 fetchArraySize = tableSize/20", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize / 20;
numRowsVal_1 = 50;
numRowsVal_2 = 100;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
2023-03-14 15:07:21 +08:00
it("154.3.4 fetchArraySize = tableSize/10", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize / 10;
numRowsVal_1 = 30;
numRowsVal_2 = 99;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
2023-03-14 15:07:21 +08:00
it("154.3.5 fetchArraySize = tableSize/5", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize / 5;
numRowsVal_1 = 5;
numRowsVal_2 = 88;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
2023-03-14 15:07:21 +08:00
it("154.3.6 fetchArraySize = tableSize", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize;
numRowsVal_1 = 15;
2018-02-06 10:22:07 +08:00
numRowsVal_2 = tableSize;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
2023-03-14 15:07:21 +08:00
it("154.3.7 fetchArraySize = (tableSize - 1)", async function() {
2023-08-17 16:11:49 +08:00
const fetchArraySizeVal = tableSize - 1;
2018-02-06 10:22:07 +08:00
numRowsVal_1 = tableSize - 1;
numRowsVal_2 = tableSize;
2023-03-14 15:07:21 +08:00
await testRS(fetchArraySizeVal);
});
});
});