More refactoring and test file changes

This commit is contained in:
Sharad Chandran R 2023-03-14 12:37:21 +05:30
parent ac5d0d9c6d
commit 231830b1ff
50 changed files with 3873 additions and 6900 deletions

View File

@ -746,10 +746,10 @@ describe('4. binding.js', function() {
nullable: true, nullable: true,
byteSize: 1 byteSize: 1
}; };
assert.deepEqual(cursor.metaData, [expectedBind]); assert.deepStrictEqual(cursor.metaData, [expectedBind]);
const rows = await cursor.getRows(); const rows = await cursor.getRows();
assert.deepEqual(rows, [ [ 'X' ] ]); assert.deepStrictEqual(rows, [ [ 'X' ] ]);
}); });
}); });
}); });

View File

@ -23,7 +23,7 @@
* limitations under the License. * limitations under the License.
* *
* NAME * NAME
* 263.binding_buffer_string.js * 270.binding_buffer_string.js
* *
* DESCRIPTION * DESCRIPTION
* Test case for bug 33943738 * Test case for bug 33943738
@ -34,7 +34,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('263. binding_buffer_string.js', function() { describe('270. binding_buffer_string.js', function() {
let connection = null; let connection = null;
const proc_blob_in_tab = "BEGIN \n" + const proc_blob_in_tab = "BEGIN \n" +
@ -65,9 +65,9 @@ describe('263. binding_buffer_string.js', function() {
await connection.close(); await connection.close();
}); });
describe('263.1 BLOB, PLSQL, BIND_IN', function() { describe('270.1 BLOB, PLSQL, BIND_IN', function() {
it('263.1.1 works with buffer', async function() { it('270.1.1 works with buffer', async function() {
const data = [ const data = [
{a: 1, b: Buffer.from("Dummy data 1".repeat(5000), "utf-8")}, {a: 1, b: Buffer.from("Dummy data 1".repeat(5000), "utf-8")},
{a: 2, b: Buffer.from("Dummy data 2".repeat(7500), "utf-8")} {a: 2, b: Buffer.from("Dummy data 2".repeat(7500), "utf-8")}

View File

@ -36,7 +36,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('100.binding_defaultBindIn.js', function() { describe('100.binding_defaultBindIn.js', function() {

View File

@ -35,7 +35,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');

View File

@ -35,7 +35,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');

View File

@ -35,7 +35,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');

View File

@ -35,7 +35,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');

View File

@ -35,7 +35,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');

View File

@ -35,7 +35,7 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const sql = require('./sqlClone.js'); const sql = require('./sql.js');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');

View File

@ -34,7 +34,6 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const sql = require('./sql.js');
describe('137. blobDMLReturningMultipleRowsAsBuffer.js', function() { describe('137. blobDMLReturningMultipleRowsAsBuffer.js', function() {
@ -73,12 +72,12 @@ describe('137. blobDMLReturningMultipleRowsAsBuffer.js', function() {
let tabsize = 10; let tabsize = 10;
before(async function() { before(async function() {
await sql.executeSql(connection, blob_table_create, {}, {}); await connection.execute(blob_table_create);
await insertData(tabsize); await insertData(tabsize);
}); });
after(async function() { after(async function() {
await sql.executeSql(connection, blob_table_drop, {}, {}); await connection.execute(blob_table_drop);
}); });
it('137.1.1 BLOB DML returning multiple rows as buffer', async function() { it('137.1.1 BLOB DML returning multiple rows as buffer', async function() {

View File

@ -34,8 +34,6 @@
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const sql = require('./sql.js');
const assist = require('./dataTypeAssist.js');
describe('138. blobDMLReturningMultipleRowsAsStream.js', function() { describe('138. blobDMLReturningMultipleRowsAsStream.js', function() {
@ -71,13 +69,12 @@ describe('138. blobDMLReturningMultipleRowsAsStream.js', function() {
describe('138.1 BLOB DML returning multiple rows as stream', function() { describe('138.1 BLOB DML returning multiple rows as stream', function() {
before(async function() { before(async function() {
await connection.execute(blob_table_create);
await sql.executeSql(connection, blob_table_create, {}, {}); await insertData(10);
insertData(10);
}); });
after(async function() { after(async function() {
await sql.executeSql(connection, blob_table_drop, {}, {}); await connection.execute(blob_table_drop);
}); });
it('138.1.1 BLOB DML returning multiple rows as stream', async function() { it('138.1.1 BLOB DML returning multiple rows as stream', async function() {
@ -140,7 +137,7 @@ describe('138. blobDMLReturningMultipleRowsAsStream.js', function() {
lob.on('end', function(err) { lob.on('end', function(err) {
assert(err); assert(err);
let expected = Buffer.from(String(id - 10), "utf-8"); let expected = Buffer.from(String(id - 10), "utf-8");
assert.strictEqual(assist.compare2Buffers(blobData, expected), true); assert.deepStrictEqual(blobData, expected);
}); });
}; };
}); });

View File

@ -36,7 +36,6 @@ const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('77. blobPlsqlBindAsBuffer_bindin.js', function() { describe('77. blobPlsqlBindAsBuffer_bindin.js', function() {
@ -203,7 +202,7 @@ describe('77. blobPlsqlBindAsBuffer_bindin.js', function() {
assert.strictEqual(resultVal.toString('utf8', 0, specStrLength), specialStr); assert.strictEqual(resultVal.toString('utf8', 0, specStrLength), specialStr);
assert.strictEqual(resultVal.toString('utf8', (totalLength - specStrLength), totalLength), specialStr); assert.strictEqual(resultVal.toString('utf8', (totalLength - specStrLength), totalLength), specialStr);
} }
assert.strictEqual(assist.compare2Buffers(resultVal, originalBuffer), true); assert.strictEqual(resultVal, originalBuffer);
}; };
// execute the bind in plsql procedure // execute the bind in plsql procedure

View File

@ -36,7 +36,6 @@ const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('79. blobPlsqlBindAsBuffer_bindinout.js', function() { describe('79. blobPlsqlBindAsBuffer_bindinout.js', function() {
@ -152,7 +151,7 @@ describe('79. blobPlsqlBindAsBuffer_bindinout.js', function() {
assert.strictEqual(resultVal.toString('utf8', 0, specStrLength), specialStr); assert.strictEqual(resultVal.toString('utf8', 0, specStrLength), specialStr);
assert.strictEqual(resultVal.toString('utf8', (resultLength - specStrLength), resultLength), specialStr); assert.strictEqual(resultVal.toString('utf8', (resultLength - specStrLength), resultLength), specialStr);
} }
assert.strictEqual(assist.compare2Buffers(resultVal, originalBuffer), true); assert.deepStrictEqual(resultVal, originalBuffer);
}; };
// execute plsql bind in out procedure, and verify the plsql bind out buffer // execute plsql bind in out procedure, and verify the plsql bind out buffer

View File

@ -36,7 +36,6 @@ const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('78. blobPlsqlBindAsBuffer_bindout.js', function() { describe('78. blobPlsqlBindAsBuffer_bindout.js', function() {
@ -116,7 +115,7 @@ describe('78. blobPlsqlBindAsBuffer_bindout.js', function() {
b: { val: insertBuffer, dir: oracledb.BIND_IN, type: oracledb.BUFFER } b: { val: insertBuffer, dir: oracledb.BIND_IN, type: oracledb.BUFFER }
}; };
if (insertBuffer == 'EMPTY_LOB') { if (insertBuffer === 'EMPTY_LOB') {
sql = "INSERT INTO nodb_tab_blob_in (id, blob_1) VALUES (:i, EMPTY_BLOB())"; sql = "INSERT INTO nodb_tab_blob_in (id, blob_1) VALUES (:i, EMPTY_BLOB())";
bindVar = { bindVar = {
i: { val: id, dir: oracledb.BIND_IN, type: oracledb.NUMBER } i: { val: id, dir: oracledb.BIND_IN, type: oracledb.NUMBER }
@ -160,10 +159,10 @@ describe('78. blobPlsqlBindAsBuffer_bindout.js', function() {
assert.deepEqual(originalData, blobData); assert.deepEqual(originalData, blobData);
}; };
const verifyBlobValueWithBuffer = async function(selectSql, oraginalBuffer, specialStr) { const verifyBlobValueWithBuffer = async function(selectSql, originalBuffer, specialStr) {
const result = await connection.execute(selectSql); const result = await connection.execute(selectSql);
const lob = result.rows[0][0]; const lob = result.rows[0][0];
if (oraginalBuffer == null | oraginalBuffer == '' || oraginalBuffer == undefined) { if (originalBuffer == null | originalBuffer == '' || originalBuffer == undefined) {
assert(lob); assert(lob);
} else { } else {
const blobData = await lob.getData(); const blobData = await lob.getData();
@ -183,12 +182,12 @@ describe('78. blobPlsqlBindAsBuffer_bindout.js', function() {
assert.strictEqual(resultVal.toString('utf8', 0, specStrLength), specialStr); assert.strictEqual(resultVal.toString('utf8', 0, specStrLength), specialStr);
assert.strictEqual(resultVal.toString('utf8', (resultLength - specStrLength), resultLength), specialStr); assert.strictEqual(resultVal.toString('utf8', (resultLength - specStrLength), resultLength), specialStr);
} }
assert.strictEqual(assist.compare2Buffers(resultVal, originalBuffer), true); assert.deepStrictEqual(resultVal, originalBuffer);
}; };
const verifyBindOutResult = async function(sqlRun, bindVar, originalBuf, specialStr) { const verifyBindOutResult = async function(sqlRun, bindVar, originalBuf, specialStr) {
const result = await connection.execute(sqlRun, bindVar); const result = await connection.execute(sqlRun, bindVar);
if (originalBuf == "EMPTY_LOB" || originalBuf == undefined || originalBuf == null || originalBuf == "") { if (originalBuf === "EMPTY_LOB" || originalBuf == undefined || originalBuf == null || originalBuf == "") {
assert.strictEqual(result.outBinds.b, null); assert.strictEqual(result.outBinds.b, null);
} else { } else {
const resultVal = result.outBinds.b; const resultVal = result.outBinds.b;

View File

@ -1,227 +0,0 @@
/* 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
* 224. cqn01.js
*
* DESCRIPTION
* Test CQN client initiated connections.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const events = require('events');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('224. cqn01.js', function() {
let isRunnable = false;
let conn, connAsDBA;
before(async function() {
const prep = await testsUtil.checkPrerequisites(1904000000, 1904000000);
isRunnable = prep && dbConfig.test.DBA_PRIVILEGE;
if (!isRunnable) {
this.skip();
} else {
try {
let credential = {
user: dbConfig.test.DBA_user,
password: dbConfig.test.DBA_password,
connectString: dbConfig.connectString,
privilege: oracledb.SYSDBA
};
connAsDBA = await oracledb.getConnection(credential);
let sql = `GRANT CHANGE NOTIFICATION TO ${dbConfig.user}`;
await connAsDBA.execute(sql);
conn = await oracledb.getConnection({
...dbConfig,
events: true
});
} catch (err) {
should.not.exist(err);
}
}
}); // before()
after(async function() {
if (!isRunnable) {
return;
} else {
try {
let sql = `REVOKE CHANGE NOTIFICATION FROM ${dbConfig.user}`;
await connAsDBA.execute(sql);
await conn.close();
await connAsDBA.close();
} catch (err) {
should.not.exist(err);
}
}
}); // after()
it('224.1 client initiated CQN', async () => {
try {
const TABLE = 'nodb_tab_cqn_001';
let sql =
`CREATE TABLE ${TABLE} (
k NUMBER
)`;
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
await conn.execute(plsql);
const eventEmitter = new events.EventEmitter();
const myCallback = function(message) {
// should.strictEqual(message.type, oracledb.SUBSCR_EVENT_TYPE_QUERY_CHANGE);
// should.strictEqual(message.registered, true);
// const table = message.queries[0].tables[0];
// const tableName = dbConfig.user.toUpperCase() + '.' + TABLE.toUpperCase();
// should.strictEqual(table.name, tableName);
// should.strictEqual(table.operation, oracledb.CQN_OPCODE_INSERT);
console.log(message);
eventEmitter.emit("received");
};
const options = {
callback : myCallback,
sql: `SELECT * FROM ${TABLE} WHERE k > :bv`,
binds: { bv : 100 },
timeout : 20,
qos : oracledb.SUBSCR_QOS_QUERY | oracledb.SUBSCR_QOS_ROWIDS,
clientInitiated: true
};
console.log("Message 1:");
await conn.subscribe('nodb_sub_001', options);
sql = `INSERT INTO ${TABLE} VALUES (101)`;
await conn.execute(sql);
sql = `INSERT INTO ${TABLE} VALUES (99)`;
await conn.execute(sql);
sql = `INSERT INTO ${TABLE} VALUES (102)`;
await conn.execute(sql);
await conn.commit();
await new Promise(function(resolve, reject) {
const timeout = setTimeout(function() {
reject(new Error("Timed out!"));
}, 25000);
eventEmitter.on("received", function() {
console.log("Received message!");
clearTimeout(timeout);
resolve();
});
});
await conn.unsubscribe('nodb_sub_001');
sql = `DROP TABLE ${TABLE} PURGE`;
await conn.execute(sql);
} catch (err) {
should.not.exist(err);
}
}); // 224.1
it('224.2 previous CQN', async () => {
try {
const TABLE = 'nodb_tab_cqn_002';
let sql =
`CREATE TABLE ${TABLE} (
k NUMBER
)`;
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
await conn.execute(plsql);
const eventEmitter = new events.EventEmitter();
const myCallback = function(message) {
// should.strictEqual(message.type, oracledb.SUBSCR_EVENT_TYPE_QUERY_CHANGE);
// should.strictEqual(message.registered, true);
// const table = message.queries[0].tables[0];
// const tableName = dbConfig.user.toUpperCase() + '.' + TABLE.toUpperCase();
// should.strictEqual(table.name, tableName);
// should.strictEqual(table.operation, oracledb.CQN_OPCODE_INSERT);
console.log(message);
eventEmitter.emit("received");
};
const options = {
callback : myCallback,
sql: `SELECT * FROM ${TABLE} WHERE k > :bv`,
binds: { bv : 100 },
timeout : 20,
qos : oracledb.SUBSCR_QOS_QUERY | oracledb.SUBSCR_QOS_ROWIDS
};
console.log("Message 2:");
await conn.subscribe('nodb_sub_002', options);
await testsUtil.sleep();
sql = `INSERT INTO ${TABLE} VALUES (101)`;
await conn.execute(sql);
sql = `INSERT INTO ${TABLE} VALUES (99)`;
await conn.execute(sql);
sql = `INSERT INTO ${TABLE} VALUES (102)`;
await conn.execute(sql);
await conn.commit();
await new Promise(function(resolve, reject) {
const timeout = setTimeout(function() {
reject(new Error("Timed out!"));
}, 25000);
eventEmitter.on("received", function() {
console.log("Received message!");
clearTimeout(timeout);
resolve();
});
});
await conn.unsubscribe('nodb_sub_002');
sql = `DROP TABLE ${TABLE} PURGE`;
await conn.execute(sql);
} catch (err) {
should.not.exist(err);
}
}); // 224.2
});

View File

@ -1,94 +0,0 @@
/* 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
* 225. cqn02.js
*
* DESCRIPTION
* Negative test of CQN client initiated connections.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const testsUtil = require('./testsUtil.js');
describe('225. cqn02.js', function() {
let isRunnable = true;
before(async function() {
const prep = await testsUtil.checkPrerequisites(1904000000, 1904000000);
isRunnable = !prep;
if (!isRunnable) {
this.skip();
}
}); // before()
it('225.1 Negative - DB version or client version is less than 19.4', async () => {
try {
const conn = await oracledb.getConnection({
...dbConfig,
events: true
});
const TABLE = 'nodb_tab_cqn02';
let sql =
`CREATE TABLE ${TABLE} (
k NUMBER
)`;
let plsql = testsUtil.sqlCreateTable(TABLE, sql);
await conn.execute(plsql);
const myCallback = function(message) {
console.log(message);
};
const options = {
callback : myCallback,
sql: `SELECT * FROM ${TABLE} WHERE k > :bv`,
binds: { bv : 100 },
timeout : 20,
qos : oracledb.SUBSCR_QOS_QUERY | oracledb.SUBSCR_QOS_ROWIDS,
clientInitiated: true
};
await assert.rejects(
async () => {
await conn.subscribe('sub1', options);
},
/DPI-1050/
);
// DPI-1050: Oracle Client library is at version 19.3 but version 19.4 or higher is needed
sql = `DROP TABLE ${TABLE} PURGE`;
await conn.execute(sql);
await conn.close();
} catch (err) {
should.not.exist(err);
}
}); // 225.1
});

View File

@ -464,6 +464,6 @@ describe('42. dataTypeRaw.js', function() {
let fetch = async function(expected) { let fetch = async function(expected) {
let sql = "select content from " + tableName + " where num = " + insertID; let sql = "select content from " + tableName + " where num = " + insertID;
let result = await connection.execute(sql); let result = await connection.execute(sql);
assist.compare2Buffers(result.rows[0][0], expected); assert.deepStrictEqual(result.rows[0][0], expected);
}; };
}); });

View File

@ -32,160 +32,138 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("148. fetchArraySize1.js", function() { describe("148. fetchArraySize1.js", function() {
let connection = null; let connection = null;
var defaultVal = oracledb.fetchArraySize; let defaultVal = oracledb.fetchArraySize;
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(defaultVal, 100); assert.strictEqual(defaultVal, 100);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("148.1 oracledb.fetchArraySize", function() { describe("148.1 oracledb.fetchArraySize", function() {
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = defaultVal; oracledb.fetchArraySize = defaultVal;
done();
}); });
it("148.1.1 oracledb.fetchArraySize = 0", function(done) { it("148.1.1 oracledb.fetchArraySize = 0", function() {
checkError(0, done); checkError(0);
}); });
it("148.1.2 oracledb.fetchArraySize = 1", function(done) { it("148.1.2 oracledb.fetchArraySize = 1", async function() {
checkGlobalOptionValue(1, 1, done); await checkGlobalOptionValue(1, 1);
}); });
it("148.1.3 Negative: oracledb.fetchArraySize = undefined", function(done) { it("148.1.3 Negative: oracledb.fetchArraySize = undefined", function() {
checkError(undefined, done); checkError(undefined);
}); });
it("148.1.4 Negative: oracledb.fetchArraySize = null", function(done) { it("148.1.4 Negative: oracledb.fetchArraySize = null", function() {
checkError(null, done); checkError(null);
}); });
it("148.1.5 Negative: oracledb.fetchArraySize = random string", function(done) { it("148.1.5 Negative: oracledb.fetchArraySize = random string", function() {
checkError("random string", done); checkError("random string");
}); });
it("148.1.6 Negative: oracledb.fetchArraySize = Boolean", function(done) { it("148.1.6 Negative: oracledb.fetchArraySize = Boolean", function() {
checkError(true, done); checkError(true);
}); });
it("148.1.7 Negative: oracledb.fetchArraySize = NaN", function(done) { it("148.1.7 Negative: oracledb.fetchArraySize = NaN", function() {
checkError(NaN, done); checkError(NaN);
}); });
it("148.1.8 oracledb.fetchArraySize = big number", function(done) { it("148.1.8 oracledb.fetchArraySize = big number", async function() {
checkGlobalOptionValue(1000000, 1000000, done); await checkGlobalOptionValue(1000000, 1000000);
}); });
}); });
describe("148.2 execute() option fetchArraySize", function() { describe("148.2 execute() option fetchArraySize", function() {
it("148.2.1 fetchArraySize = 0", function(done) { it("148.2.1 fetchArraySize = 0", async function() {
queryExpectsError(0, done); await queryExpectsError(0);
}); });
it("148.2.2 fetchArraySize = 1", function(done) { it("148.2.2 fetchArraySize = 1", async function() {
checkExecOptionValue(1, done); await checkExecOptionValue(1);
}); });
it("148.2.3 fetchArraySize = undefined works as default value 100", function(done) { it("148.2.3 fetchArraySize = undefined works as default value 100", async function() {
checkExecOptionValue(undefined, done); await checkExecOptionValue(undefined);
}); });
it("148.2.4 Negative: fetchArraySize = null", function(done) { it("148.2.4 Negative: fetchArraySize = null", async function() {
queryExpectsError(null, done); await queryExpectsError(null);
}); });
it("148.2.5 Negative: fetchArraySize = random string", function(done) { it("148.2.5 Negative: fetchArraySize = random string", async function() {
queryExpectsError("random string", done); await queryExpectsError("random string");
}); });
it("148.2.6 Negative: fetchArraySize = Boolean", function(done) { it("148.2.6 Negative: fetchArraySize = Boolean", async function() {
queryExpectsError(false, done); await queryExpectsError(false);
}); });
it("148.2.7 Negative: fetchArraySize = NaN", function(done) { it("148.2.7 Negative: fetchArraySize = NaN", async function() {
queryExpectsError(NaN, done); await queryExpectsError(NaN);
}); });
it("148.2.8 fetchArraySize = big number", function(done) { it("148.2.8 fetchArraySize = big number", async function() {
checkExecOptionValue(1000000, done); await checkExecOptionValue(1000000);
}); });
}); });
var checkGlobalOptionValue = function(values, expectedFetchArraySize, cb) { const checkGlobalOptionValue = async function(values, expectedFetchArraySize) {
should.doesNotThrow( assert.doesNotThrow(
function() { function() {
oracledb.fetchArraySize = values; oracledb.fetchArraySize = values;
} }
); );
connection.execute( let result = await connection.execute(
"select 'oracledb.fetchArraySize' from dual", "select 'oracledb.fetchArraySize' from dual"
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rows[0][0], "oracledb.fetchArraySize");
should.strictEqual(oracledb.fetchArraySize, expectedFetchArraySize);
cb();
}
); );
assert.strictEqual(result.rows[0][0], "oracledb.fetchArraySize");
assert.strictEqual(oracledb.fetchArraySize, expectedFetchArraySize);
}; };
var checkError = function(values, cb) { const checkError = function(values) {
should.throws( assert.throws(
function() { function() {
oracledb.fetchArraySize = values; oracledb.fetchArraySize = values;
}, },
/NJS-004:/ /NJS-004:/
); );
cb();
}; };
var checkExecOptionValue = function(values, cb) { const checkExecOptionValue = async function(values) {
connection.execute( let result = await connection.execute(
"select 'fetchArraySize' from dual", "select 'fetchArraySize' from dual",
[], [],
{ fetchArraySize: values }, { fetchArraySize: values }
function(err, result) {
should.not.exist(err);
should.strictEqual(oracledb.fetchArraySize, 100);
should.strictEqual(result.rows[0][0], "fetchArraySize");
cb();
}
); );
assert.strictEqual(oracledb.fetchArraySize, 100);
assert.strictEqual(result.rows[0][0], "fetchArraySize");
}; };
var queryExpectsError = function(values, cb) { const queryExpectsError = async function(values) {
connection.execute( const sql = "select 'fetchArraySize' from dual";
"select 'fetchArraySize' from dual", const options = { fetchArraySize: values };
[], await assert.rejects(
{ fetchArraySize: values }, async () => await connection.execute(sql, [], options),
function(err, result) { /NJS-007:/
should.exist(err);
should.not.exist(result);
should.strictEqual(err.message, "NJS-007: invalid value for \"fetchArraySize\" in parameter 3");
cb();
}
); );
}; };

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. */ /* Copyright (c) 2017, 2023, Oracle and/or its affiliates. */
/****************************************************************************** /******************************************************************************
* *
@ -38,8 +38,7 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("149. fetchArraySize2.js", function() { describe("149. fetchArraySize2.js", function() {
@ -76,210 +75,166 @@ describe("149. fetchArraySize2.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_fetcArraySize, 100); assert.strictEqual(default_fetcArraySize, 100);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("149.1 basic fetch with different maxRows and oracledb.fetchArraySize", function() { describe("149.1 basic fetch with different maxRows and oracledb.fetchArraySize", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
const basicFetch = function(fetchArraySizeVal, maxRowsVal, affectedID, cb) { const basicFetch = async function(fetchArraySizeVal, maxRowsVal, affectedID) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
connection.execute( let result = await connection.execute(
"SELECT * FROM " + tableName + " WHERE id > " + affectedID + " ORDER BY id", "SELECT * FROM " + tableName + " WHERE id > " + affectedID + " ORDER BY id"
function(err, result) { );
should.not.exist(err);
let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal; let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID; if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
should.strictEqual(result.rows.length, resultLenExpected); assert.strictEqual(result.rows.length, resultLenExpected);
verifyResult(result.rows, affectedID, cb); verifyResult(result.rows, affectedID);
};
const verifyResult = function(result, affectedID) {
for (let element of result) {
const index = result.indexOf(element) + 1 + affectedID;
assert.strictEqual(element[1], String(index));
assert.strictEqual(element[0], index);
} }
);
}; };
const verifyResult = function(result, affectedID, callback) { it("149.1.1 maxRows > table size > oracledb.fetchArraySize", async function() {
async.forEach(result, function(element, cb) {
const index = result.indexOf(element);
verifyEachRow(index + 1 + affectedID, element);
cb();
}, function(err) {
should.not.exist(err);
callback();
});
};
const verifyEachRow = function(index, element) {
should.strictEqual(element[1], String(index));
should.strictEqual(element[0], index);
};
it("149.1.1 maxRows > table size > oracledb.fetchArraySize", function(done) {
const fetchArraySizeVal = tableSize - 1; const fetchArraySizeVal = tableSize - 1;
const maxRowsVal = tableSize + 1; const maxRowsVal = tableSize + 1;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.2 maxRows > oracledb.fetchArraySize > table size", function(done) { it("149.1.2 maxRows > oracledb.fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize - 99; const fetchArraySizeVal = tableSize - 99;
const maxRowsVal = tableSize - 7; const maxRowsVal = tableSize - 7;
const affectedID = 20; const affectedID = 20;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.3 table size > maxRows > oracledb.fetchArraySize", function(done) { it("149.1.3 table size > maxRows > oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 100; const fetchArraySizeVal = tableSize - 100;
const maxRowsVal = tableSize - 2; const maxRowsVal = tableSize - 2;
const affectedID = 10; const affectedID = 10;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("149.1.4 table size > oracledb.fetchArraySize > maxRow", async function() {
const fetchArraySizeVal = tableSize - 3; const fetchArraySizeVal = tableSize - 3;
const maxRowsVal = tableSize - 77; const maxRowsVal = tableSize - 77;
const affectedID = 50; const affectedID = 50;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.5 maxRows = oracledb.fetchArraySize < table size", function(done) { it("149.1.5 maxRows = oracledb.fetchArraySize < table size", async function() {
const fetchArraySizeVal = tableSize - 110; const fetchArraySizeVal = tableSize - 110;
const maxRowsVal = tableSize - 110; const maxRowsVal = tableSize - 110;
const affectedID = 20; const affectedID = 20;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.6 maxRows = oracledb.fetchArraySize = table size", function(done) { it("149.1.6 maxRows = oracledb.fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = tableSize; const maxRowsVal = tableSize;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.7 maxRows = oracledb.fetchArraySize > table size", function(done) { it("149.1.7 maxRows = oracledb.fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 9999; const fetchArraySizeVal = tableSize + 9999;
const maxRowsVal = tableSize + 9999; const maxRowsVal = tableSize + 9999;
const affectedID = 10; const affectedID = 10;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.8 maxRows = oracledb.fetchArraySize/10", function(done) { it("149.1.8 maxRows = oracledb.fetchArraySize/10", async function() {
const fetchArraySizeVal = tableSize / 10 - 1; const fetchArraySizeVal = tableSize / 10 - 1;
const maxRowsVal = tableSize / 10; const maxRowsVal = tableSize / 10;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.9 maxRows = 10 * oracledb.fetchArraySize", function(done) { it("149.1.9 maxRows = 10 * oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = 90; const fetchArraySizeVal = 90;
const maxRowsVal = 900; const maxRowsVal = 900;
const affectedID = 50; const affectedID = 50;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("149.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
const fetchArraySizeVal = tableSize / 10; const fetchArraySizeVal = tableSize / 10;
const maxRowsVal = tableSize / 10 + 1; const maxRowsVal = tableSize / 10 + 1;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.11 maxRows = 0, fetchArraySize = table size ", function(done) { it("149.1.11 maxRows = 0, fetchArraySize = table size ", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = 0; const maxRowsVal = 0;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.12 maxRows = 9999999, fetchArraySize = table size ", function(done) { it("149.1.12 maxRows = 9999999, fetchArraySize = table size ", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = 9999999; const maxRowsVal = 9999999;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.13 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("149.1.13 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = tableSize - 1; const maxRowsVal = tableSize - 1;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.1.14 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("149.1.14 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
const fetchArraySizeVal = tableSize - 1; const fetchArraySizeVal = tableSize - 1;
const maxRowsVal = tableSize; const maxRowsVal = tableSize;
const affectedID = 0; const affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });
describe("149.2 REF CURSORS with different numRows and oracledb.fetchArraySize", function() { describe("149.2 REF CURSORS with different numRows and oracledb.fetchArraySize", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
const testRefCursor = function(fetchArraySizeVal, numRowsVal, cb) { const testRefCursor = async function(fetchArraySizeVal, numRowsVal) {
const create_ref = `CREATE OR REPLACE PROCEDURE testrefproc (p_out OUT SYS_REFCURSOR) const create_ref = `CREATE OR REPLACE PROCEDURE testrefproc (p_out OUT SYS_REFCURSOR)
AS AS
BEGIN BEGIN
@ -289,294 +244,249 @@ describe("149. fetchArraySize2.js", function() {
const drop_ref = "DROP PROCEDURE testrefproc"; const drop_ref = "DROP PROCEDURE testrefproc";
const exec_ref = "BEGIN testrefproc(:o); END;"; const exec_ref = "BEGIN testrefproc(:o); END;";
async.series([ await connection.execute(create_ref);
function(callback) {
connection.execute(
create_ref,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( let result = await connection.execute(
exec_ref, exec_ref,
[ [
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT } { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
], ],
{ outFormat: oracledb.OUT_FORMAT_OBJECT }, { outFormat: oracledb.OUT_FORMAT_OBJECT }
function(err, result) { );
should.not.exist(err);
const rowCount = 0; const rowCount = 0;
fetchRowsFromRS(result.outBinds[0], numRowsVal, rowCount, callback); fetchRowsFromRS(result.outBinds[0], numRowsVal, rowCount);
}
); await connection.execute(drop_ref);
},
function(callback) {
connection.execute(
drop_ref,
function(err) {
should.not.exist(err);
callback();
}
);
}
], cb);
}; };
function fetchRowsFromRS(rs, numRowsVal, rowCount, cb) { async function fetchRowsFromRS(rs, numRowsVal, rowCount) {
rs.getRows(numRowsVal, function(err, rows) { let rows = await rs.getRows(numRowsVal);
if (rows.length > 0) { if (rows.length > 0) {
for (let i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
(rows.length).should.be.belowOrEqual(numRowsVal); assert(rows.length <= numRowsVal);
rowCount = rowCount + 1; rowCount++;
// console.log(rows[i][0]); assert.strictEqual(rows[i].ID, rowCount);
should.strictEqual(rows[i].ID, rowCount); assert.strictEqual(rows[i].CONTENT, rowCount.toString());
should.strictEqual(rows[i].CONTENT, rowCount.toString());
} }
return fetchRowsFromRS(rs, numRowsVal, rowCount, cb); return fetchRowsFromRS(rs, numRowsVal, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("149.2.1 numRows > table size > oracledb.fetchArraySize", function(done) { it("149.2.1 numRows > table size > oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 1; const fetchArraySizeVal = tableSize - 1;
const numRowsVal = tableSize + 1; const numRowsVal = tableSize + 1;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.2 numRows > oracledb.fetchArraySize > table size", function(done) { it("149.2.2 numRows > oracledb.fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 7; const fetchArraySizeVal = tableSize + 7;
const numRowsVal = tableSize + 77; const numRowsVal = tableSize + 77;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.3 table size > numRows > oracledb.fetchArraySize", function(done) { it("149.2.3 table size > numRows > oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 11; const fetchArraySizeVal = tableSize - 11;
const numRowsVal = tableSize - 2; const numRowsVal = tableSize - 2;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("149.2.4 table size > oracledb.fetchArraySize > maxRow", async function() {
const fetchArraySizeVal = tableSize - 90; const fetchArraySizeVal = tableSize - 90;
const numRowsVal = tableSize - 150; const numRowsVal = tableSize - 150;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.5 numRows = oracledb.fetchArraySize < table size", function(done) { it("149.2.5 numRows = oracledb.fetchArraySize < table size", async function() {
const fetchArraySizeVal = tableSize - 110; const fetchArraySizeVal = tableSize - 110;
const numRowsVal = tableSize - 110; const numRowsVal = tableSize - 110;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.6 numRows = oracledb.fetchArraySize = table size", function(done) { it("149.2.6 numRows = oracledb.fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const numRowsVal = tableSize; const numRowsVal = tableSize;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.7 numRows = oracledb.fetchArraySize > table size", function(done) { it("149.2.7 numRows = oracledb.fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 9999; const fetchArraySizeVal = tableSize + 9999;
const numRowsVal = tableSize + 9999; const numRowsVal = tableSize + 9999;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.8 numRows = oracledb.fetchArraySize/10", function(done) { it("149.2.8 numRows = oracledb.fetchArraySize/10", async function() {
const fetchArraySizeVal = tableSize / 10 + 1; const fetchArraySizeVal = tableSize / 10 + 1;
const numRowsVal = tableSize / 10; const numRowsVal = tableSize / 10;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.9 numRows = 10 * oracledb.fetchArraySize", function(done) { it("149.2.9 numRows = 10 * oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = 90; const fetchArraySizeVal = 90;
const numRowsVal = 900; const numRowsVal = 900;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("149.2.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
const fetchArraySizeVal = tableSize / 10; const fetchArraySizeVal = tableSize / 10;
const numRowsVal = tableSize / 10 + 1; const numRowsVal = tableSize / 10 + 1;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.11 numRows = (table size - 1), fetchArraySize = table size", function(done) { it("149.2.11 numRows = (table size - 1), fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const numRowsVal = tableSize - 1; const numRowsVal = tableSize - 1;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("149.2.12 fetchArraySize = (table size - 1), numRows = table size", function(done) { it("149.2.12 fetchArraySize = (table size - 1), numRows = table size", async function() {
const fetchArraySizeVal = tableSize - 1; const fetchArraySizeVal = tableSize - 1;
const numRowsVal = tableSize; const numRowsVal = tableSize;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
}); });
describe("149.3 queryStream() with different maxRows and oracledb.fetchArraySize", function() { describe("149.3 queryStream() with different maxRows and oracledb.fetchArraySize", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
const testQueryStream = function(fetchArraySizeVal, maxRowsVal, affectedID, cb) { const testQueryStream = async function(fetchArraySizeVal, maxRowsVal, affectedID) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
const resultLenExpected = tableSize - affectedID; const resultLenExpected = tableSize - affectedID;
const querySql = "select * from " + tableName + " where id > " + affectedID + " order by id"; const querySql = "select * from " + tableName + " where id > " + affectedID + " order by id";
const stream = connection.queryStream(querySql); const stream = await connection.queryStream(querySql);
stream.on('error', function(error) {
should.fail(error, null, 'Error event should not be triggered');
});
let counter = 0; let counter = 0;
stream.on('data', function(data) { await new Promise((resolve, reject) => {
should.exist(data); stream.on('error', reject);
counter = counter + 1;
verifyResult(data, counter, affectedID);
});
stream.on('end', function() { stream.on('end', function() {
should.equal(counter, resultLenExpected); assert.strictEqual(counter, resultLenExpected);
stream.destroy(); stream.destroy();
}); });
stream.on('close', resolve);
stream.on('close', function() { stream.on('data', function(data) {
cb(); assert(data);
counter++;
verifyResult(data, counter, affectedID);
});
}); });
}; };
const verifyResult = function(data, counter, affectedID) { const verifyResult = function(data, counter, affectedID) {
should.strictEqual(data[0], counter + affectedID); assert.strictEqual(data[0], counter + affectedID);
should.strictEqual(data[1], String(counter + affectedID)); assert.strictEqual(data[1], String(counter + affectedID));
}; };
it("149.3.1 maxRows > table size > oracledb.fetchArraySize", function(done) { it("149.3.1 maxRows > table size > oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 1; const fetchArraySizeVal = tableSize - 1;
const maxRowsVal = tableSize + 1; const maxRowsVal = tableSize + 1;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.2 maxRows > oracledb.fetchArraySize > table size", function(done) { it("149.3.2 maxRows > oracledb.fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 101; const fetchArraySizeVal = tableSize + 101;
const maxRowsVal = tableSize + 1000; const maxRowsVal = tableSize + 1000;
const affectedID = 20; const affectedID = 20;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.3 table size > maxRows > oracledb.fetchArraySize", function(done) { it("149.3.3 table size > maxRows > oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = tableSize - 11; const fetchArraySizeVal = tableSize - 11;
const maxRowsVal = tableSize - 2; const maxRowsVal = tableSize - 2;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("149.3.4 table size > oracledb.fetchArraySize > maxRow", async function() {
const fetchArraySizeVal = tableSize - 90; const fetchArraySizeVal = tableSize - 90;
const maxRowsVal = tableSize - 150; const maxRowsVal = tableSize - 150;
const affectedID = 50; const affectedID = 50;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.5 maxRows = oracledb.fetchArraySize < table size", function(done) { it("149.3.5 maxRows = oracledb.fetchArraySize < table size", async function() {
const fetchArraySizeVal = tableSize - 110; const fetchArraySizeVal = tableSize - 110;
const maxRowsVal = tableSize - 110; const maxRowsVal = tableSize - 110;
const affectedID = 20; const affectedID = 20;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.6 maxRows = oracledb.fetchArraySize = table size", function(done) { it("149.3.6 maxRows = oracledb.fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = tableSize; const maxRowsVal = tableSize;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.7 maxRows = oracledb.fetchArraySize > table size", function(done) { it("149.3.7 maxRows = oracledb.fetchArraySize > table size", async function() {
const fetchArraySizeVal = tableSize + 9999; const fetchArraySizeVal = tableSize + 9999;
const maxRowsVal = tableSize + 9999; const maxRowsVal = tableSize + 9999;
const affectedID = 10; const affectedID = 10;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.8 maxRows = oracledb.fetchArraySize/10", function(done) { it("149.3.8 maxRows = oracledb.fetchArraySize/10", async function() {
const fetchArraySizeVal = tableSize / 10 + 1; const fetchArraySizeVal = tableSize / 10 + 1;
const maxRowsVal = tableSize / 10; const maxRowsVal = tableSize / 10;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.9 maxRows = 10 * oracledb.fetchArraySize", function(done) { it("149.3.9 maxRows = 10 * oracledb.fetchArraySize", async function() {
const fetchArraySizeVal = 90; const fetchArraySizeVal = 90;
const maxRowsVal = 900; const maxRowsVal = 900;
const affectedID = 50; const affectedID = 50;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("149.3.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
const fetchArraySizeVal = tableSize / 10; const fetchArraySizeVal = tableSize / 10;
const maxRowsVal = tableSize / 10 + 1; const maxRowsVal = tableSize / 10 + 1;
const affectedID = 50; const affectedID = 50;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.11 maxRows = 0, fetchArraySize = table size", function(done) { it("149.3.11 maxRows = 0, fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = 0; const maxRowsVal = 0;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.12 maxRows = 9999999, fetchArraySize = table size", function(done) { it("149.3.12 maxRows = 9999999, fetchArraySize = table size", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = 9999999; const maxRowsVal = 9999999;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.13 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("149.3.13 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
const fetchArraySizeVal = tableSize; const fetchArraySizeVal = tableSize;
const maxRowsVal = tableSize - 1; const maxRowsVal = tableSize - 1;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("149.3.14 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("149.3.14 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
const fetchArraySizeVal = tableSize - 1; const fetchArraySizeVal = tableSize - 1;
const maxRowsVal = tableSize; const maxRowsVal = tableSize;
const affectedID = 0; const affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });

View File

@ -36,17 +36,16 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("150. fetchArraySize3.js", function() { describe("150. fetchArraySize3.js", function() {
let connection = null; let connection = null;
var default_fetcArraySize = oracledb.fetchArraySize; let default_fetcArraySize = oracledb.fetchArraySize;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_150"; let tableName = "nodb_fetchArraySize_150";
var tableSize = 1000; let tableSize = 1000;
const create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
@ -74,129 +73,94 @@ describe("150. fetchArraySize3.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_fetcArraySize, 100); assert.strictEqual(default_fetcArraySize, 100);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("150.1 DML binding", function() { describe("150.1 DML binding", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var dmlBinding = function(fetchArraySize, affectedRowId, cb) { const dmlBinding = async function(fetchArraySize, affectedRowId) {
oracledb.fetchArraySize = fetchArraySize; oracledb.fetchArraySize = fetchArraySize;
async.series([ let result = await connection.execute(
function(callback) {
connection.execute(
"update " + tableName + " set content = :c where id > :num", "update " + tableName + " set content = :c where id > :num",
{ {
num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER }, num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
c: { val: "something", dir: oracledb.BIND_IN, type: oracledb.STRING } c: { val: "something", dir: oracledb.BIND_IN, type: oracledb.STRING }
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, tableSize - affectedRowId);
callback();
});
},
function(callback) {
connection.execute(
"select * from " + tableName + " where id > :num order by id",
{ num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER } },
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rows.length, tableSize - affectedRowId);
verifyResult(result.rows, affectedRowId);
callback();
} }
); );
} assert.strictEqual(result.rowsAffected, tableSize - affectedRowId);
], cb);
result = await connection.execute(
"select * from " + tableName + " where id > :num order by id",
{ num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER } }
);
assert.strictEqual(result.rows.length, tableSize - affectedRowId);
verifyResult(result.rows, affectedRowId);
}; };
var verifyResult = function(result, affectedRowId) { let verifyResult = function(result, affectedRowId) {
async.forEach(result, function(element, cb) { for (let element of result) {
var index = result.indexOf(element); let index = result.indexOf(element);
verifyEachRow(index + 1 + affectedRowId, element); verifyEachRow(index + 1 + affectedRowId, element);
cb(); }
}, function(err) {
should.not.exist(err);
});
}; };
var verifyEachRow = function(index, element) { let verifyEachRow = function(index, element) {
should.strictEqual(element[0], index); assert.strictEqual(element[0], index);
should.strictEqual(element[1], "something"); assert.strictEqual(element[1], "something");
}; };
it("150.1.1 oracledb.fetchArraySize = 1", function(done) { it("150.1.1 oracledb.fetchArraySize = 1", async function() {
dmlBinding(1, 50, done); await dmlBinding(1, 50);
}); });
it("150.1.2 oracledb.fetchArraySize = tableSize/20", function(done) { it("150.1.2 oracledb.fetchArraySize = tableSize/20", async function() {
dmlBinding(tableSize / 20, 0, done); await dmlBinding(tableSize / 20, 0);
}); });
it("150.1.3 oracledb.fetchArraySize = tableSize/10", function(done) { it("150.1.3 oracledb.fetchArraySize = tableSize/10", async function() {
dmlBinding(tableSize / 10, 2, done); await dmlBinding(tableSize / 10, 2);
}); });
it("150.1.4 oracledb.fetchArraySize = tableSize", function(done) { it("150.1.4 oracledb.fetchArraySize = tableSize", async function() {
dmlBinding(tableSize, 1, done); await dmlBinding(tableSize, 1);
}); });
it("150.1.5 oracledb.fetchArraySize = (table size - 1)", function(done) { it("150.1.5 oracledb.fetchArraySize = (table size - 1)", async function() {
dmlBinding(tableSize - 1, 0, done); await dmlBinding(tableSize - 1, 0);
}); });
}); });
describe("150.2 procedure binding", function() { describe("150.2 procedure binding", function() {
var proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_pkg IS\n" + const proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_pkg IS\n" +
" TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" + " TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" + " TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" +
" PROCEDURE array_out(ids OUT idType);\n" + " PROCEDURE array_out(ids OUT idType);\n" +
" PROCEDURE array_inout(id_in IN NUMBER, contents IN OUT stringType); \n" + " PROCEDURE array_inout(id_in IN NUMBER, contents IN OUT stringType); \n" +
"END;"; "END;";
var proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_pkg IS \n" + const proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_pkg IS \n" +
" PROCEDURE array_out(ids OUT idType) IS \n" + " PROCEDURE array_out(ids OUT idType) IS \n" +
" BEGIN \n" + " BEGIN \n" +
" SELECT id BULK COLLECT INTO ids from " + tableName + " order by 1; \n" + " SELECT id BULK COLLECT INTO ids from " + tableName + " order by 1; \n" +
@ -207,209 +171,135 @@ describe("150. fetchArraySize3.js", function() {
" SELECT content BULK COLLECT INTO contents FROM " + tableName + " where id > id_in ORDER BY id; \n" + " SELECT content BULK COLLECT INTO contents FROM " + tableName + " where id > id_in ORDER BY id; \n" +
" END; \n " + " END; \n " +
"END;"; "END;";
var proc_drop = "DROP PACKAGE nodb_ref_pkg"; const proc_drop = "DROP PACKAGE nodb_ref_pkg";
before(function(done) { before(async function() {
async.series([ await connection.execute(create_table);
function(cb) { await connection.execute(proc_package);
connection.execute( await connection.execute(proc_package_body);
create_table,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package_body,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
after(function(done) { after(async function() {
async.series([ await connection.execute(proc_drop);
function(cb) { await connection.execute(drop_table);
connection.execute(
proc_drop,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var proc_query_inout = function(updateFromId, maxArraySizeVal, fetchArraySizeVal, cb) { const proc_query_inout = async function(updateFromId, maxArraySizeVal, fetchArraySizeVal) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( let result = await connection.execute(
"BEGIN nodb_ref_pkg.array_inout(:id_in, :c); END;", "BEGIN nodb_ref_pkg.array_inout(:id_in, :c); END;",
{ {
id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId }, id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId },
c: { type: oracledb.STRING, dir: oracledb.BIND_INOUT, val: ["something new"], maxArraySize: maxArraySizeVal }, c: { type: oracledb.STRING, dir: oracledb.BIND_INOUT, val: ["something new"], maxArraySize: maxArraySizeVal },
},
function(err, result) {
should.not.exist(err);
var rowsAffected = tableSize - updateFromId;
should.strictEqual(result.outBinds.c.length, rowsAffected);
proc_verifyResult_inout(result.outBinds.c, updateFromId, cb);
} }
); );
const rowsAffected = tableSize - updateFromId;
const outVal = result.outBinds.c;
assert.strictEqual(outVal.length, rowsAffected);
for (let element of outVal) {
const index = outVal.indexOf(element) + updateFromId + 1;
assert.strictEqual(element, "something new " + index);
}
}; };
var proc_verifyResult_inout = function(result, updateFromId, callback) { const proc_query_out = async function(maxArraySizeVal, fetchArraySizeVal) {
async.forEach(result, function(element, cb) {
var index = result.indexOf(element);
proc_verifyEachRows_inout(index, element, updateFromId);
cb();
}, function(err) {
should.not.exist(err);
callback();
});
};
var proc_verifyEachRows_inout = function(index, element, updateFromId) {
var expectedTail = index + updateFromId + 1;
should.strictEqual(element, "something new " + expectedTail);
};
var proc_query_out = function(maxArraySizeVal, fetchArraySizeVal, cb) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( const result = await connection.execute(
"BEGIN nodb_ref_pkg.array_out(:c); END;", "BEGIN nodb_ref_pkg.array_out(:c); END;",
{ {
c: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal }, c: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal },
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.outBinds.c.length, tableSize);
proc_verifyResult_out(result.outBinds.c);
cb();
} }
); );
const outVal = result.outBinds.c;
assert.strictEqual(outVal.length, tableSize);
for (let element of outVal) {
const index = outVal.indexOf(element);
assert.strictEqual(element, index + 1);
}
}; };
var proc_verifyResult_out = function(result) { it("150.2.1 Bind OUT with oracledb.fetchArraySize = 1", async function() {
async.forEach(result, function(element, cb) { let maxArraySizeVal = tableSize;
var index = result.indexOf(element); let fetchArraySizeVal = 1;
proc_verifyEachRow_out(index, element); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
cb();
}, function(err) {
should.not.exist(err);
});
};
var proc_verifyEachRow_out = function(index, element) {
should.strictEqual(element, index + 1);
};
it("150.2.1 Bind OUT with oracledb.fetchArraySize = 1", function(done) {
var maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done);
}); });
it("150.2.2 Bind OUT with oracledb.fetchArraySize = tableSize/20", function(done) { it("150.2.2 Bind OUT with oracledb.fetchArraySize = tableSize/20", async function() {
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.3 Bind OUT with oracledb.fetchArraySize = tableSize/10", function(done) { it("150.2.3 Bind OUT with oracledb.fetchArraySize = tableSize/10", async function() {
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.4 Bind OUT with oracledb.fetchArraySize = tableSize", function(done) { it("150.2.4 Bind OUT with oracledb.fetchArraySize = tableSize", async function() {
var maxArraySizeVal = tableSize + 1; let maxArraySizeVal = tableSize + 1;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.5 Bind OUT with oracledb.fetchArraySize = (table size - 1)", function(done) { it("150.2.5 Bind OUT with oracledb.fetchArraySize = (table size - 1)", async function() {
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.6 Bind IN OUT with oracledb.fetchArraySize = 1", function(done) { it("150.2.6 Bind IN OUT with oracledb.fetchArraySize = 1", async function() {
var updateFromId = 20; let updateFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1; let fetchArraySizeVal = 1;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.7 Bind IN OUT with oracledb.fetchArraySize = tableSize/20", function(done) { it("150.2.7 Bind IN OUT with oracledb.fetchArraySize = tableSize/20", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.8 Bind IN OUT with oracledb.fetchArraySize = tableSize/10", function(done) { it("150.2.8 Bind IN OUT with oracledb.fetchArraySize = tableSize/10", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.9 Bind IN OUT with oracledb.fetchArraySize = tableSize", function(done) { it("150.2.9 Bind IN OUT with oracledb.fetchArraySize = tableSize", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize + 10; let maxArraySizeVal = tableSize + 10;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.2.10 Bind IN OUT with oracledb.fetchArraySize = (table size - 1)", function(done) { it("150.2.10 Bind IN OUT with oracledb.fetchArraySize = (table size - 1)", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
}); });
describe("150.3 function binding", function() { describe("150.3 function binding", function() {
var proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_fun_pkg AS\n" + const proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_fun_pkg AS\n" +
" TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" + " TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" + " TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" +
" FUNCTION array_out(id_in IN NUMBER) RETURN idType;\n" + " FUNCTION array_out(id_in IN NUMBER) RETURN idType;\n" +
" FUNCTION array_inout(id_in IN NUMBER, contents IN OUT stringType) RETURN idType; \n" + " FUNCTION array_inout(id_in IN NUMBER, contents IN OUT stringType) RETURN idType; \n" +
"END;"; "END;";
var proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_fun_pkg AS \n" + let proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_fun_pkg AS \n" +
" FUNCTION array_out(id_in IN NUMBER) RETURN idType AS \n" + " FUNCTION array_out(id_in IN NUMBER) RETURN idType AS \n" +
" tmp_id1 idType; \n" + " tmp_id1 idType; \n" +
" BEGIN \n" + " BEGIN \n" +
@ -425,207 +315,136 @@ describe("150. fetchArraySize3.js", function() {
" RETURN tmp_id2; \n" + " RETURN tmp_id2; \n" +
" END; \n " + " END; \n " +
"END;"; "END;";
var proc_drop = "DROP PACKAGE nodb_ref_fun_pkg"; const proc_drop = "DROP PACKAGE nodb_ref_fun_pkg";
before(function(done) { before(async function() {
async.series([ await connection.execute(create_table);
function(cb) { await connection.execute(proc_package);
connection.execute( await connection.execute(proc_package_body);
create_table,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package_body,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
after(function(done) { after(async function() {
async.series([ await connection.execute(proc_drop);
function(cb) { await connection.execute(drop_table);
connection.execute(
proc_drop,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var fun_query_inout = function(updateFromId, maxArraySizeVal, fetchArraySizeVal, cb) { const fun_query_inout = async function(updateFromId, maxArraySizeVal, fetchArraySizeVal) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( let result = await connection.execute(
"BEGIN :output := nodb_ref_fun_pkg.array_inout(:id_in, :c_inout); END;", "BEGIN :output := nodb_ref_fun_pkg.array_inout(:id_in, :c_inout); END;",
{ {
id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId }, id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId },
c_inout: { type: oracledb.STRING, dir: oracledb.BIND_INOUT, val: ["something new"], maxArraySize: maxArraySizeVal }, c_inout: { type: oracledb.STRING, dir: oracledb.BIND_INOUT, val: ["something new"], maxArraySize: maxArraySizeVal },
output: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal } output: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal }
},
function(err, result) {
should.not.exist(err);
fun_verifyResult_inout(result.outBinds.c_inout, updateFromId);
fun_verifyResult_inout(result.outBinds.output, updateFromId);
cb();
} }
); );
fun_verifyResult_inout(result.outBinds.c_inout, updateFromId);
fun_verifyResult_inout(result.outBinds.output, updateFromId);
}; };
var fun_verifyResult_inout = function(result, updateFromId) { const fun_verifyResult_inout = function(result, updateFromId) {
var rowsAffected = tableSize - updateFromId; let rowsAffected = tableSize - updateFromId;
should.strictEqual(result.length, rowsAffected); assert.strictEqual(result.length, rowsAffected);
async.forEach(result, function(element, cb) { for (let element of result) {
var index = result.indexOf(element); const index = result.indexOf(element) + updateFromId + 1;
fun_verifyEachRow_inout(index, element, updateFromId);
cb();
}, function(err) {
should.not.exist(err);
});
};
var fun_verifyEachRow_inout = function(index, element, updateFromId) {
if (typeof element === "string") { if (typeof element === "string") {
var expectedTail = index + updateFromId + 1; assert.strictEqual(element, "something new " + index);
should.strictEqual(element, "something new " + expectedTail);
} else if (typeof element === "number") { } else if (typeof element === "number") {
should.strictEqual(element, index + 1 + updateFromId); assert.strictEqual(element, index);
}
} }
}; };
var fun_query_out = function(affectFromId, maxArraySizeVal, fetchArraySizeVal, cb) { const fun_query_out = async function(affectFromId, maxArraySizeVal, fetchArraySizeVal) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( const result = await connection.execute(
"BEGIN :output := nodb_ref_fun_pkg.array_out(:c); END;", "BEGIN :output := nodb_ref_fun_pkg.array_out(:c); END;",
{ {
c: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: affectFromId }, c: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: affectFromId },
output: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal } output: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal }
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.outBinds.output.length, tableSize - affectFromId);
fun_verifyResult_out(result.outBinds.output, affectFromId);
cb();
} }
); );
const outVal = result.outBinds.output;
assert.strictEqual(outVal.length, tableSize - affectFromId);
for (let element of outVal) {
const index = outVal.indexOf(element) + affectFromId + 1;
assert.strictEqual(element, index);
}
}; };
var fun_verifyResult_out = function(result, affectFromId) { it("150.3.1 Bind OUT with oracledb.fetchArraySize = 1", async function() {
async.forEach(result, function(element, cb) { let affectFromId = 0;
var index = result.indexOf(element); let maxArraySizeVal = tableSize;
fun_verifyEachRow_out(index, element, affectFromId); let fetchArraySizeVal = 1;
cb(); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}, function(err) {
should.not.exist(err);
});
};
var fun_verifyEachRow_out = function(index, element, affectFromId) {
should.strictEqual(element, index + 1 + affectFromId);
};
it("150.3.1 Bind OUT with oracledb.fetchArraySize = 1", function(done) {
var affectFromId = 0;
var maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done);
}); });
it("150.3.2 Bind OUT with oracledb.fetchArraySize = tableSize/20", function(done) { it("150.3.2 Bind OUT with oracledb.fetchArraySize = tableSize/20", async function() {
var affectFromId = 0; let affectFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.3 Bind OUT with oracledb.fetchArraySize = tableSize/10", function(done) { it("150.3.3 Bind OUT with oracledb.fetchArraySize = tableSize/10", async function() {
var affectFromId = 0; let affectFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.4 Bind OUT with oracledb.fetchArraySize = tableSize", function(done) { it("150.3.4 Bind OUT with oracledb.fetchArraySize = tableSize", async function() {
var affectFromId = 0; let affectFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.5 Bind OUT with oracledb.fetchArraySize = (table size - 1)", function(done) { it("150.3.5 Bind OUT with oracledb.fetchArraySize = (table size - 1)", async function() {
var affectFromId = 0; let affectFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.6 Bind IN OUT with oracledb.fetchArraySize = 1", function(done) { it("150.3.6 Bind IN OUT with oracledb.fetchArraySize = 1", async function() {
var updateFromId = 20; let updateFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1; let fetchArraySizeVal = 1;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.7 Bind IN OUT with oracledb.fetchArraySize = tableSize/20", function(done) { it("150.3.7 Bind IN OUT with oracledb.fetchArraySize = tableSize/20", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.8 Bind IN OUT with oracledb.fetchArraySize = tableSize/10", function(done) { it("150.3.8 Bind IN OUT with oracledb.fetchArraySize = tableSize/10", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.9 Bind IN OUT with oracledb.fetchArraySize = tableSize", function(done) { it("150.3.9 Bind IN OUT with oracledb.fetchArraySize = tableSize", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("150.3.10 Bind IN OUT with oracledb.fetchArraySize = (table size - 1)", function(done) { it("150.3.10 Bind IN OUT with oracledb.fetchArraySize = (table size - 1)", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
}); });

View File

@ -36,18 +36,18 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("151. fetchArraySize4.js", function() { describe("151. fetchArraySize4.js", function() {
let connection = null; let connection = null;
var default_fetcArraySize = oracledb.fetchArraySize; let default_fetcArraySize = oracledb.fetchArraySize;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_151"; const tableName = "nodb_fetchArraySize_151";
var tableSize = 1000; let tableSize = 1000;
let create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -73,398 +73,321 @@ describe("151. fetchArraySize4.js", function() {
let drop_table = "DROP TABLE " + tableName + " PURGE"; let drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_fetcArraySize, 100); assert.strictEqual(default_fetcArraySize, 100);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("151.1 getRows() of resultSet = true", function() { describe("151.1 getRows() of resultSet = true", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testGetRow = function(fetchArraySizeVal, numRowsVal, cb) { const testGetRow = async function(fetchArraySizeVal, numRowsVal) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " order by id", "select * from " + tableName + " order by id",
[], [],
{ resultSet: true }, { resultSet: true }
function(err, result) {
should.not.exist(err);
var rowCount = 0;
fetchRowsFromRS(result.resultSet, numRowsVal, rowCount, cb);
}
); );
let rowCount = 0;
fetchRowsFromRS(result.resultSet, numRowsVal, rowCount);
}; };
function fetchRowsFromRS(rs, numRowsVal, rowCount, cb) { async function fetchRowsFromRS(rs, numRowsVal, rowCount) {
rs.getRows(numRowsVal, function(err, rows) { let rows = await rs.getRows(numRowsVal);
(rows.length).should.be.belowOrEqual(numRowsVal); assert(rows.length <= numRowsVal);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1; rowCount++;
should.strictEqual(rows[i][0], rowCount); assert.strictEqual(rows[i][0], rowCount);
should.strictEqual(rows[i][1], rowCount.toString()); assert.strictEqual(rows[i][1], rowCount.toString());
} }
return fetchRowsFromRS(rs, numRowsVal, rowCount, cb); return fetchRowsFromRS(rs, numRowsVal, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("151.1.1 numRows > table size > oracledb.fetchArraySize", function(done) { it("151.1.1 numRows > table size > oracledb.fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var numRowsVal = tableSize + 1; let numRowsVal = tableSize + 1;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.2 numRows > oracledb.fetchArraySize > table size", function(done) { it("151.1.2 numRows > oracledb.fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 1200; let fetchArraySizeVal = tableSize + 1200;
var numRowsVal = tableSize + 10000; let numRowsVal = tableSize + 10000;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.3 table size > numRows > oracledb.fetchArraySize", function(done) { it("151.1.3 table size > numRows > oracledb.fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 11; let fetchArraySizeVal = tableSize - 11;
var numRowsVal = tableSize - 2; let numRowsVal = tableSize - 2;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("151.1.4 table size > oracledb.fetchArraySize > maxRow", async function() {
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var numRowsVal = tableSize - 150; let numRowsVal = tableSize - 150;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.5 numRows = oracledb.fetchArraySize < table size", function(done) { it("151.1.5 numRows = oracledb.fetchArraySize < table size", async function() {
var fetchArraySizeVal = tableSize - 110; let fetchArraySizeVal = tableSize - 110;
var numRowsVal = tableSize - 110; let numRowsVal = tableSize - 110;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.6 numRows = oracledb.fetchArraySize = table size", function(done) { it("151.1.6 numRows = oracledb.fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var numRowsVal = tableSize; let numRowsVal = tableSize;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.7 numRows = oracledb.fetchArraySize > table size", function(done) { it("151.1.7 numRows = oracledb.fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 9999; let fetchArraySizeVal = tableSize + 9999;
var numRowsVal = tableSize + 9999; let numRowsVal = tableSize + 9999;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.8 numRows = oracledb.fetchArraySize/10", function(done) { it("151.1.8 numRows = oracledb.fetchArraySize/10", async function() {
var fetchArraySizeVal = tableSize / 10 + 1; let fetchArraySizeVal = tableSize / 10 + 1;
var numRowsVal = tableSize / 10; let numRowsVal = tableSize / 10;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.9 numRows = 10 * oracledb.fetchArraySize", function(done) { it("151.1.9 numRows = 10 * oracledb.fetchArraySize", async function() {
var fetchArraySizeVal = 90; let fetchArraySizeVal = 90;
var numRowsVal = 900; let numRowsVal = 900;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("151.1.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var numRowsVal = tableSize / 10 + 1; let numRowsVal = tableSize / 10 + 1;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.11 numRows = (table size - 1), fetchArraySize = table size", function(done) { it("151.1.11 numRows = (table size - 1), fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var numRowsVal = tableSize - 1; let numRowsVal = tableSize - 1;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("151.1.12 fetchArraySize = (table size - 1), numRows = table size", function(done) { it("151.1.12 fetchArraySize = (table size - 1), numRows = table size", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var numRowsVal = tableSize; let numRowsVal = tableSize;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
}); });
describe("151.2 getRow() of resultSet = true", function() { describe("151.2 getRow() of resultSet = true", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testGetRows = function(fetchArraySize, cb) { const testGetRows = async function(fetchArraySize) {
oracledb.fetchArraySize = fetchArraySize; oracledb.fetchArraySize = fetchArraySize;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " order by id", "select * from " + tableName + " order by id",
[], [],
{ resultSet: true }, { resultSet: true }
function(err, result) {
should.not.exist(err);
// should.strictEqual(result.rows.length, default_maxRows);
var rowCount = 0;
fetchRowFromRS(result.resultSet, rowCount, cb);
}
); );
let rowCount = 0;
await fetchRowFromRS(result.resultSet, rowCount);
}; };
function fetchRowFromRS(rs, rowCount, cb) { async function fetchRowFromRS(rs, rowCount) {
rs.getRow(function(err, row) { let row = await rs.getRow();
if (row) { if (row) {
rowCount = rowCount + 1; rowCount++;
// console.log(rows[i][0]); assert.strictEqual(row[0], rowCount);
should.strictEqual(row[0], rowCount); assert.strictEqual(row[1], rowCount.toString());
should.strictEqual(row[1], rowCount.toString()); return await fetchRowFromRS(rs, rowCount);
return fetchRowFromRS(rs, rowCount, cb);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("151.2.1 oracledb.fetchArraySize = 1", function(done) { it("151.2.1 oracledb.fetchArraySize = 1", async function() {
testGetRows(1, done); await testGetRows(1);
}); });
it("151.2.2 oracledb.fetchArraySize = tableSize/50", function(done) { it("151.2.2 oracledb.fetchArraySize = tableSize/50", async function() {
testGetRows(tableSize / 50, done); await testGetRows(tableSize / 50);
}); });
it("151.2.3 oracledb.fetchArraySize = tableSize/20", function(done) { it("151.2.3 oracledb.fetchArraySize = tableSize/20", async function() {
testGetRows(tableSize / 20, done); await testGetRows(tableSize / 20);
}); });
it("151.2.4 oracledb.fetchArraySize = tableSize/10", function(done) { it("151.2.4 oracledb.fetchArraySize = tableSize/10", async function() {
testGetRows(tableSize / 10, done); await testGetRows(tableSize / 10);
}); });
it("151.2.5 oracledb.fetchArraySize = tableSize/5", function(done) { it("151.2.5 oracledb.fetchArraySize = tableSize/5", async function() {
testGetRows(tableSize / 5, done); await testGetRows(tableSize / 5);
}); });
it("151.2.6 oracledb.fetchArraySize = tableSize", function(done) { it("151.2.6 oracledb.fetchArraySize = tableSize", async function() {
testGetRows(tableSize, done); await testGetRows(tableSize);
}); });
it("151.2.7 oracledb.fetchArraySize = (tableSize - 1)", function(done) { it("151.2.7 oracledb.fetchArraySize = (tableSize - 1)", async function() {
testGetRows(tableSize - 1, done); await testGetRows(tableSize - 1);
}); });
}); });
describe("151.3 interleaved calls to getRow() and getRows()", function() { describe("151.3 interleaved calls to getRow() and getRows()", function() {
var numRowsVal_1, numRowsVal_2; let numRowsVal_1, numRowsVal_2;
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testRS = function(fetchArraySizeVal, cb) { const testRS = async function(fetchArraySizeVal) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " order by id", "select * from " + tableName + " order by id",
[], [],
{ resultSet: true }, { resultSet: true }
function(err, result) {
should.not.exist(err);
var rowCount = 0;
fetchRowFromRS(result.resultSet, rowCount, cb);
}
); );
let rowCount = 0;
await fetchRowFromRS(result.resultSet, rowCount);
}; };
function fetchRowFromRS(rs, rowCount, cb) { async function fetchRowFromRS(rs, rowCount) {
rs.getRow(function(err, row) { let row = await rs.getRow();
if (row) { if (row) {
rowCount = rowCount + 1; rowCount = rowCount + 1;
should.strictEqual(row[0], rowCount); assert.strictEqual(row[0], rowCount);
should.strictEqual(row[1], rowCount.toString()); assert.strictEqual(row[1], rowCount.toString());
return fetchRowsFromRS_1(rs, rowCount, cb); return await fetchRowsFromRS_1(rs, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
function fetchRowsFromRS_1(rs, rowCount, cb) { async function fetchRowsFromRS_1(rs, rowCount) {
rs.getRows(numRowsVal_1, function(err, rows) { let rows = await rs.getRows(numRowsVal_1);
(rows.length).should.be.belowOrEqual(numRowsVal_1); assert(rows.length <= numRowsVal_1);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1; rowCount++;
should.strictEqual(rows[i][0], rowCount); assert.strictEqual(rows[i][0], rowCount);
should.strictEqual(rows[i][1], rowCount.toString()); assert.strictEqual(rows[i][1], rowCount.toString());
} }
return fetchRowsFromRS_2(rs, rowCount, cb); return await fetchRowsFromRS_2(rs, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
function fetchRowsFromRS_2(rs, rowCount, cb) { async function fetchRowsFromRS_2(rs, rowCount) {
rs.getRows(numRowsVal_2, function(err, rows) { let rows = await rs.getRows(numRowsVal_2);
(rows.length).should.be.belowOrEqual(numRowsVal_2); assert(rows.length <= numRowsVal_2);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1; rowCount++;
should.strictEqual(rows[i][0], rowCount); assert.strictEqual(rows[i][0], rowCount);
should.strictEqual(rows[i][1], rowCount.toString()); assert.strictEqual(rows[i][1], rowCount.toString());
} }
return fetchRowFromRS(rs, rowCount, cb); return await fetchRowFromRS(rs, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("151.3.1 oracledb.fetchArraySize = 1", function(done) { it("151.3.1 oracledb.fetchArraySize = 1", async function() {
var fetchArraySizeVal = 1; let fetchArraySizeVal = 1;
numRowsVal_1 = 2; numRowsVal_1 = 2;
numRowsVal_2 = 10; numRowsVal_2 = 10;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("151.3.2 oracledb.fetchArraySize = tableSize/50", function(done) { it("151.3.2 oracledb.fetchArraySize = tableSize/50", async function() {
var fetchArraySizeVal = tableSize / 50; let fetchArraySizeVal = tableSize / 50;
numRowsVal_1 = 5; numRowsVal_1 = 5;
numRowsVal_2 = 88; numRowsVal_2 = 88;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("151.3.3 oracledb.fetchArraySize = tableSize/20", function(done) { it("151.3.3 oracledb.fetchArraySize = tableSize/20", async function() {
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
numRowsVal_1 = 50; numRowsVal_1 = 50;
numRowsVal_2 = 100; numRowsVal_2 = 100;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("151.3.4 oracledb.fetchArraySize = tableSize/10", function(done) { it("151.3.4 oracledb.fetchArraySize = tableSize/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
numRowsVal_1 = 30; numRowsVal_1 = 30;
numRowsVal_2 = 99; numRowsVal_2 = 99;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("151.3.5 oracledb.fetchArraySize = tableSize/5", function(done) { it("151.3.5 oracledb.fetchArraySize = tableSize/5", async function() {
var fetchArraySizeVal = tableSize / 5; let fetchArraySizeVal = tableSize / 5;
numRowsVal_1 = 5; numRowsVal_1 = 5;
numRowsVal_2 = 88; numRowsVal_2 = 88;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("151.3.6 oracledb.fetchArraySize = tableSize", function(done) { it("151.3.6 oracledb.fetchArraySize = tableSize", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
numRowsVal_1 = 15; numRowsVal_1 = 15;
numRowsVal_2 = tableSize; numRowsVal_2 = tableSize;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("151.3.6 oracledb.fetchArraySize = (tableSize - 1)", function(done) { it("151.3.6 oracledb.fetchArraySize = (tableSize - 1)", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
numRowsVal_1 = tableSize - 1; numRowsVal_1 = tableSize - 1;
numRowsVal_2 = tableSize; numRowsVal_2 = tableSize;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
}); });

View File

@ -39,16 +39,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("152. fetchArraySize5.js", function() { describe("152. fetchArraySize5.js", function() {
let connection = null; let connection = null;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_152"; const tableName = "nodb_fetchArraySize_152";
var tableSize = 1000; let tableSize = 1000;
const create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
@ -76,224 +75,168 @@ describe("152. fetchArraySize5.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("152.1 basic fetch with different maxRows and fetchArraySize", function() { describe("152.1 basic fetch with different maxRows and fetchArraySize", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var basicFetch = function(fetchArraySizeVal, maxRowsVal, affectedID, cb) { const basicFetch = async function(fetchArraySizeVal, maxRowsVal, affectedID) {
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
connection.execute( const result = await connection.execute(
"select * from " + tableName + " where id > " + affectedID + " order by id", "select * from " + tableName + " where id > " + affectedID + " order by id",
[], [],
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
var resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
should.strictEqual(result.rows.length, resultLenExpected);
verifyResult(result.rows, affectedID, cb);
} }
); );
let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
const rows = result.rows;
assert.strictEqual(rows.length, resultLenExpected);
for (let element of rows) {
const index = rows.indexOf(element) + affectedID + 1;
assert.strictEqual(element[1], String(index));
assert.strictEqual(element[0], index);
}
}; };
var verifyResult = function(result, affectedID, callback) { it("152.1.1 maxRows > table size > fetchArraySize", async function() {
async.forEach(result, function(element, cb) { let fetchArraySizeVal = tableSize - 50;
var index = result.indexOf(element); let maxRowsVal = tableSize + 10000;
verifyEachRow(index + 1 + affectedID, element); let affectedID = 20;
cb(); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}, function(err) {
should.not.exist(err);
callback();
});
};
var verifyEachRow = function(index, element) {
should.strictEqual(element[1], String(index));
should.strictEqual(element[0], index);
};
it("152.1.1 maxRows > table size > fetchArraySize", function(done) {
var fetchArraySizeVal = tableSize - 50;
var maxRowsVal = tableSize + 10000;
var affectedID = 20;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done);
}); });
it("152.1.2 maxRows > fetchArraySize > table size", function(done) { it("152.1.2 maxRows > fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 1001; let fetchArraySizeVal = tableSize + 1001;
var maxRowsVal = tableSize + 10000; let maxRowsVal = tableSize + 10000;
var affectedID = 20; let affectedID = 20;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.3 table size > maxRows > fetchArraySize", function(done) { it("152.1.3 table size > maxRows > fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 11; let fetchArraySizeVal = tableSize - 11;
var maxRowsVal = tableSize - 2; let maxRowsVal = tableSize - 2;
var affectedID = 0; let affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.4 table size > fetchArraySize > maxRow", function(done) { it("152.1.4 table size > fetchArraySize > maxRow", async function() {
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var maxRowsVal = tableSize - 150; let maxRowsVal = tableSize - 150;
var affectedID = 50; let affectedID = 50;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.5 maxRows = fetchArraySize < table size", function(done) { it("152.1.5 maxRows = fetchArraySize < table size", async function() {
var fetchArraySizeVal = tableSize - 110; let fetchArraySizeVal = tableSize - 110;
var maxRowsVal = tableSize - 110; let maxRowsVal = tableSize - 110;
var affectedID = 20; let affectedID = 20;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.6 maxRows = fetchArraySize = table size", function(done) { it("152.1.6 maxRows = fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.7 maxRows = fetchArraySize > table size", function(done) { it("152.1.7 maxRows = fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 9999; let fetchArraySizeVal = tableSize + 9999;
var maxRowsVal = tableSize + 9999; let maxRowsVal = tableSize + 9999;
var affectedID = 10; let affectedID = 10;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.8 maxRows = fetchArraySize/10", function(done) { it("152.1.8 maxRows = fetchArraySize/10", async function() {
var fetchArraySizeVal = tableSize / 10 + 1; let fetchArraySizeVal = tableSize / 10 + 1;
var maxRowsVal = tableSize / 10; let maxRowsVal = tableSize / 10;
var affectedID = 7; let affectedID = 7;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.9 maxRows = 10 * fetchArraySize", function(done) { it("152.1.9 maxRows = 10 * fetchArraySize", async function() {
var fetchArraySizeVal = 90; let fetchArraySizeVal = 90;
var maxRowsVal = 900; let maxRowsVal = 900;
var affectedID = 50; let affectedID = 50;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("152.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var maxRowsVal = tableSize / 10 + 1; let maxRowsVal = tableSize / 10 + 1;
var affectedID = 50; let affectedID = 50;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.11 maxRows = 0, fetchArraySize = table size ", function(done) { it("152.1.11 maxRows = 0, fetchArraySize = table size ", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = 0; let maxRowsVal = 0;
var affectedID = 0; let affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.12 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("152.1.12 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize - 1; let maxRowsVal = tableSize - 1;
var affectedID = 0; let affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.1.13 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("152.1.13 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
var fetchArraySizeVal = 999; let fetchArraySizeVal = 999;
var maxRowsVal = 1000; let maxRowsVal = 1000;
var affectedID = 0; let affectedID = 0;
basicFetch(fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetch(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });
describe("152.2 REF CURSORS with different numRows and fetchArraySize", function() { describe("152.2 REF CURSORS with different numRows and fetchArraySize", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testRefCursor = function(fetchArraySizeVal, numRowsVal, cb) { const testRefCursor = async function(fetchArraySizeVal, numRowsVal) {
var create_ref = "CREATE OR REPLACE PROCEDURE testrefproc (p_out OUT SYS_REFCURSOR) " + const create_ref = "CREATE OR REPLACE PROCEDURE testrefproc (p_out OUT SYS_REFCURSOR) " +
"AS " + "AS " +
"BEGIN " + "BEGIN " +
" OPEN p_out FOR " + " OPEN p_out FOR " +
" SELECT * FROM " + tableName + " order by id;" + " SELECT * FROM " + tableName + " order by id;" +
"END; "; "END; ";
var drop_ref = "drop procedure testrefproc"; const drop_ref = "drop procedure testrefproc";
var exec_ref = "BEGIN testrefproc(:o); END;"; const exec_ref = "BEGIN testrefproc(:o); END;";
async.series([ await connection.execute(create_ref);
function(callback) {
connection.execute( let result = await connection.execute(
create_ref,
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.execute(
exec_ref, exec_ref,
[ [
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT } { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
@ -301,268 +244,228 @@ describe("152. fetchArraySize5.js", function() {
{ {
outFormat: oracledb.OUT_FORMAT_OBJECT, outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
var rowCount = 0;
fetchRowsFromRS(result.outBinds[0], numRowsVal, rowCount, callback);
} }
); );
}, let rowCount = 0;
function(callback) { await fetchRowsFromRS(result.outBinds[0], numRowsVal, rowCount);
connection.execute(
drop_ref, await connection.execute(drop_ref);
function(err) {
should.not.exist(err);
callback();
}
);
}
], cb);
}; };
function fetchRowsFromRS(rs, numRowsVal, rowCount, cb) { async function fetchRowsFromRS(rs, numRowsVal, rowCount) {
rs.getRows(numRowsVal, function(err, rows) { let rows = await rs.getRows(numRowsVal);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
(rows.length).should.be.belowOrEqual(numRowsVal); assert(rows.length, numRowsVal);
rowCount = rowCount + 1; rowCount++;
// console.log(rows[i][0]); // console.log(rows[i][0]);
should.strictEqual(rows[i].ID, rowCount); assert.strictEqual(rows[i].ID, rowCount);
should.strictEqual(rows[i].CONTENT, rowCount.toString()); assert.strictEqual(rows[i].CONTENT, rowCount.toString());
} }
return fetchRowsFromRS(rs, numRowsVal, rowCount, cb); return await fetchRowsFromRS(rs, numRowsVal, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("152.2.1 numRows > table size > fetchArraySize", function(done) { it("152.2.1 numRows > table size > fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 50; let fetchArraySizeVal = tableSize - 50;
var numRowsVal = tableSize + 10000; let numRowsVal = tableSize + 10000;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.2 numRows > fetchArraySize > table size", function(done) { it("152.2.2 numRows > fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 1200; let fetchArraySizeVal = tableSize + 1200;
var numRowsVal = tableSize + 10000; let numRowsVal = tableSize + 10000;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.3 table size > numRows > fetchArraySize", function(done) { it("152.2.3 table size > numRows > fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 21; let fetchArraySizeVal = tableSize - 21;
var numRowsVal = tableSize - 2; let numRowsVal = tableSize - 2;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.4 table size > fetchArraySize > maxRow", function(done) { it("152.2.4 table size > fetchArraySize > maxRow", async function() {
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var numRowsVal = tableSize - 150; let numRowsVal = tableSize - 150;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.5 numRows = fetchArraySize < table size", function(done) { it("152.2.5 numRows = fetchArraySize < table size", async function() {
var fetchArraySizeVal = tableSize - 110; let fetchArraySizeVal = tableSize - 110;
var numRowsVal = tableSize - 110; let numRowsVal = tableSize - 110;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.6 numRows = fetchArraySize = table size", function(done) { it("152.2.6 numRows = fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var numRowsVal = tableSize; let numRowsVal = tableSize;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.7 numRows = fetchArraySize > table size", function(done) { it("152.2.7 numRows = fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 9999; let fetchArraySizeVal = tableSize + 9999;
var numRowsVal = tableSize + 9999; let numRowsVal = tableSize + 9999;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.8 numRows = fetchArraySize/10", function(done) { it("152.2.8 numRows = fetchArraySize/10", async function() {
var fetchArraySizeVal = tableSize / 10 + 1; let fetchArraySizeVal = tableSize / 10 + 1;
var numRowsVal = tableSize / 10; let numRowsVal = tableSize / 10;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.9 numRows = 10 * fetchArraySize", function(done) { it("152.2.9 numRows = 10 * fetchArraySize", async function() {
var fetchArraySizeVal = 90; let fetchArraySizeVal = 90;
var numRowsVal = 900; let numRowsVal = 900;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("152.2.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var numRowsVal = tableSize / 10 + 1; let numRowsVal = tableSize / 10 + 1;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.11 numRows = (table size - 1), fetchArraySize = table size", function(done) { it("152.2.11 numRows = (table size - 1), fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var numRowsVal = tableSize - 1; let numRowsVal = tableSize - 1;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
it("152.2.12 fetchArraySize = (table size - 1), numRows = table size", function(done) { it("152.2.12 fetchArraySize = (table size - 1), numRows = table size", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var numRowsVal = tableSize; let numRowsVal = tableSize;
testRefCursor(fetchArraySizeVal, numRowsVal, done); await testRefCursor(fetchArraySizeVal, numRowsVal);
}); });
}); });
describe("152.3 queryStream() with different maxRows and fetchArraySize", function() { describe("152.3 queryStream() with different maxRows and fetchArraySize", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testQueryStream = function(fetchArraySizeVal, maxRowsVal, affectedID, cb) { const testQueryStream = async function(fetchArraySizeVal, maxRowsVal, affectedID) {
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
var resultLenExpected = tableSize - affectedID; let resultLenExpected = tableSize - affectedID;
var querySql = "select * from " + tableName + " where id > " + affectedID + " order by id"; let querySql = "select * from " + tableName + " where id > " + affectedID + " order by id";
var stream = connection.queryStream(querySql, [], {fetchArraySize: fetchArraySizeVal}); let stream = connection.queryStream(querySql, [], {fetchArraySize: fetchArraySizeVal});
let counter = 0;
stream.on('error', function(error) { await new Promise((resolve, reject) => {
should.fail(error, null, 'Error event should not be triggered'); stream.on('error', reject);
});
var counter = 0;
stream.on('data', function(data) { stream.on('data', function(data) {
should.exist(data); counter++;
counter = counter + 1; assert.strictEqual(data[0], counter + affectedID);
verifyResult(data, counter, affectedID); assert.strictEqual(data[1], String(counter + affectedID));
}); });
stream.on('end', function() { stream.on('end', function() {
should.equal(counter, resultLenExpected); assert.strictEqual(counter, resultLenExpected);
stream.destroy(); stream.destroy();
}); });
stream.on('close', resolve);
stream.on('close', function() {
cb();
}); });
}; };
var verifyResult = function(data, counter, affectedID) { it("152.3.1 maxRows > table size > fetchArraySize", async function() {
should.strictEqual(data[0], counter + affectedID); let fetchArraySizeVal = tableSize - 50;
should.strictEqual(data[1], String(counter + affectedID)); let maxRowsVal = tableSize + 10000;
}; let affectedID = 20;
await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
it("152.3.1 maxRows > table size > fetchArraySize", function(done) {
var fetchArraySizeVal = tableSize - 50;
var maxRowsVal = tableSize + 10000;
var affectedID = 20;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done);
}); });
it("152.3.2 maxRows > fetchArraySize > table size", function(done) { it("152.3.2 maxRows > fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 1001; let fetchArraySizeVal = tableSize + 1001;
var maxRowsVal = tableSize + 10000; let maxRowsVal = tableSize + 10000;
var affectedID = 20; let affectedID = 20;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.3 table size > maxRows > fetchArraySize", function(done) { it("152.3.3 table size > maxRows > fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 31; let fetchArraySizeVal = tableSize - 31;
var maxRowsVal = tableSize - 2; let maxRowsVal = tableSize - 2;
var affectedID = 10; let affectedID = 10;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.4 table size > fetchArraySize > maxRow", function(done) { it("152.3.4 table size > fetchArraySize > maxRow", async function() {
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var maxRowsVal = tableSize - 150; let maxRowsVal = tableSize - 150;
var affectedID = 50; let affectedID = 50;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.5 maxRows = fetchArraySize < table size", function(done) { it("152.3.5 maxRows = fetchArraySize < table size", async function() {
var fetchArraySizeVal = tableSize - 110; let fetchArraySizeVal = tableSize - 110;
var maxRowsVal = tableSize - 110; let maxRowsVal = tableSize - 110;
var affectedID = 20; let affectedID = 20;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.6 maxRows = fetchArraySize = table size", function(done) { it("152.3.6 maxRows = fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.7 maxRows = fetchArraySize > table size", function(done) { it("152.3.7 maxRows = fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 9999; let fetchArraySizeVal = tableSize + 9999;
var maxRowsVal = tableSize + 9999; let maxRowsVal = tableSize + 9999;
var affectedID = 10; let affectedID = 10;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.8 maxRows = fetchArraySize/10", function(done) { it("152.3.8 maxRows = fetchArraySize/10", async function() {
var fetchArraySizeVal = tableSize / 10 + 1; let fetchArraySizeVal = tableSize / 10 + 1;
var maxRowsVal = tableSize / 10; let maxRowsVal = tableSize / 10;
var affectedID = 0; let affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.9 maxRows = 10 * fetchArraySize", function(done) { it("152.3.9 maxRows = 10 * fetchArraySize", async function() {
var fetchArraySizeVal = 90; let fetchArraySizeVal = 90;
var maxRowsVal = 900; let maxRowsVal = 900;
var affectedID = 50; let affectedID = 50;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("152.3.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var maxRowsVal = tableSize / 10 + 1; let maxRowsVal = tableSize / 10 + 1;
var affectedID = 0; let affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.11 maxRows = 0, fetchArraySize = table size", function(done) { it("152.3.11 maxRows = 0, fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = 0; let maxRowsVal = 0;
var affectedID = 0; let affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.12 maxRows = (table size - 1), fetchArraySize = table size", function(done) { it("152.3.12 maxRows = (table size - 1), fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize - 1; let maxRowsVal = tableSize - 1;
var affectedID = 0; let affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("152.3.13 fetchArraySize = (table size - 1), maxRows = table size", function(done) { it("152.3.13 fetchArraySize = (table size - 1), maxRows = table size", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID, done); await testQueryStream(fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });

View File

@ -36,16 +36,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("153. fetchArraySize6.js", function() { describe("153. fetchArraySize6.js", function() {
let connection = null; let connection = null;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_153"; const tableName = "nodb_fetchArraySize_153";
var tableSize = 1000; let tableSize = 1000;
const create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
@ -73,53 +72,31 @@ describe("153. fetchArraySize6.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("153.1 DML binding", function() { describe("153.1 DML binding", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var dmlBinding = function(fetchArraySizeVal, affectedRowId, cb) { const dmlBinding = async function(fetchArraySizeVal, affectedRowId) {
async.series([ let result = await connection.execute(
function(callback) {
connection.execute(
"update " + tableName + " set content = :c where id > :num", "update " + tableName + " set content = :c where id > :num",
{ {
num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER }, num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
@ -127,74 +104,58 @@ describe("153. fetchArraySize6.js", function() {
}, },
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
}, }
function(err, result) { );
should.not.exist(err); assert.strictEqual(result.rowsAffected, tableSize - affectedRowId);
should.strictEqual(result.rowsAffected, tableSize - affectedRowId);
callback(); result = await connection.execute(
});
},
function(callback) {
connection.execute(
"select * from " + tableName + " where id > :num order by id", "select * from " + tableName + " where id > :num order by id",
{ num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER } }, { num: { val: affectedRowId, dir: oracledb.BIND_IN, type: oracledb.NUMBER } },
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rows.length, tableSize - affectedRowId);
verifyResult(result.rows, affectedRowId);
callback();
} }
); );
const rows = result.rows;
assert.strictEqual(rows.length, tableSize - affectedRowId);
for (let element of rows) {
const index = rows.indexOf(element);
assert.strictEqual(element[0], index + affectedRowId + 1);
assert.strictEqual(element[1], "something");
} }
], cb);
}; };
var verifyResult = function(result, affectedRowId) { it("153.1.1 fetchArraySize = 1", async function() {
async.forEach(result, function(element, cb) { await dmlBinding(1, 50);
var index = result.indexOf(element);
should.strictEqual(element[0], index + affectedRowId + 1);
should.strictEqual(element[1], "something");
cb();
}, function(err) {
should.not.exist(err);
});
};
it("153.1.1 fetchArraySize = 1", function(done) {
dmlBinding(1, 50, done);
}); });
it("153.1.2 fetchArraySize = tableSize/20", function(done) { it("153.1.2 fetchArraySize = tableSize/20", async function() {
dmlBinding(tableSize / 20, 0, done); await dmlBinding(tableSize / 20, 0);
}); });
it("153.1.3 fetchArraySize = tableSize/10", function(done) { it("153.1.3 fetchArraySize = tableSize/10", async function() {
dmlBinding(tableSize / 10, 2, done); await dmlBinding(tableSize / 10, 2);
}); });
it("153.1.4 fetchArraySize = tableSize", function(done) { it("153.1.4 fetchArraySize = tableSize", async function() {
dmlBinding(tableSize, 0, done); await dmlBinding(tableSize, 0);
}); });
it("153.1.5 fetchArraySize = (table size - 1)", function(done) { it("153.1.5 fetchArraySize = (table size - 1)", async function() {
dmlBinding(tableSize - 1, 0, done); await dmlBinding(tableSize - 1, 0);
}); });
}); });
describe("153.2 procedure binding", function() { describe("153.2 procedure binding", function() {
var proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_pkg IS\n" + const proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_pkg IS\n" +
" TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" + " TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" + " TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" +
" PROCEDURE array_out(ids OUT idType);\n" + " PROCEDURE array_out(ids OUT idType);\n" +
" PROCEDURE array_inout(id_in IN NUMBER, contents IN OUT stringType); \n" + " PROCEDURE array_inout(id_in IN NUMBER, contents IN OUT stringType); \n" +
"END;"; "END;";
var proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_pkg IS \n" + const proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_pkg IS \n" +
" PROCEDURE array_out(ids OUT idType) IS \n" + " PROCEDURE array_out(ids OUT idType) IS \n" +
" BEGIN \n" + " BEGIN \n" +
" SELECT id BULK COLLECT INTO ids from " + tableName + " order by 1; \n" + " SELECT id BULK COLLECT INTO ids from " + tableName + " order by 1; \n" +
@ -205,70 +166,25 @@ describe("153. fetchArraySize6.js", function() {
" SELECT content BULK COLLECT INTO contents FROM " + tableName + " where id > id_in ORDER BY id; \n" + " SELECT content BULK COLLECT INTO contents FROM " + tableName + " where id > id_in ORDER BY id; \n" +
" END; \n " + " END; \n " +
"END;"; "END;";
var proc_drop = "DROP PACKAGE nodb_ref_pkg"; const proc_drop = "DROP PACKAGE nodb_ref_pkg";
before(function(done) { before(async function() {
async.series([ await connection.execute(create_table);
function(cb) { await connection.execute(proc_package);
connection.execute( await connection.execute(proc_package_body);
create_table,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package_body,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
after(function(done) { after(async function() {
async.series([ await connection.execute(proc_drop);
function(cb) { await connection.execute(drop_table);
connection.execute(
proc_drop,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var proc_query_inout = function(updateFromId, maxArraySizeVal, fetchArraySizeVal, cb) { const proc_query_inout = async function(updateFromId, maxArraySizeVal, fetchArraySizeVal) {
connection.execute( let result = await connection.execute(
"BEGIN nodb_ref_pkg.array_inout(:id_in, :c); END;", "BEGIN nodb_ref_pkg.array_inout(:id_in, :c); END;",
{ {
id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId }, id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId },
@ -276,133 +192,112 @@ describe("153. fetchArraySize6.js", function() {
}, },
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
var rowsAffected = tableSize - updateFromId;
should.strictEqual(result.outBinds.c.length, rowsAffected);
proc_verifyResult_inout(result.outBinds.c, updateFromId, cb);
} }
); );
const rowsAffected = tableSize - updateFromId;
const outVal = result.outBinds.c;
assert.strictEqual(outVal.length, rowsAffected);
for (let element of outVal) {
const index = outVal.indexOf(element) + updateFromId + 1;
assert.strictEqual(element, "something new " + index);
}
}; };
var proc_verifyResult_inout = function(result, updateFromId, callback) { let proc_query_out = async function(maxArraySizeVal, fetchArraySizeVal) {
async.forEach(result, function(element, cb) { let result = await connection.execute(
var index = result.indexOf(element);
var expectedTail = index + updateFromId + 1;
should.strictEqual(element, "something new " + expectedTail);
cb();
}, function(err) {
should.not.exist(err);
callback();
});
};
var proc_query_out = function(maxArraySizeVal, fetchArraySizeVal, cb) {
connection.execute(
"BEGIN nodb_ref_pkg.array_out(:c); END;", "BEGIN nodb_ref_pkg.array_out(:c); END;",
{ {
c: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal }, c: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxArraySize: maxArraySizeVal },
}, },
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.outBinds.c.length, tableSize);
proc_verifyResult_out(result.outBinds.c);
cb();
} }
); );
const outVal = result.outBinds.c;
assert.strictEqual(outVal.length, tableSize);
for (let element of outVal) {
const index = outVal.indexOf(element);
assert.strictEqual(element, index + 1);
}
}; };
var proc_verifyResult_out = function(result) { it("153.2.1 Bind OUT with fetchArraySize = 1", async function() {
async.forEach(result, function(element, cb) { let maxArraySizeVal = tableSize;
var index = result.indexOf(element); let fetchArraySizeVal = 1;
should.strictEqual(element, index + 1); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
cb();
}, function(err) {
should.not.exist(err);
});
};
it("153.2.1 Bind OUT with fetchArraySize = 1", function(done) {
var maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done);
}); });
it("153.2.2 Bind OUT with fetchArraySize = tableSize/20", function(done) { it("153.2.2 Bind OUT with fetchArraySize = tableSize/20", async function() {
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.3 Bind OUT with fetchArraySize = tableSize/10", function(done) { it("153.2.3 Bind OUT with fetchArraySize = tableSize/10", async function() {
var maxArraySizeVal = tableSize * 10; let maxArraySizeVal = tableSize * 10;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.4 Bind OUT with fetchArraySize = tableSize", function(done) { it("153.2.4 Bind OUT with fetchArraySize = tableSize", async function() {
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.5 Bind OUT with fetchArraySize = (table size - 1)", function(done) { it("153.2.5 Bind OUT with fetchArraySize = (table size - 1)", async function() {
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
proc_query_out(maxArraySizeVal, fetchArraySizeVal, done); await proc_query_out(maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.6 Bind IN OUT with fetchArraySize = 1", function(done) { it("153.2.6 Bind IN OUT with fetchArraySize = 1", async function() {
var updateFromId = 20; let updateFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1; let fetchArraySizeVal = 1;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.7 Bind IN OUT with fetchArraySize = tableSize/20", function(done) { it("153.2.7 Bind IN OUT with fetchArraySize = tableSize/20", async function() {
var updateFromId = 20; let updateFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.8 Bind IN OUT with fetchArraySize = tableSize/10", function(done) { it("153.2.8 Bind IN OUT with fetchArraySize = tableSize/10", async function() {
var updateFromId = 10; let updateFromId = 10;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.9 Bind IN OUT with fetchArraySize = tableSize", function(done) { it("153.2.9 Bind IN OUT with fetchArraySize = tableSize", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.2.10 Bind IN OUT with fetchArraySize = (table size - 1)", function(done) { it("153.2.10 Bind IN OUT with fetchArraySize = (table size - 1)", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await proc_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
}); });
describe("153.3 function binding", function() { describe("153.3 function binding", function() {
var proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_fun_pkg AS\n" + const proc_package = "CREATE OR REPLACE PACKAGE nodb_ref_fun_pkg AS\n" +
" TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" + " TYPE idType IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;\n" +
" TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" + " TYPE stringType IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;\n" +
" FUNCTION array_out(id_in IN NUMBER) RETURN idType;\n" + " FUNCTION array_out(id_in IN NUMBER) RETURN idType;\n" +
" FUNCTION array_inout(id_in IN NUMBER, contents IN OUT stringType) RETURN idType; \n" + " FUNCTION array_inout(id_in IN NUMBER, contents IN OUT stringType) RETURN idType; \n" +
"END;"; "END;";
var proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_fun_pkg AS \n" + const proc_package_body = "CREATE OR REPLACE PACKAGE BODY nodb_ref_fun_pkg AS \n" +
" FUNCTION array_out(id_in IN NUMBER) RETURN idType AS \n" + " FUNCTION array_out(id_in IN NUMBER) RETURN idType AS \n" +
" tmp_id1 idType; \n" + " tmp_id1 idType; \n" +
" BEGIN \n" + " BEGIN \n" +
@ -418,70 +313,25 @@ describe("153. fetchArraySize6.js", function() {
" RETURN tmp_id2; \n" + " RETURN tmp_id2; \n" +
" END; \n " + " END; \n " +
"END;"; "END;";
var proc_drop = "DROP PACKAGE nodb_ref_fun_pkg"; const proc_drop = "DROP PACKAGE nodb_ref_fun_pkg";
before(function(done) { before(async function() {
async.series([ await connection.execute(create_table);
function(cb) { await connection.execute(proc_package);
connection.execute( await connection.execute(proc_package_body);
create_table,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
proc_package_body,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
after(function(done) { after(async function() {
async.series([ await connection.execute(proc_drop);
function(cb) { await connection.execute(drop_table);
connection.execute(
proc_drop,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var fun_query_inout = function(updateFromId, maxArraySizeVal, fetchArraySizeVal, cb) { const fun_query_inout = async function(updateFromId, maxArraySizeVal, fetchArraySizeVal) {
connection.execute( let result = await connection.execute(
"BEGIN :output := nodb_ref_fun_pkg.array_inout(:id_in, :c_inout); END;", "BEGIN :output := nodb_ref_fun_pkg.array_inout(:id_in, :c_inout); END;",
{ {
id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId }, id_in: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: updateFromId },
@ -490,36 +340,28 @@ describe("153. fetchArraySize6.js", function() {
}, },
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
fun_verifyResult_inout(result.outBinds.c_inout, updateFromId);
fun_verifyResult_inout(result.outBinds.output, updateFromId);
cb();
} }
); );
fun_verifyResult_inout(result.outBinds.c_inout, updateFromId);
fun_verifyResult_inout(result.outBinds.output, updateFromId);
}; };
var fun_verifyResult_inout = function(result, updateFromId) { const fun_verifyResult_inout = function(result, updateFromId) {
var rowsAffected = tableSize - updateFromId; let rowsAffected = tableSize - updateFromId;
should.strictEqual(result.length, rowsAffected); assert.strictEqual(result.length, rowsAffected);
async.forEach(result, function(element, cb) { for (let element of result) {
var index = result.indexOf(element); let index = result.indexOf(element);
if (typeof element === "string") { if (typeof element === "string") {
var expectedTail = index + updateFromId + 1; let expectedTail = index + updateFromId + 1;
should.strictEqual(element, "something new " + expectedTail); assert.strictEqual(element, "something new " + expectedTail);
} else if (typeof element === "number") { } else if (typeof element === "number") {
should.strictEqual(element, index + 1 + updateFromId); assert.strictEqual(element, index + 1 + updateFromId);
}
} }
cb();
}, function(err) {
should.not.exist(err);
});
}; };
var fun_query_out = function(affectFromId, maxArraySizeVal, fetchArraySizeVal, cb) { const fun_query_out = async function(affectFromId, maxArraySizeVal, fetchArraySizeVal) {
connection.execute( let result = await connection.execute(
"BEGIN :output := nodb_ref_fun_pkg.array_out(:c); END;", "BEGIN :output := nodb_ref_fun_pkg.array_out(:c); END;",
{ {
c: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: affectFromId }, c: { type: oracledb.NUMBER, dir: oracledb.BIND_IN, val: affectFromId },
@ -527,94 +369,84 @@ describe("153. fetchArraySize6.js", function() {
}, },
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.outBinds.output.length, tableSize - affectFromId);
fun_verifyResult_out(result.outBinds.output, affectFromId);
cb();
} }
); );
const outVal = result.outBinds.output;
assert.strictEqual(outVal.length, tableSize - affectFromId);
for (let element of outVal) {
const index = outVal.indexOf(element);
assert.strictEqual(element, index + 1 + affectFromId);
}
}; };
var fun_verifyResult_out = function(result, affectFromId) { it("153.3.1 Bind OUT with fetchArraySize = 1", async function() {
async.forEach(result, function(element, cb) { let affectFromId = 10;
var index = result.indexOf(element); let maxArraySizeVal = tableSize;
should.strictEqual(element, index + 1 + affectFromId); let fetchArraySizeVal = 1;
cb(); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}, function(err) {
should.not.exist(err);
});
};
it("153.3.1 Bind OUT with fetchArraySize = 1", function(done) {
var affectFromId = 10;
var maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done);
}); });
it("153.3.2 Bind OUT with fetchArraySize = tableSize/20", function(done) { it("153.3.2 Bind OUT with fetchArraySize = tableSize/20", async function() {
var affectFromId = 20; let affectFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.3 Bind OUT with fetchArraySize = tableSize/10", function(done) { it("153.3.3 Bind OUT with fetchArraySize = tableSize/10", async function() {
var affectFromId = 5; let affectFromId = 5;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.4 Bind OUT with fetchArraySize = tableSize", function(done) { it("153.3.4 Bind OUT with fetchArraySize = tableSize", async function() {
var affectFromId = 29; let affectFromId = 29;
var maxArraySizeVal = tableSize * 10; let maxArraySizeVal = tableSize * 10;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.5 Bind OUT with fetchArraySize = (table size - 1)", function(done) { it("153.3.5 Bind OUT with fetchArraySize = (table size - 1)", async function() {
var affectFromId = 0; let affectFromId = 0;
var maxArraySizeVal = tableSize * 10; let maxArraySizeVal = tableSize * 10;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_out(affectFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.6 Bind IN OUT with fetchArraySize = 1", function(done) { it("153.3.6 Bind IN OUT with fetchArraySize = 1", async function() {
var updateFromId = 20; let updateFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = 1; let fetchArraySizeVal = 1;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.7 Bind IN OUT with fetchArraySize = tableSize/20", function(done) { it("153.3.7 Bind IN OUT with fetchArraySize = tableSize/20", async function() {
var updateFromId = 20; let updateFromId = 20;
var maxArraySizeVal = tableSize; let maxArraySizeVal = tableSize;
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.8 Bind IN OUT with fetchArraySize = tableSize/10", function(done) { it("153.3.8 Bind IN OUT with fetchArraySize = tableSize/10", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.9 Bind IN OUT with fetchArraySize = tableSize", function(done) { it("153.3.9 Bind IN OUT with fetchArraySize = tableSize", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
it("153.3.10 Bind IN OUT with fetchArraySize = (table size - 1)", function(done) { it("153.3.10 Bind IN OUT with fetchArraySize = (table size - 1)", async function() {
var updateFromId = 0; let updateFromId = 0;
var maxArraySizeVal = tableSize * 2; let maxArraySizeVal = tableSize * 2;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal, done); await fun_query_inout(updateFromId, maxArraySizeVal, fetchArraySizeVal);
}); });
}); });

View File

@ -36,15 +36,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("154. fetchArraySize7.js", function() { describe("154. fetchArraySize7.js", function() {
let connection = null; let connection = null;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_154"; const tableName = "nodb_fetchArraySize_154";
var tableSize = 1000; const tableSize = 1000;
const create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
@ -72,401 +72,326 @@ describe("154. fetchArraySize7.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("154.1 getRows() of resultSet = true", function() { describe("154.1 getRows() of resultSet = true", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testGetRow = function(fetchArraySizeVal, numRowsVal, cb) { const testGetRow = async function(fetchArraySizeVal, numRowsVal) {
connection.execute( const result = await connection.execute(
"select * from " + tableName + " order by id", "select * from " + tableName + " order by id",
[], [],
{ {
resultSet: true, resultSet: true,
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
var rowCount = 0;
fetchRowsFromRS(result.resultSet, numRowsVal, rowCount, cb);
} }
); );
let rowCount = 0;
fetchRowsFromRS(result.resultSet, numRowsVal, rowCount);
}; };
function fetchRowsFromRS(rs, numRowsVal, rowCount, cb) { async function fetchRowsFromRS(rs, numRowsVal, rowCount) {
rs.getRows(numRowsVal, function(err, rows) { let rows = await rs.getRows(numRowsVal);
(rows.length).should.be.belowOrEqual(numRowsVal); assert(rows.length <= numRowsVal);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1; rowCount = rowCount + 1;
should.strictEqual(rows[i][0], rowCount); assert.strictEqual(rows[i][0], rowCount);
should.strictEqual(rows[i][1], rowCount.toString()); assert.strictEqual(rows[i][1], rowCount.toString());
} }
return fetchRowsFromRS(rs, numRowsVal, rowCount, cb); return await fetchRowsFromRS(rs, numRowsVal, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("154.1.1 numRows > table size > fetchArraySize", function(done) { it("154.1.1 numRows > table size > fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 50; let fetchArraySizeVal = tableSize - 50;
var numRowsVal = tableSize + 10000; let numRowsVal = tableSize + 10000;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.2 numRows > fetchArraySize > table size", function(done) { it("154.1.2 numRows > fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 1200; let fetchArraySizeVal = tableSize + 1200;
var numRowsVal = tableSize + 10000; let numRowsVal = tableSize + 10000;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.3 table size > numRows > fetchArraySize", function(done) { it("154.1.3 table size > numRows > fetchArraySize", async function() {
var fetchArraySizeVal = tableSize - 91; let fetchArraySizeVal = tableSize - 91;
var numRowsVal = tableSize - 2; let numRowsVal = tableSize - 2;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.4 table size > fetchArraySize > maxRow", function(done) { it("154.1.4 table size > fetchArraySize > maxRow", async function() {
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var numRowsVal = tableSize - 150; let numRowsVal = tableSize - 150;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.5 numRows = fetchArraySize < table size", function(done) { it("154.1.5 numRows = fetchArraySize < table size", async function() {
var fetchArraySizeVal = tableSize - 110; let fetchArraySizeVal = tableSize - 110;
var numRowsVal = tableSize - 110; let numRowsVal = tableSize - 110;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.6 numRows = fetchArraySize = table size", function(done) { it("154.1.6 numRows = fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var numRowsVal = tableSize; let numRowsVal = tableSize;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.7 numRows = fetchArraySize > table size", function(done) { it("154.1.7 numRows = fetchArraySize > table size", async function() {
var fetchArraySizeVal = tableSize + 9999; let fetchArraySizeVal = tableSize + 9999;
var numRowsVal = tableSize + 9999; let numRowsVal = tableSize + 9999;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.8 numRows = fetchArraySize/10", function(done) { it("154.1.8 numRows = fetchArraySize/10", async function() {
var fetchArraySizeVal = tableSize / 10 + 1; let fetchArraySizeVal = tableSize / 10 + 1;
var numRowsVal = tableSize / 10; let numRowsVal = tableSize / 10;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.9 numRows = 10 * fetchArraySize", function(done) { it("154.1.9 numRows = 10 * fetchArraySize", async function() {
var fetchArraySizeVal = 90; let fetchArraySizeVal = 90;
var numRowsVal = 900; let numRowsVal = 900;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("154.1.10 numRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var numRowsVal = tableSize / 10 + 1; let numRowsVal = tableSize / 10 + 1;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.11 numRows = (table size - 1), fetchArraySize = table size", function(done) { it("154.1.11 numRows = (table size - 1), fetchArraySize = table size", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var numRowsVal = tableSize - 1; let numRowsVal = tableSize - 1;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
it("154.1.12 fetchArraySize = (table size - 1), numRows = table size", function(done) { it("154.1.12 fetchArraySize = (table size - 1), numRows = table size", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var numRowsVal = tableSize; let numRowsVal = tableSize;
testGetRow(fetchArraySizeVal, numRowsVal, done); await testGetRow(fetchArraySizeVal, numRowsVal);
}); });
}); });
describe("154.2 getRow() of resultSet = true", function() { describe("154.2 getRow() of resultSet = true", function() {
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testGetRows = function(fetchArraySizeVal, cb) { const testGetRows = async function(fetchArraySizeVal) {
connection.execute( let result = await connection.execute(
"select * from " + tableName + " order by id", "select * from " + tableName + " order by id",
[], [],
{ {
resultSet: true, resultSet: true,
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
// should.strictEqual(result.rows.length, default_maxRows);
var rowCount = 0;
fetchRowFromRS(result.resultSet, rowCount, cb);
} }
); );
let rowCount = 0;
// assert.strictEqual(result.rows.length, default_maxRows);
await fetchRowFromRS(result.resultSet, rowCount);
}; };
function fetchRowFromRS(rs, rowCount, cb) { async function fetchRowFromRS(rs, rowCount) {
rs.getRow(function(err, row) { let row = await rs.getRow();
if (row) { if (row) {
rowCount = rowCount + 1; rowCount = rowCount + 1;
// console.log(rows[i][0]); // console.log(rows[i][0]);
should.strictEqual(row[0], rowCount); assert.strictEqual(row[0], rowCount);
should.strictEqual(row[1], rowCount.toString()); assert.strictEqual(row[1], rowCount.toString());
return fetchRowFromRS(rs, rowCount, cb); return fetchRowFromRS(rs, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("154.2.1 fetchArraySize = 1", function(done) { it("154.2.1 fetchArraySize = 1", async function() {
testGetRows(1, done); await testGetRows(1);
}); });
it("154.2.2 fetchArraySize = tableSize/50", function(done) { it("154.2.2 fetchArraySize = tableSize/50", async function() {
testGetRows(tableSize / 50, done); await testGetRows(tableSize / 50);
}); });
it("154.2.3 fetchArraySize = tableSize/20", function(done) { it("154.2.3 fetchArraySize = tableSize/20", async function() {
testGetRows(tableSize / 20, done); await testGetRows(tableSize / 20);
}); });
it("154.2.4 fetchArraySize = tableSize/10", function(done) { it("154.2.4 fetchArraySize = tableSize/10", async function() {
testGetRows(tableSize / 10, done); await testGetRows(tableSize / 10);
}); });
it("154.2.5 fetchArraySize = tableSize/5", function(done) { it("154.2.5 fetchArraySize = tableSize/5", async function() {
testGetRows(tableSize / 5, done); await testGetRows(tableSize / 5);
}); });
it("154.2.6 fetchArraySize = tableSize", function(done) { it("154.2.6 fetchArraySize = tableSize", async function() {
testGetRows(tableSize, done); await testGetRows(tableSize);
}); });
it("154.2.7 fetchArraySize = (table size - 1)", function(done) { it("154.2.7 fetchArraySize = (table size - 1)", async function() {
testGetRows(tableSize - 1, done); await testGetRows(tableSize - 1);
}); });
}); });
describe("154.3 interleaved calls to getRow() and getRows()", function() { describe("154.3 interleaved calls to getRow() and getRows()", function() {
var numRowsVal_1, numRowsVal_2; let numRowsVal_1, numRowsVal_2;
before(function(done) { before(async function() {
connection.execute( await connection.execute(create_table);
create_table,
function(err) {
should.not.exist(err);
done() ;
}
);
}); });
after(function(done) { after(async function() {
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var testRS = function(fetchArraySizeVal, cb) { const testRS = async function(fetchArraySizeVal) {
connection.execute( let result = await connection.execute(
"select * from " + tableName + " order by id", "select * from " + tableName + " order by id",
[], [],
{ {
resultSet: true, resultSet: true,
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
var rowCount = 0;
fetchRowFromRS(result.resultSet, rowCount, cb);
} }
); );
let rowCount = 0;
fetchRowFromRS(result.resultSet, rowCount);
}; };
function fetchRowFromRS(rs, rowCount, cb) { async function fetchRowFromRS(rs, rowCount) {
rs.getRow(function(err, row) { let row = await rs.getRow();
if (row) { if (row) {
rowCount = rowCount + 1; rowCount = rowCount + 1;
should.strictEqual(row[0], rowCount); assert.strictEqual(row[0], rowCount);
should.strictEqual(row[1], rowCount.toString()); assert.strictEqual(row[1], rowCount.toString());
return fetchRowsFromRS_1(rs, rowCount, cb); return await fetchRowsFromRS_1(rs, rowCount);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
function fetchRowsFromRS_1(rs, rowCount, cb) { async function fetchRowsFromRS_1(rs, rowCount, cb) {
rs.getRows(numRowsVal_1, function(err, rows) { let rows = await rs.getRows(numRowsVal_1);
(rows.length).should.be.belowOrEqual(numRowsVal_1); assert(rows.length <= numRowsVal_1);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1; rowCount = rowCount + 1;
should.strictEqual(rows[i][0], rowCount); assert.strictEqual(rows[i][0], rowCount);
should.strictEqual(rows[i][1], rowCount.toString()); assert.strictEqual(rows[i][1], rowCount.toString());
} }
return fetchRowsFromRS_2(rs, rowCount, cb); return await fetchRowsFromRS_2(rs, rowCount, cb);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
function fetchRowsFromRS_2(rs, rowCount, cb) { async function fetchRowsFromRS_2(rs, rowCount, cb) {
rs.getRows(numRowsVal_2, function(err, rows) { let rows = await rs.getRows(numRowsVal_2);
(rows.length).should.be.belowOrEqual(numRowsVal_2); assert(rows.length <= numRowsVal_2);
if (rows.length > 0) { if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
rowCount = rowCount + 1; rowCount = rowCount + 1;
should.strictEqual(rows[i][0], rowCount); assert.strictEqual(rows[i][0], rowCount);
should.strictEqual(rows[i][1], rowCount.toString()); assert.strictEqual(rows[i][1], rowCount.toString());
} }
return fetchRowFromRS(rs, rowCount, cb); return await fetchRowFromRS(rs, rowCount, cb);
} else { } else {
should.strictEqual(rowCount, tableSize); assert.strictEqual(rowCount, tableSize);
rs.close(function(err) { await rs.close();
should.not.exist(err);
cb();
});
} }
});
} }
it("154.3.1 fetchArraySize = 1", function(done) { it("154.3.1 fetchArraySize = 1", async function() {
var fetchArraySizeVal = 1; let fetchArraySizeVal = 1;
numRowsVal_1 = 2; numRowsVal_1 = 2;
numRowsVal_2 = 10; numRowsVal_2 = 10;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("154.3.2 fetchArraySize = tableSize/50", function(done) { it("154.3.2 fetchArraySize = tableSize/50", async function() {
var fetchArraySizeVal = tableSize / 50; let fetchArraySizeVal = tableSize / 50;
numRowsVal_1 = 5; numRowsVal_1 = 5;
numRowsVal_2 = 88; numRowsVal_2 = 88;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("154.3.3 fetchArraySize = tableSize/20", function(done) { it("154.3.3 fetchArraySize = tableSize/20", async function() {
var fetchArraySizeVal = tableSize / 20; let fetchArraySizeVal = tableSize / 20;
numRowsVal_1 = 50; numRowsVal_1 = 50;
numRowsVal_2 = 100; numRowsVal_2 = 100;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("154.3.4 fetchArraySize = tableSize/10", function(done) { it("154.3.4 fetchArraySize = tableSize/10", async function() {
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
numRowsVal_1 = 30; numRowsVal_1 = 30;
numRowsVal_2 = 99; numRowsVal_2 = 99;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("154.3.5 fetchArraySize = tableSize/5", function(done) { it("154.3.5 fetchArraySize = tableSize/5", async function() {
var fetchArraySizeVal = tableSize / 5; let fetchArraySizeVal = tableSize / 5;
numRowsVal_1 = 5; numRowsVal_1 = 5;
numRowsVal_2 = 88; numRowsVal_2 = 88;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("154.3.6 fetchArraySize = tableSize", function(done) { it("154.3.6 fetchArraySize = tableSize", async function() {
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
numRowsVal_1 = 15; numRowsVal_1 = 15;
numRowsVal_2 = tableSize; numRowsVal_2 = tableSize;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
it("154.3.7 fetchArraySize = (tableSize - 1)", function(done) { it("154.3.7 fetchArraySize = (tableSize - 1)", async function() {
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
numRowsVal_1 = tableSize - 1; numRowsVal_1 = tableSize - 1;
numRowsVal_2 = tableSize; numRowsVal_2 = tableSize;
testRS(fetchArraySizeVal, done); await testRS(fetchArraySizeVal);
}); });
}); });

View File

@ -33,16 +33,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require ('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe("155. fetchArraySize8.js", function() { describe("155. fetchArraySize8.js", function() {
let connection = null; let connection = null;
var default_fetcArraySize = oracledb.fetchArraySize; let default_fetcArraySize = oracledb.fetchArraySize;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_155"; const tableName = "nodb_fetchArraySize_155";
const create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
@ -64,333 +63,275 @@ describe("155. fetchArraySize8.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_fetcArraySize, 100); assert.strictEqual(default_fetcArraySize, 100);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("155.1 Streaming clobs with different oracledb.fetchArraySize", function() { describe("155.1 Streaming clobs with different oracledb.fetchArraySize", function() {
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var basicFetchWithGlobalOption = function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, cb) { const basicFetchWithGlobalOption = async function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID) {
async.series([ await connection.execute(create_table);
function(callback) { await insertData(tableSize);
connection.execute(
create_table,
function(err) {
should.not.exist(err);
callback() ;
}
);
},
function(callback) {
insertData(tableSize, callback);
},
function(callback) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " where id > " + affectedID + " order by id", "select * from " + tableName + " where id > " + affectedID + " order by id"
function(err, result) { );
should.not.exist(err); let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
var resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID; if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
should.strictEqual(result.rows.length, resultLenExpected); assert.strictEqual(result.rows.length, resultLenExpected);
verifyResult(result.rows, callback); await verifyResult(result.rows);
}
); await connection.execute(drop_table);
},
function(callback) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
callback();
}
);
}
], cb);
}; };
it("155.1.1 maxRows > table size > oracledb.fetchArraySize", function(done) { it("155.1.1 maxRows > table size > oracledb.fetchArraySize", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize / 2; let fetchArraySizeVal = tableSize / 2;
var maxRowsVal = tableSize * 2; let maxRowsVal = tableSize * 2;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.2 maxRows > oracledb.fetchArraySize > table size", function(done) { it("155.1.2 maxRows > oracledb.fetchArraySize > table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize + 10; let fetchArraySizeVal = tableSize + 10;
var maxRowsVal = tableSize * 3; let maxRowsVal = tableSize * 3;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.3 table size > maxRows > oracledb.fetchArraySize", function(done) { it("155.1.3 table size > maxRows > oracledb.fetchArraySize", async function() {
var tableSize = 199; let tableSize = 199;
var fetchArraySizeVal = tableSize - 80; let fetchArraySizeVal = tableSize - 80;
var maxRowsVal = tableSize - 50; let maxRowsVal = tableSize - 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("155.1.4 table size > oracledb.fetchArraySize > maxRow", async function() {
var tableSize = 290; let tableSize = 290;
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var maxRowsVal = tableSize - 150; let maxRowsVal = tableSize - 150;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.5 maxRows = oracledb.fetchArraySize < table size", function(done) { it("155.1.5 maxRows = oracledb.fetchArraySize < table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize - 3; let fetchArraySizeVal = tableSize - 3;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.6 maxRows = oracledb.fetchArraySize = table size", function(done) { it("155.1.6 maxRows = oracledb.fetchArraySize = table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.7 maxRows = oracledb.fetchArraySize > table size", function(done) { it("155.1.7 maxRows = oracledb.fetchArraySize > table size", async function() {
var tableSize = 10; let tableSize = 10;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.8 maxRows = oracledb.fetchArraySize/10", function(done) { it("155.1.8 maxRows = oracledb.fetchArraySize/10", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal / 10; let maxRowsVal = fetchArraySizeVal / 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.9 maxRows = 10 * oracledb.fetchArraySize", function(done) { it("155.1.9 maxRows = 10 * oracledb.fetchArraySize", async function() {
var tableSize = 2; let tableSize = 2;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal * 10; let maxRowsVal = fetchArraySizeVal * 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("155.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var tableSize = 200; let tableSize = 200;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var maxRowsVal = fetchArraySizeVal + 50; let maxRowsVal = fetchArraySizeVal + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.11 maxRows = 0, fetchArraySize = table size ", function(done) { it("155.1.11 maxRows = 0, fetchArraySize = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = 0; let maxRowsVal = 0;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.12 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("155.1.12 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize - 1; let maxRowsVal = tableSize - 1;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.1.13 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("155.1.13 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });
describe("155.2 Streaming clobs with different execute() option fetchArraySize", function() { describe("155.2 Streaming clobs with different execute() option fetchArraySize", function() {
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var basicFetchWithExecOption = function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, cb) { const basicFetchWithExecOption = async function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID) {
async.series([ await connection.execute(create_table);
function(callback) { await insertData(tableSize);
connection.execute(
create_table,
function(err) {
should.not.exist(err);
callback() ;
}
);
},
function(callback) {
insertData(tableSize, callback);
},
function(callback) {
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " where id > " + affectedID + " order by id", "select * from " + tableName + " where id > " + affectedID + " order by id",
[], [],
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
}, }
function(err, result) { );
should.not.exist(err); let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
var resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID; if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
should.strictEqual(result.rows.length, resultLenExpected); assert.strictEqual(result.rows.length, resultLenExpected);
verifyResult(result.rows, callback); await verifyResult(result.rows);
}
);
},
function(callback) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
callback();
}
);
}
], cb);
}; };
it("155.2.1 maxRows > table size > oracledb.fetchArraySize", function(done) { it("155.2.1 maxRows > table size > oracledb.fetchArraySize", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize - 50; let fetchArraySizeVal = tableSize - 50;
var maxRowsVal = tableSize + 200; let maxRowsVal = tableSize + 200;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.2 maxRows > oracledb.fetchArraySize > table size", function(done) { it("155.2.2 maxRows > oracledb.fetchArraySize > table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = tableSize + 50; let maxRowsVal = tableSize + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.3 table size > maxRows > oracledb.fetchArraySize", function(done) { it("155.2.3 table size > maxRows > oracledb.fetchArraySize", async function() {
var tableSize = 199; let tableSize = 199;
var fetchArraySizeVal = tableSize - 130; let fetchArraySizeVal = tableSize - 130;
var maxRowsVal = tableSize - 50; let maxRowsVal = tableSize - 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("155.2.4 table size > oracledb.fetchArraySize > maxRow", async function() {
var tableSize = 290; let tableSize = 290;
var fetchArraySizeVal = tableSize - 10; let fetchArraySizeVal = tableSize - 10;
var maxRowsVal = tableSize - 50; let maxRowsVal = tableSize - 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.5 maxRows = oracledb.fetchArraySize < table size", function(done) { it("155.2.5 maxRows = oracledb.fetchArraySize < table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize - 3; let fetchArraySizeVal = tableSize - 3;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.6 maxRows = oracledb.fetchArraySize = table size", function(done) { it("155.2.6 maxRows = oracledb.fetchArraySize = table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.7 maxRows = oracledb.fetchArraySize > table size", function(done) { it("155.2.7 maxRows = oracledb.fetchArraySize > table size", async function() {
var tableSize = 10; let tableSize = 10;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.8 maxRows = oracledb.fetchArraySize/10", function(done) { it("155.2.8 maxRows = oracledb.fetchArraySize/10", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal / 10; let maxRowsVal = fetchArraySizeVal / 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.9 maxRows = 10 * oracledb.fetchArraySize", function(done) { it("155.2.9 maxRows = 10 * oracledb.fetchArraySize", async function() {
var tableSize = 2; let tableSize = 2;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal * 10; let maxRowsVal = fetchArraySizeVal * 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("155.2.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var tableSize = 200; let tableSize = 200;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var maxRowsVal = fetchArraySizeVal + 50; let maxRowsVal = fetchArraySizeVal + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.11 maxRows = 0, fetchArraySize = table size ", function(done) { it("155.2.11 maxRows = 0, fetchArraySize = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = 0; let maxRowsVal = 0;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.12 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("155.2.12 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize - 1; let maxRowsVal = tableSize - 1;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("155.2.13 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("155.2.13 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });
var insertData = function(tableSize, cb) { let insertData = async function(tableSize) {
var insert_data = "BEGIN \n" + const insert_data = "BEGIN \n" +
" FOR i IN 1.." + tableSize + " LOOP \n" + " FOR i IN 1.." + tableSize + " LOOP \n" +
" EXECUTE IMMEDIATE (' \n" + " EXECUTE IMMEDIATE (' \n" +
" insert into " + tableName + " values (' || i || ',''CLOB' || to_char(i) || ''') \n" + " insert into " + tableName + " values (' || i || ',''CLOB' || to_char(i) || ''') \n" +
@ -399,65 +340,25 @@ describe("155. fetchArraySize8.js", function() {
" commit; \n" + " commit; \n" +
"END; "; "END; ";
async.series([ await connection.execute(insert_data);
function(callback) { let result = await connection.execute(
connection.execute( "select id from " + tableName
insert_data,
function(err) {
should.not.exist(err);
callback();
}
); );
}, assert.strictEqual(result.rows.length, tableSize);
function(callback) {
connection.execute(
"select id from " + tableName,
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rows.length, tableSize);
callback();
}
);
}
], cb);
}; };
var verifyResult = function(rows, cb) { const verifyResult = async function(rows) {
async.eachSeries( for (let row of rows) {
rows, await verifyEachRow(row);
verifyEachRow,
function(err) {
should.not.exist(err);
return cb();
} }
);
}; };
var verifyEachRow = function(row, cb) { const verifyEachRow = async function(row) {
var id = row[0]; const id = row[0];
should.strictEqual(row[0], id); assert.strictEqual(row[0], id);
var lob = row[1]; const lob = row[1];
should.exist(lob); const clobData = await lob.getData();
lob.setEncoding('utf8'); assert.strictEqual(clobData, "CLOB" + String(id));
var clobData = '';
lob.on('data', function(chunk) {
clobData += chunk;
});
lob.on('error', function(err) {
should.not.exist(err);
});
lob.on('end', function(err) {
should.not.exist(err);
should.strictEqual(clobData, "CLOB" + String(id));
});
lob.on('close', function(err) {
should.not.exist(err);
cb(err);
});
}; };
}); });

View File

@ -33,17 +33,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js');
describe("156. fetchArraySize9.js", function() { describe("156. fetchArraySize9.js", function() {
let connection = null; let connection = null;
var default_fetcArraySize = oracledb.fetchArraySize; let default_fetcArraySize = oracledb.fetchArraySize;
var default_maxRows = oracledb.maxRows; let default_maxRows = oracledb.maxRows;
var tableName = "nodb_fetchArraySize_156"; const tableName = "nodb_fetchArraySize_156";
const create_table = "BEGIN \n" + const create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
@ -65,333 +63,277 @@ describe("156. fetchArraySize9.js", function() {
const drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before(function(done) { before(async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.strictEqual(default_fetcArraySize, 100); assert.strictEqual(default_fetcArraySize, 100);
should.strictEqual(default_maxRows, 0); assert.strictEqual(default_maxRows, 0);
should.not.exist(err);
connection = conn;
done();
});
}); });
after(function(done) { after(async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe("156.1 Streaming blobs with different oracledb.fetchArraySize", function() { describe("156.1 Streaming blobs with different oracledb.fetchArraySize", function() {
afterEach(function(done) { afterEach(function() {
oracledb.fetchArraySize = default_fetcArraySize; oracledb.fetchArraySize = default_fetcArraySize;
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var basicFetchWithGlobalOption = function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, cb) { const basicFetchWithGlobalOption = async function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID) {
async.series([ await connection.execute(create_table);
function(callback) { await insertData(tableSize);
connection.execute(
create_table,
function(err) {
should.not.exist(err);
callback() ;
}
);
},
function(callback) {
insertData(tableSize, callback);
},
function(callback) {
oracledb.fetchArraySize = fetchArraySizeVal; oracledb.fetchArraySize = fetchArraySizeVal;
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " where id > " + affectedID + " order by id", "select * from " + tableName + " where id > " + affectedID + " order by id"
function(err, result) { );
should.not.exist(err); let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
var resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID; if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
should.strictEqual(result.rows.length, resultLenExpected); assert.strictEqual(result.rows.length, resultLenExpected);
verifyResult(result.rows, callback); await verifyResult(result.rows);
}
); await connection.execute(drop_table);
},
function(callback) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
callback();
}
);
}
], cb);
}; };
it("156.1.1 maxRows > table size > oracledb.fetchArraySize", function(done) { it("156.1.1 maxRows > table size > oracledb.fetchArraySize", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize - 50; let fetchArraySizeVal = tableSize - 50;
var maxRowsVal = tableSize + 200; let maxRowsVal = tableSize + 200;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.2 maxRows > oracledb.fetchArraySize > table size", function(done) { it("156.1.2 maxRows > oracledb.fetchArraySize > table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = tableSize + 50; let maxRowsVal = tableSize + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.3 table size > maxRows > oracledb.fetchArraySize", function(done) { it("156.1.3 table size > maxRows > oracledb.fetchArraySize", async function() {
var tableSize = 199; let tableSize = 199;
var fetchArraySizeVal = tableSize - 130; let fetchArraySizeVal = tableSize - 130;
var maxRowsVal = tableSize - 50; let maxRowsVal = tableSize - 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("156.1.4 table size > oracledb.fetchArraySize > maxRow", async function() {
var tableSize = 290; let tableSize = 290;
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var maxRowsVal = tableSize - 150; let maxRowsVal = tableSize - 150;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.5 maxRows = oracledb.fetchArraySize < table size", function(done) { it("156.1.5 maxRows = oracledb.fetchArraySize < table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize - 3; let fetchArraySizeVal = tableSize - 3;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.6 maxRows = oracledb.fetchArraySize = table size", function(done) { it("156.1.6 maxRows = oracledb.fetchArraySize = table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.7 maxRows = oracledb.fetchArraySize > table size", function(done) { it("156.1.7 maxRows = oracledb.fetchArraySize > table size", async function() {
var tableSize = 10; let tableSize = 10;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.8 maxRows = oracledb.fetchArraySize/10", function(done) { it("156.1.8 maxRows = oracledb.fetchArraySize/10", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal / 10; let maxRowsVal = fetchArraySizeVal / 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.9 maxRows = 10 * oracledb.fetchArraySize", function(done) { it("156.1.9 maxRows = 10 * oracledb.fetchArraySize", async function() {
var tableSize = 2; let tableSize = 2;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal * 10; let maxRowsVal = fetchArraySizeVal * 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("156.1.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var tableSize = 200; let tableSize = 200;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var maxRowsVal = fetchArraySizeVal + 50; let maxRowsVal = fetchArraySizeVal + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.11 maxRows = 0, fetchArraySize = table size ", function(done) { it("156.1.11 maxRows = 0, fetchArraySize = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = 0; let maxRowsVal = 0;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.12 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("156.1.12 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize - 1; let maxRowsVal = tableSize - 1;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.1.13 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("156.1.13 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithGlobalOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });
describe("156.2 Streaming blobs with different execute() option fetchArraySize", function() { describe("156.2 Streaming blobs with different execute() option fetchArraySize", function() {
afterEach(function(done) { afterEach(function() {
oracledb.maxRows = default_maxRows; oracledb.maxRows = default_maxRows;
done();
}); });
var basicFetchWithExecOption = function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, cb) { let basicFetchWithExecOption = async function(tableSize, fetchArraySizeVal, maxRowsVal, affectedID) {
async.series([ await connection.execute(create_table);
function(callback) { await insertData(tableSize);
connection.execute(
create_table,
function(err) {
should.not.exist(err);
callback() ;
}
);
},
function(callback) {
insertData(tableSize, callback);
},
function(callback) {
oracledb.maxRows = maxRowsVal; oracledb.maxRows = maxRowsVal;
connection.execute( let result = await connection.execute(
"select * from " + tableName + " where id > " + affectedID + " order by id", "select * from " + tableName + " where id > " + affectedID + " order by id",
[], [],
{ {
fetchArraySize: fetchArraySizeVal fetchArraySize: fetchArraySizeVal
}, }
function(err, result) { );
should.not.exist(err); let resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
var resultLenExpected = maxRowsVal > (tableSize - affectedID) ? (tableSize - affectedID) : maxRowsVal;
if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID; if (maxRowsVal === 0) resultLenExpected = tableSize - affectedID;
should.strictEqual(result.rows.length, resultLenExpected); assert.strictEqual(result.rows.length, resultLenExpected);
verifyResult(result.rows, callback); await verifyResult(result.rows);
}
); await connection.execute(drop_table);
},
function(callback) {
connection.execute(
drop_table,
function(err) {
should.not.exist(err);
callback();
}
);
}
], cb);
}; };
it("156.2.1 maxRows > table size > oracledb.fetchArraySize", function(done) { it("156.2.1 maxRows > table size > oracledb.fetchArraySize", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize - 50; let fetchArraySizeVal = tableSize - 50;
var maxRowsVal = tableSize + 200; let maxRowsVal = tableSize + 200;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.2 maxRows > oracledb.fetchArraySize > table size", function(done) { it("156.2.2 maxRows > oracledb.fetchArraySize > table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = tableSize + 50; let maxRowsVal = tableSize + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.3 table size > maxRows > oracledb.fetchArraySize", function(done) { it("156.2.3 table size > maxRows > oracledb.fetchArraySize", async function() {
var tableSize = 199; let tableSize = 199;
var fetchArraySizeVal = tableSize - 30; let fetchArraySizeVal = tableSize - 30;
var maxRowsVal = tableSize - 10; let maxRowsVal = tableSize - 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.4 table size > oracledb.fetchArraySize > maxRow", function(done) { it("156.2.4 table size > oracledb.fetchArraySize > maxRow", async function() {
var tableSize = 290; let tableSize = 290;
var fetchArraySizeVal = tableSize - 90; let fetchArraySizeVal = tableSize - 90;
var maxRowsVal = tableSize - 150; let maxRowsVal = tableSize - 150;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.5 maxRows = oracledb.fetchArraySize < table size", function(done) { it("156.2.5 maxRows = oracledb.fetchArraySize < table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize - 3; let fetchArraySizeVal = tableSize - 3;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.6 maxRows = oracledb.fetchArraySize = table size", function(done) { it("156.2.6 maxRows = oracledb.fetchArraySize = table size", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.7 maxRows = oracledb.fetchArraySize > table size", function(done) { it("156.2.7 maxRows = oracledb.fetchArraySize > table size", async function() {
var tableSize = 10; let tableSize = 10;
var fetchArraySizeVal = tableSize + 30; let fetchArraySizeVal = tableSize + 30;
var maxRowsVal = fetchArraySizeVal; let maxRowsVal = fetchArraySizeVal;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.8 maxRows = oracledb.fetchArraySize/10", function(done) { it("156.2.8 maxRows = oracledb.fetchArraySize/10", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal / 10; let maxRowsVal = fetchArraySizeVal / 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.9 maxRows = 10 * oracledb.fetchArraySize", function(done) { it("156.2.9 maxRows = 10 * oracledb.fetchArraySize", async function() {
var tableSize = 2; let tableSize = 2;
var fetchArraySizeVal = 30; let fetchArraySizeVal = 30;
var maxRowsVal = fetchArraySizeVal * 10; let maxRowsVal = fetchArraySizeVal * 10;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", function(done) { it("156.2.10 maxRows > fetchArraySize, fetchArraySize = (table size)/10", async function() {
var tableSize = 200; let tableSize = 200;
var fetchArraySizeVal = tableSize / 10; let fetchArraySizeVal = tableSize / 10;
var maxRowsVal = tableSize / 10 + 50; let maxRowsVal = tableSize / 10 + 50;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.11 maxRows = 0, fetchArraySize = table size ", function(done) { it("156.2.11 maxRows = 0, fetchArraySize = table size ", async function() {
var tableSize = 20; let tableSize = 20;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = 0; let maxRowsVal = 0;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.12 maxRows = (table size - 1), fetchArraySize = table size ", function(done) { it("156.2.12 maxRows = (table size - 1), fetchArraySize = table size ", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize; let fetchArraySizeVal = tableSize;
var maxRowsVal = tableSize - 1; let maxRowsVal = tableSize - 1;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
it("156.2.13 fetchArraySize = (table size - 1), maxRows = table size ", function(done) { it("156.2.13 fetchArraySize = (table size - 1), maxRows = table size ", async function() {
var tableSize = 100; let tableSize = 100;
var fetchArraySizeVal = tableSize - 1; let fetchArraySizeVal = tableSize - 1;
var maxRowsVal = tableSize; let maxRowsVal = tableSize;
var affectedID = 0; let affectedID = 0;
basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID, done); await basicFetchWithExecOption(tableSize, fetchArraySizeVal, maxRowsVal, affectedID);
}); });
}); });
var insertData = function(tableSize, cb) { const insertData = async function(tableSize) {
var insert_data = "DECLARE \n" + const insert_data = "DECLARE \n" +
" tmpchar VARCHAR2(2000); \n" + " tmpchar VARCHAR2(2000); \n" +
" tmplob BLOB; \n" + " tmplob BLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
@ -402,63 +344,25 @@ describe("156. fetchArraySize9.js", function() {
" END LOOP; \n" + " END LOOP; \n" +
" commit; \n" + " commit; \n" +
"END; "; "END; ";
async.series([ await connection.execute(insert_data);
function(callback) { const result = await connection.execute(
connection.execute( "select id from " + tableName
insert_data,
function(err) {
should.not.exist(err);
callback();
}
); );
}, assert.strictEqual(result.rows.length, tableSize);
function(callback) {
connection.execute(
"select id from " + tableName,
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rows.length, tableSize);
callback();
}
);
}
], cb);
}; };
var verifyResult = function(rows, cb) { const verifyResult = async function(rows) {
async.eachSeries( for (let row of rows) {
rows, await verifyEachRow(row);
verifyEachRow,
function(err) {
should.not.exist(err);
return cb();
} }
);
}; };
var verifyEachRow = function(row, cb) { const verifyEachRow = async function(row) {
var id = row[0]; const id = row[0];
var lob = row[1]; const lob = row[1];
should.exist(lob); const blobData = await lob.getData();
var blobData = 0; const expected = Buffer.from((String(id)), "utf-8");
var totalLength = 0; assert.deepStrictEqual(blobData, expected);
blobData = Buffer.alloc(0);
lob.on('data', function(chunk) {
totalLength = totalLength + chunk.length;
blobData = Buffer.concat([blobData, chunk], totalLength);
});
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event.");
});
lob.on('end', function(err) {
should.not.exist(err);
var expected = Buffer.from((String(id)), "utf-8");
should.strictEqual(assist.compare2Buffers(blobData, expected), true);
cb(err);
});
}; };
}); });

View File

@ -32,8 +32,7 @@
'use strict'; 'use strict';
const oracledb = require ('oracledb'); const oracledb = require ('oracledb');
const should = require ('should'); const assert = require('assert');
const async = require ('async');
const dbConfig = require ('./dbconfig.js'); const dbConfig = require ('./dbconfig.js');
const assist = require ('./dataTypeAssist.js'); const assist = require ('./dataTypeAssist.js');
@ -41,61 +40,49 @@ const assist = require ('./dataTypeAssist.js');
describe('56. fetchAs.js', function() { describe('56. fetchAs.js', function() {
let connection = null; let connection = null;
beforeEach('get one connection', function(done) { beforeEach('get one connection', async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.not.exist(err);
connection = conn;
done();
});
}); });
afterEach('release connection, reset fetchAsString property', function(done) { afterEach('release connection, reset fetchAsString property', async function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
it('56.1 property value check', function() { it('56.1 property value check', function() {
(oracledb.fetchAsString).should.eql([]); assert.deepStrictEqual(oracledb.fetchAsString, []);
oracledb.fetchAsString = [oracledb.DATE]; oracledb.fetchAsString = [oracledb.DATE];
should.deepEqual(oracledb.fetchAsString, [ oracledb.DATE ]); assert.deepStrictEqual(oracledb.fetchAsString, [ oracledb.DATE ]);
oracledb.fetchAsString = [ oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.NUMBER ];
should.deepEqual(oracledb.fetchAsString, [ oracledb.NUMBER ]); assert.deepStrictEqual(oracledb.fetchAsString, [ oracledb.NUMBER ]);
oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ];
should.deepEqual(oracledb.fetchAsString, [ oracledb.DATE, oracledb.NUMBER ]); assert.deepStrictEqual(oracledb.fetchAsString, [ oracledb.DATE, oracledb.NUMBER ]);
oracledb.fetchAsString = [ oracledb.DB_TYPE_JSON ]; oracledb.fetchAsString = [ oracledb.DB_TYPE_JSON ];
should.deepEqual(oracledb.fetchAsString, [ oracledb.DB_TYPE_JSON ]); assert.deepStrictEqual(oracledb.fetchAsString, [ oracledb.DB_TYPE_JSON ]);
oracledb.fetchAsString = [ oracledb.DB_TYPE_JSON, oracledb.DATE, oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.DB_TYPE_JSON, oracledb.DATE, oracledb.NUMBER ];
should.deepEqual(oracledb.fetchAsString, [ oracledb.DB_TYPE_JSON, oracledb.DATE, oracledb.NUMBER ]); assert.deepStrictEqual(oracledb.fetchAsString, [ oracledb.DB_TYPE_JSON, oracledb.DATE, oracledb.NUMBER ]);
}); });
it('56.2 Fetch DATE column values as STRING - by-Column name', function(done) { it('56.2 Fetch DATE column values as STRING - by-Column name', async function() {
connection.execute( let result = await connection.execute(
"SELECT TO_DATE('2005-01-06', 'YYYY-DD-MM') AS TS_DATE FROM DUAL", "SELECT TO_DATE('2005-01-06', 'YYYY-DD-MM') AS TS_DATE FROM DUAL",
[], [],
{ {
outFormat: oracledb.OUT_FORMAT_OBJECT, outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchInfo : { "TS_DATE": { type : oracledb.STRING } } fetchInfo : { "TS_DATE": { type : oracledb.STRING } }
},
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0]);
result.rows[0].TS_DATE.should.be.a.String();
done();
} }
); );
assert.strictEqual(typeof result.rows[0].TS_DATE, "string");
}); });
it('56.3 Fetch DATE, NUMBER column values STRING - by Column-name', function(done) { it('56.3 Fetch DATE, NUMBER column values STRING - by Column-name', async function() {
connection.execute( let result = await connection.execute(
"SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL", "SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL",
[], [],
{ {
@ -105,22 +92,17 @@ describe('56. fetchAs.js', function() {
"TS_DATE" : { type : oracledb.STRING }, "TS_DATE" : { type : oracledb.STRING },
"TS_NUM" : { type : oracledb.STRING } "TS_NUM" : { type : oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0]);
result.rows[0].TS_DATE.should.be.a.String();
result.rows[0].TS_NUM.should.be.a.String();
Number(result.rows[0].TS_NUM).should.equal(1234567);
done();
} }
); );
assert.strictEqual(typeof result.rows[0].TS_DATE, "string");
assert.strictEqual(typeof result.rows[0].TS_NUM, "string");
assert.strictEqual(Number(result.rows[0].TS_NUM), 1234567);
}); });
it('56.4 Fetch DATE, NUMBER as STRING by-time configuration and by-name', function(done) { it('56.4 Fetch DATE, NUMBER as STRING by-time configuration and by-name', async function() {
oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ];
connection.execute( let result = await connection.execute(
"SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL", "SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL",
[], [],
{ {
@ -130,22 +112,17 @@ describe('56. fetchAs.js', function() {
"TS_DATE" : { type : oracledb.STRING }, "TS_DATE" : { type : oracledb.STRING },
"TS_NUM" : { type : oracledb.STRING } "TS_NUM" : { type : oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0]);
result.rows[0].TS_DATE.should.be.a.String();
result.rows[0].TS_NUM.should.be.a.String();
Number(result.rows[0].TS_NUM).should.equal(1234567);
done();
} }
); );
assert.strictEqual(typeof result.rows[0].TS_DATE, "string");
assert.strictEqual(typeof result.rows[0].TS_NUM, "string");
assert.strictEqual(Number(result.rows[0].TS_NUM), 1234567);
}); });
it('56.5 Fetch DATE, NUMBER column as STRING by-type and override at execute time', function(done) { it('56.5 Fetch DATE, NUMBER column as STRING by-type and override at execute time', async function() {
oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ];
connection.execute( let result = await connection.execute(
"SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL", "SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL",
[], [],
{ {
@ -155,20 +132,15 @@ describe('56. fetchAs.js', function() {
"TS_DATE" : { type : oracledb.DEFAULT }, "TS_DATE" : { type : oracledb.DEFAULT },
"TS_NUM" : { type : oracledb.STRING } "TS_NUM" : { type : oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0]);
result.rows[0].TS_DATE.should.be.an.Object;
result.rows[0].TS_NUM.should.be.a.String();
Number(result.rows[0].TS_NUM).should.equal(1234567);
done();
} }
); );
assert.strictEqual(typeof result.rows[0].TS_DATE, "object");
assert.strictEqual(typeof result.rows[0].TS_NUM, "string");
assert.strictEqual(Number(result.rows[0].TS_NUM), 1234567);
}); });
it('56.6 Fetch ROWID column values STRING - non-ResultSet', function(done) { it('56.6 Fetch ROWID column values STRING - non-ResultSet', async function() {
connection.execute( let result = await connection.execute(
"SELECT ROWID from DUAL", "SELECT ROWID from DUAL",
[], [],
{ {
@ -177,18 +149,13 @@ describe('56. fetchAs.js', function() {
{ {
"ROWID" : { type : oracledb.STRING } "ROWID" : { type : oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0].TS_DATA);
result.rows[0].ROWID.should.be.a.String();
done();
} }
); );
assert.strictEqual(typeof result.rows[0].ROWID, "string");
}); });
it('56.7 Fetch ROWID column values STRING - ResultSet', function(done) { it('56.7 Fetch ROWID column values STRING - ResultSet', async function() {
connection.execute( let result = await connection.execute(
"SELECT ROWID from DUAL", "SELECT ROWID from DUAL",
[], [],
{ {
@ -198,21 +165,11 @@ describe('56. fetchAs.js', function() {
{ {
"ROWID" : { type : oracledb.STRING } "ROWID" : { type : oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
result.resultSet.getRow(function(err, row) {
should.not.exist(err);
// console.log(row);
row.ROWID.should.be.a.String();
result.resultSet.close(function(err) {
should.not.exist(err);
done();
});
});
} }
); );
let row = await result.resultSet.getRow();
assert.strictEqual(typeof row.ROWID, "string");
await result.resultSet.close();
}); });
/* /*
@ -221,7 +178,7 @@ describe('56. fetchAs.js', function() {
* Numbers out of above range will be rounded. * Numbers out of above range will be rounded.
* The last element is out of Oracle database standard Number range. It will be rounded by database. * The last element is out of Oracle database standard Number range. It will be rounded by database.
*/ */
var numStrs = let numStrs =
[ [
'17249138680355831', '17249138680355831',
'-17249138680355831', '-17249138680355831',
@ -230,7 +187,7 @@ describe('56. fetchAs.js', function() {
'0.1724913868035583123456789123456789123456' '0.1724913868035583123456789123456789123456'
]; ];
var numResults = let numResults =
[ [
'17249138680355831', '17249138680355831',
'-17249138680355831', '-17249138680355831',
@ -239,9 +196,9 @@ describe('56. fetchAs.js', function() {
'.172491386803558312345678912345678912346' '.172491386803558312345678912345678912346'
]; ];
it('56.8 large numbers with fetchInfo', function(done) { it('56.8 large numbers with fetchInfo', async function() {
async.eachSeries(numStrs, function(element, callback) { for (let element of numStrs) {
connection.execute( let result = await connection.execute(
"SELECT TO_NUMBER( " + element + " ) AS TS_NUM FROM DUAL", "SELECT TO_NUMBER( " + element + " ) AS TS_NUM FROM DUAL",
[], [],
{ {
@ -250,62 +207,49 @@ describe('56. fetchAs.js', function() {
{ {
"TS_NUM" : { type : oracledb.STRING } "TS_NUM" : { type : oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
result.rows[0].TS_NUM.should.be.a.String();
(result.rows[0].TS_NUM).should.eql(numResults[numStrs.indexOf(element)]);
callback();
} }
); );
}, function(err) { assert.strictEqual(typeof result.rows[0].TS_NUM, "string");
should.not.exist(err); assert.strictEqual(result.rows[0].TS_NUM, numResults[numStrs.indexOf(element)]);
done(); }
});
}); });
it('56.9 large numbers with setting fetchAsString property', function(done) { it('56.9 large numbers with setting fetchAsString property', async function() {
oracledb.fetchAsString = [ oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.NUMBER ];
async.eachSeries(numStrs, function(element, callback) { for (let element of numStrs) {
connection.execute( let result = await connection.execute(
"SELECT TO_NUMBER( " + element + " ) AS TS_NUM FROM DUAL", "SELECT TO_NUMBER( " + element + " ) AS TS_NUM FROM DUAL",
[], [],
{ outFormat : oracledb.OUT_FORMAT_OBJECT }, { outFormat : oracledb.OUT_FORMAT_OBJECT }
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0].TS_NUM);
result.rows[0].TS_NUM.should.be.a.String();
(result.rows[0].TS_NUM).should.eql(numResults[numStrs.indexOf(element)]);
callback();
}
); );
}, function(err) { assert.strictEqual(typeof result.rows[0].TS_NUM, "string");
should.not.exist(err); assert.strictEqual(result.rows[0].TS_NUM, numResults[numStrs.indexOf(element)]);
done(); }
});
}); });
// FetchInfo format should <columName> : {type : oracledb.<type> } // FetchInfo format should <columName> : {type : oracledb.<type> }
it('56.10 invalid syntax for type should result in error', function(done) { it('56.10 invalid syntax for type should result in error', async function() {
connection.execute ( await assert.rejects(
async () => {
await connection.execute(
"SELECT SYSDATE AS THE_DATE FROM DUAL", "SELECT SYSDATE AS THE_DATE FROM DUAL",
{ }, { },
{ fetchInfo : { "THE_DATE" : oracledb.STRING }}, { fetchInfo : { "THE_DATE" : oracledb.STRING }}
function(err) { );
should.exist (err) ; },
should.strictEqual(err.message, 'NJS-015: type was not specified for conversion'); // NJS-015: type was not specified for conversion
done (); / NJS-015:/
}); );
}); });
it('56.11 assigns an empty array to fetchAsString', function() { it('56.11 assigns an empty array to fetchAsString', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
(oracledb.fetchAsString).should.eql([]); assert.deepStrictEqual(oracledb.fetchAsString, []);
}); });
it('56.12 Negative - empty string', function() { it('56.12 Negative - empty string', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = ''; oracledb.fetchAsString = '';
}, },
@ -314,7 +258,7 @@ describe('56. fetchAs.js', function() {
}); });
it('56.13 Negative - null', function() { it('56.13 Negative - null', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = null; oracledb.fetchAsString = null;
}, },
@ -323,7 +267,7 @@ describe('56. fetchAs.js', function() {
}); });
it('56.14 Negative - undefined', function() { it('56.14 Negative - undefined', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = undefined; oracledb.fetchAsString = undefined;
}, },
@ -332,7 +276,7 @@ describe('56. fetchAs.js', function() {
}); });
it('56.15 Negative - NaN', function() { it('56.15 Negative - NaN', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = NaN; oracledb.fetchAsString = NaN;
}, },
@ -341,7 +285,7 @@ describe('56. fetchAs.js', function() {
}); });
it('56.16 Negative - invalid type of value, number', function() { it('56.16 Negative - invalid type of value, number', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = 10; oracledb.fetchAsString = 10;
}, },
@ -350,7 +294,7 @@ describe('56. fetchAs.js', function() {
}); });
it('56.17 Negative - invalid type of value, string', function() { it('56.17 Negative - invalid type of value, string', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = 'abc'; oracledb.fetchAsString = 'abc';
}, },
@ -358,64 +302,54 @@ describe('56. fetchAs.js', function() {
); );
}); });
it('56.18 Negative - passing oracledb.DATE type to fetchInfo', function(done) { it('56.18 Negative - passing oracledb.DATE type to fetchInfo', async function() {
connection.execute( await assert.rejects(
async () => {
await connection.execute(
"select sysdate as ts_date from dual", "select sysdate as ts_date from dual",
{ }, { },
{ {
fetchInfo: { ts_date: { type: oracledb.DATE } } fetchInfo: { ts_date: { type: oracledb.DATE } }
},
function(err, result) {
should.exist(err);
should.strictEqual(
err.message,
'NJS-021: invalid type for conversion specified'
);
should.not.exist(result);
done();
} }
); );
},
// NJS-021: invalid type for conversion specified
/NJS-021:/
);
}); });
it('56.19 Negative - passing empty JSON to fetchInfo', function(done) { it('56.19 Negative - passing empty JSON to fetchInfo', async function() {
connection.execute( let result = await connection.execute(
"select sysdate as ts_date from dual", "select sysdate as ts_date from dual",
{ }, { },
{ {
fetchInfo: {} fetchInfo: {}
},
function(err, result) {
should.not.exist(err);
should.exist(result);
(result.rows[0][0]).should.be.a.Date();
done();
} }
); );
assert(result);
assert.strictEqual(result.rows[0][0] instanceof Date, true);
}); });
it('56.20 Negative - passing oracledb.NUMBER type to fetchInfo', function(done) { it('56.20 Negative - passing oracledb.NUMBER type to fetchInfo', async function() {
connection.execute( await assert.rejects(
async () => {
await connection.execute(
"select sysdate as ts_date from dual", "select sysdate as ts_date from dual",
{ }, { },
{ {
fetchInfo: { ts_date: { type: oracledb.NUMBER } } fetchInfo: { ts_date: { type: oracledb.NUMBER } }
},
function(err, result) {
should.exist(err);
should.strictEqual(
err.message,
'NJS-021: invalid type for conversion specified'
);
should.not.exist(result);
done();
} }
); );
},
// NJS-021: invalid type for conversion specified
/NJS-021:/
);
}); });
it('56.21 Negative - invalid type of value, Date', function() { it('56.21 Negative - invalid type of value, Date', function() {
should.throws( assert.throws(
function() { function() {
var dt = new Date (); let dt = new Date ();
oracledb.fetchAsString = dt; oracledb.fetchAsString = dt;
}, },
/NJS-004:/ /NJS-004:/
@ -423,9 +357,9 @@ describe('56. fetchAs.js', function() {
}); });
it('56.22 Negative - invalid type of value, Buffer', function() { it('56.22 Negative - invalid type of value, Buffer', function() {
should.throws( assert.throws(
function() { function() {
var buf = assist.createBuffer (10) ; // arbitary sized buffer let buf = assist.createBuffer (10) ; // arbitary sized buffer
oracledb.fetchAsString = buf; oracledb.fetchAsString = buf;
}, },
/NJS-004:/ /NJS-004:/

View File

@ -34,24 +34,16 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const async = require('async'); const assert = require('assert');
const should = require('should');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('139. fetchAsStringWithRefCursor.js', function() { describe('139. fetchAsStringWithRefCursor.js', function() {
let connection = null; let connection = null;
var tableName = "nodb_tab_fetchAsRefCursor"; const tableName = "nodb_tab_fetchAsRefCursor";
before(function(done) { before(async function() {
async.series([ connection = await oracledb.getConnection(dbConfig);
function(cb) { // PL/SQL procedure to create the table
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
});
},
function createTable(cb) {
let sql = "BEGIN \n" + let sql = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
@ -70,17 +62,10 @@ describe('139. fetchAsStringWithRefCursor.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
await connection.execute(sql);
connection.execute( // PL/SQL procedure to insert data into the table
sql, sql = "DECLARE \n" +
function(err) {
should.not.exist(err);
cb();
}
);
},
function insertData(cb) {
let sql = "DECLARE \n" +
" x NUMBER := 0; \n" + " x NUMBER := 0; \n" +
" n VARCHAR2(20); \n" + " n VARCHAR2(20); \n" +
"BEGIN \n" + "BEGIN \n" +
@ -90,70 +75,31 @@ describe('139. fetchAsStringWithRefCursor.js', function() {
" INSERT INTO " + tableName + " VALUES(x, n, TO_DATE('2012-02-18', 'YYYY-MM-DD')); \n" + " INSERT INTO " + tableName + " VALUES(x, n, TO_DATE('2012-02-18', 'YYYY-MM-DD')); \n" +
" END LOOP; \n" + " END LOOP; \n" +
"END; "; "END; ";
await connection.execute(sql);
connection.execute( // PL/SQL procedure for the ref cursor
sql,
function(err) {
should.not.exist(err);
cb();
}
);
},
function createProc(cb) {
let proc = "CREATE OR REPLACE PROCEDURE nodb_proc_fetchcursor (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) \n" + let proc = "CREATE OR REPLACE PROCEDURE nodb_proc_fetchcursor (p_in IN NUMBER, p_out OUT SYS_REFCURSOR) \n" +
"AS \n" + "AS \n" +
"BEGIN \n" + "BEGIN \n" +
" OPEN p_out FOR \n" + " OPEN p_out FOR \n" +
" SELECT * FROM " + tableName + " WHERE id > p_in; \n" + " SELECT * FROM " + tableName + " WHERE id > p_in; \n" +
"END; "; "END; ";
connection.execute( await connection.execute(proc);
proc,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); });
after(function(done) { after(async function() {
async.series([
function(cb) {
let sql = "DROP PROCEDURE nodb_proc_fetchcursor"; let sql = "DROP PROCEDURE nodb_proc_fetchcursor";
connection.execute( await connection.execute(sql);
sql,
function(err) { sql = "DROP TABLE " + tableName + " PURGE";
should.not.exist(err); await connection.execute(sql);
cb();
} await connection.close();
);
},
function(cb) {
let sql = "DROP TABLE " + tableName + " PURGE";
connection.execute(
sql,
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.close(function(err) {
should.not.exist(err);
cb();
});
},
function restoreSettings(cb) {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
cb();
}
], done);
}); });
it('139.1 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) { it('139.1 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
connection.execute( let result = await connection.execute(
"begin nodb_proc_fetchcursor(:in, :out); end;", "begin nodb_proc_fetchcursor(:in, :out); end;",
{ {
in: 290, in: 290,
@ -166,63 +112,48 @@ describe('139. fetchAsStringWithRefCursor.js', function() {
"ID": { type: oracledb.STRING }, "ID": { type: oracledb.STRING },
"HIREDATE": { type: oracledb.STRING } "HIREDATE": { type: oracledb.STRING }
} }
},
function(err, result) {
should.not.exist(err);
fetchRowFromRC(result.outBinds.out, done);
} }
); );
var fetchRowFromRC = function(rc, callback) { const fetchRowFromRC = async function(rc) {
rc.getRow(function(err, row) { const row = await rc.getRow();
should.not.exist(err);
if (row) { if (row) {
(row.ID).should.be.a.String(); assert.strictEqual(typeof row.ID, "string");
(row.HIREDATE).should.be.a.String(); assert.strictEqual(typeof row.HIREDATE, "string");
return fetchRowFromRC(rc, callback); return await fetchRowFromRC(rc);
} else { } else {
rc.close(function(err) { await rc.close();
should.not.exist(err);
callback();
});
} }
});
}; // fetchRowFromRC() }; // fetchRowFromRC()
await fetchRowFromRC(result.outBinds.out);
}); // 139.1 }); // 139.1
it('139.2 fetchAsString takes effect as well', function(done) { it('139.2 fetchAsString takes effect as well', async function() {
oracledb.fetchAsString = [ oracledb.DATE ]; oracledb.fetchAsString = [ oracledb.DATE ];
connection.execute( let result = await connection.execute(
"begin nodb_proc_fetchcursor(:in, :out); end;", "begin nodb_proc_fetchcursor(:in, :out); end;",
{ {
in: 295, in: 295,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
}, },
{ outFormat: oracledb.OUT_FORMAT_OBJECT }, { outFormat: oracledb.OUT_FORMAT_OBJECT }
function(err, result) {
should.not.exist(err);
fetchRowFromRC(result.outBinds.out, done);
}
); );
var fetchRowFromRC = function(rc, callback) { const fetchRowFromRC = async function(rc) {
rc.getRow(function(err, row) { const row = await rc.getRow();
should.not.exist(err);
if (row) { if (row) {
(row.ID).should.not.be.a.String(); assert.notStrictEqual(typeof row.ID, "string");
(row.HIREDATE).should.be.a.String(); assert.strictEqual(typeof row.HIREDATE, "string");
return fetchRowFromRC(rc, callback); return await fetchRowFromRC(rc);
} else { } else {
rc.close(function(err) { await rc.close();
should.not.exist(err);
callback();
});
} }
});
}; // fetchRowFromRC() }; // fetchRowFromRC()
await fetchRowFromRC(result.outBinds.out);
}); // 139.2 }); // 139.2
}); });

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,6 @@ const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('88. fetchBlobAsBuffer2.js', function() { describe('88. fetchBlobAsBuffer2.js', function() {
@ -104,8 +103,7 @@ describe('88. fetchBlobAsBuffer2.js', function() {
// compare fetch result // compare fetch result
const compareClientFetchResult = function(resultVal, specialStr, content, contentLength) { const compareClientFetchResult = function(resultVal, specialStr, content, contentLength) {
assert.strictEqual(resultVal.length, contentLength); assert.strictEqual(resultVal.length, contentLength);
const compareBuffer = assist.compare2Buffers(resultVal, content); assert.deepStrictEqual(resultVal, content);
assert.strictEqual(compareBuffer, true);
}; };
describe('88.1 fetch BLOB columns by setting fetchInfo option', function() { describe('88.1 fetch BLOB columns by setting fetchInfo option', function() {

View File

@ -33,8 +33,7 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const async = require('async'); const assert = require('assert');
const should = require('should');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js'); const assist = require('./dataTypeAssist.js');
@ -42,9 +41,9 @@ const assist = require('./dataTypeAssist.js');
describe('89. fetchBlobAsBuffer3.js', function() { describe('89. fetchBlobAsBuffer3.js', function() {
let connection = null; let connection = null;
var insertID = 1; // assume id for insert into db starts from 1 let insertID = 1; // assume id for insert into db starts from 1
var proc_create_table2 = "BEGIN \n" + const proc_create_table2 = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -62,181 +61,96 @@ describe('89. fetchBlobAsBuffer3.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
var drop_table2 = "DROP TABLE nodb_blob2 PURGE"; const drop_table2 = "DROP TABLE nodb_blob2 PURGE";
var defaultStmtCache = oracledb.stmtCacheSize; const defaultStmtCache = oracledb.stmtCacheSize;
before('get one connection', function(done) { before('get one connection', async function() {
oracledb.stmtCacheSize = 0; oracledb.stmtCacheSize = 0;
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.not.exist(err);
connection = conn;
done();
});
}); // before }); // before
after('release connection', function(done) { after('release connection', async function() {
oracledb.stmtCacheSize = defaultStmtCache; oracledb.stmtCacheSize = defaultStmtCache;
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); // after }); // after
var insertIntoBlobTable2 = function(id, content1, content2, callback) { const insertIntoBlobTable2 = async function(id, content1, content2) {
connection.execute( let result = await connection.execute(
"INSERT INTO nodb_blob2 VALUES (:ID, :B1, :B2)", "INSERT INTO nodb_blob2 VALUES (:ID, :B1, :B2)",
[ id, content1, content2 ], [ id, content1, content2 ]
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 1);
callback();
}
); );
}; assert.strictEqual(result.rowsAffected, 1);
// compare fetch result
var compareClientFetchResult = function(err, resultVal, specialStr, content, contentLength) {
should.not.exist(err);
compareBuffers(resultVal, specialStr, content, contentLength);
};
// compare two buffers
var compareBuffers = function(resultVal, specialStr, content, contentLength) {
should.equal(resultVal.length, contentLength);
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
}; };
describe('89.1 fetch multiple BLOBs', function() { describe('89.1 fetch multiple BLOBs', function() {
before('create Table and populate', function(done) { before('create Table and populate', async function() {
connection.execute( await connection.execute(proc_create_table2);
proc_create_table2,
function(err) {
should.not.exist(err);
done() ;
}
);
}); // before }); // before
after('drop table', function(done) { after('drop table', async function() {
connection.execute( await connection.execute(drop_table2);
drop_table2,
function(err) {
should.not.exist(err);
done();
}
);
}); // after }); // after
beforeEach('set oracledb.fetchAsBuffer', function(done) { beforeEach('set oracledb.fetchAsBuffer', function() {
oracledb.fetchAsBuffer = [ oracledb.BLOB ]; oracledb.fetchAsBuffer = [ oracledb.BLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
done();
}); // afterEach }); // afterEach
it('89.1.1 fetch multiple BLOB columns as Buffer', function(done) { it('89.1.1 fetch multiple BLOB columns as Buffer', async function() {
var id = insertID++; const id = insertID++;
var specialStr_1 = '89.1.1_1'; const specialStr_1 = '89.1.1_1';
var contentLength_1 = 26; const contentLength_1 = 26;
var strBuf_1 = random.getRandomString(contentLength_1, specialStr_1); const strBuf_1 = random.getRandomString(contentLength_1, specialStr_1);
var content_1 = Buffer.from(strBuf_1, "utf-8"); const content_1 = Buffer.from(strBuf_1, "utf-8");
var specialStr_2 = '89.1.1_2'; const specialStr_2 = '89.1.1_2';
var contentLength_2 = 100; const contentLength_2 = 100;
var strBuf_2 = random.getRandomString(contentLength_2, specialStr_2); const strBuf_2 = random.getRandomString(contentLength_2, specialStr_2);
var content_2 = Buffer.from(strBuf_2, "utf-8"); const content_2 = Buffer.from(strBuf_2, "utf-8");
async.series([ await insertIntoBlobTable2(id, content_1, content_2);
function(cb) { const result = await connection.execute(
insertIntoBlobTable2(id, content_1, content_2, cb); "SELECT ID, B1, B2 from nodb_blob2"
},
function(cb) {
connection.execute(
"SELECT ID, B1, B2 from nodb_blob2",
function(err, result) {
should.not.exist(err);
var resultVal = result.rows[0][1];
compareClientFetchResult(err, resultVal, specialStr_1, content_1, contentLength_1);
resultVal = result.rows[0][2];
compareClientFetchResult(err, resultVal, specialStr_2, content_2, contentLength_2);
cb();
}
); );
} assert.deepStrictEqual(result.rows[0][1], content_1);
], done); assert.deepStrictEqual(result.rows[0][2], content_2);
}); // 89.1.1 }); // 89.1.1
it('89.1.2 fetch two BLOB columns, one as string, another streamed', function(done) { it('89.1.2 fetch two BLOB columns, one as string, another streamed', async function() {
var id = insertID++; const id = insertID++;
var specialStr_1 = '89.1.2_1'; const specialStr_1 = '89.1.2_1';
var contentLength_1 = 30; const contentLength_1 = 30;
var strBuf_1 = random.getRandomString(contentLength_1, specialStr_1); const strBuf_1 = random.getRandomString(contentLength_1, specialStr_1);
var content_1 = Buffer.from(strBuf_1, "utf-8"); const content_1 = Buffer.from(strBuf_1, "utf-8");
var specialStr_2 = '89.1.2_2'; const specialStr_2 = '89.1.2_2';
var contentLength_2 = 50; const contentLength_2 = 50;
var strBuf_2 = random.getRandomString(contentLength_2, specialStr_2); const strBuf_2 = random.getRandomString(contentLength_2, specialStr_2);
var content_2 = Buffer.from(strBuf_2, "utf-8"); const content_2 = Buffer.from(strBuf_2, "utf-8");
async.series([ await insertIntoBlobTable2(id, content_1, content_2);
function(cb) {
insertIntoBlobTable2(id, content_1, content_2, cb); let result = await connection.execute(
},
function(cb) {
connection.execute(
"SELECT ID, B1 from nodb_blob2 where ID = :id", "SELECT ID, B1 from nodb_blob2 where ID = :id",
{ id : id }, { id : id }
function(err, result) {
should.not.exist(err);
var resultVal = result.rows[0][1];
compareClientFetchResult(err, resultVal, specialStr_1, content_1, contentLength_1);
cb();
}
); );
}, assert.deepStrictEqual(result.rows[0][1], content_1);
function(cb) {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
connection.execute( result = await connection.execute(
"SELECT B2 from nodb_blob2 where ID = :id", "SELECT B2 from nodb_blob2 where ID = :id",
{ id : id }, { id : id }
function(err, result) {
should.not.exist(err);
(result.rows.length).should.not.eql(0);
var lob = result.rows[0][0];
should.exist(lob);
// set the encoding so we get a 'string' not a 'buffer'
lob.setEncoding('utf8');
var clobData = '';
lob.on('data', function(chunk) {
clobData += chunk;
});
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event.");
});
lob.on('end', function() {
should.not.exist(err);
var specialStrLen_2 = specialStr_2.length;
var resultLen_2 = clobData.length;
should.equal(clobData.length, contentLength_2);
should.strictEqual(clobData.substring(0, specialStrLen_2), specialStr_2);
should.strictEqual(clobData.substring(resultLen_2 - specialStrLen_2, resultLen_2), specialStr_2);
cb();
});
}
); );
} assert.notStrictEqual(result.rows.length, 0);
], done); const clobData = (await result.rows[0][0].getData()).toString();
const specialStrLen_2 = specialStr_2.length;
const resultLen_2 = clobData.length;
assert.strictEqual(clobData.length, contentLength_2);
assert.strictEqual(clobData.substring(0, specialStrLen_2), specialStr_2);
assert.strictEqual(clobData.substring(resultLen_2 - specialStrLen_2, resultLen_2), specialStr_2);
}); // 89.1.2 }); // 89.1.2
@ -244,165 +158,150 @@ describe('89. fetchBlobAsBuffer3.js', function() {
describe('89.2 types support for fetchAsBuffer property', function() { describe('89.2 types support for fetchAsBuffer property', function() {
afterEach ('clear the by-type specification', function(done) { afterEach('clear the by-type specification', function() {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
done ();
}); });
it('89.2.1 String not supported in fetchAsBuffer', function(done) { it('89.2.1 String not supported in fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.STRING ]; oracledb.fetchAsBuffer = [ oracledb.STRING ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 89.2.1 }); // 89.2.1
it('89.2.2 CLOB not supported in fetchAsBuffer', function(done) { it('89.2.2 CLOB not supported in fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.CLOB ]; oracledb.fetchAsBuffer = [ oracledb.CLOB ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 89.2.2 }); // 89.2.2
it('89.2.3 Number not supported in fetchAsBuffer', function(done) { it('89.2.3 Number not supported in fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.NUMBER ]; oracledb.fetchAsBuffer = [ oracledb.NUMBER ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 89.2.3 }); // 89.2.3
it('89.2.4 Date not supported in fetchAsBuffer', function(done) { it('89.2.4 Date not supported in fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.DATE ]; oracledb.fetchAsBuffer = [ oracledb.DATE ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 89.2.4 }); // 89.2.4
it('89.2.5 Cursor not supported in fetchAsBuffer', function(done) { it('89.2.5 Cursor not supported in fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.CURSOR ]; oracledb.fetchAsBuffer = [ oracledb.CURSOR ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 89.2.5 }); // 89.2.5
it('89.2.6 Buffer not supported in fetchAsBuffer', function(done) { it('89.2.6 Buffer not supported in fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.BUFFER ]; oracledb.fetchAsBuffer = [ oracledb.BUFFER ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 89.2.6 }); // 89.2.6
it('89.2.7 BLOB supported in fetchAsBuffer', function(done) { it('89.2.7 BLOB supported in fetchAsBuffer', function() {
should.doesNotThrow( assert.doesNotThrow(
function() { function() {
oracledb.fetchAsBuffer = [ oracledb.BLOB ]; oracledb.fetchAsBuffer = [ oracledb.BLOB ];
} }
); );
should.strictEqual(oracledb.fetchAsBuffer.length, 1); assert.strictEqual(oracledb.fetchAsBuffer.length, 1);
should.strictEqual(oracledb.fetchAsBuffer[0], oracledb.BLOB); assert.strictEqual(oracledb.fetchAsBuffer[0], oracledb.BLOB);
done();
}); // 89.2.7 }); // 89.2.7
it('89.2.8 negative null value for fetchAsBuffer', function(done) { it('89.2.8 negative null value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = null; oracledb.fetchAsBuffer = null;
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.8 }); // 89.2.8
it('89.2.9 negative undefined value for fetchAsBuffer', function(done) { it('89.2.9 negative undefined value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = undefined; oracledb.fetchAsBuffer = undefined;
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.9 }); // 89.2.9
it('89.2.10 negative numeric value for fetchAsBuffer', function(done) { it('89.2.10 negative numeric value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = 89210; oracledb.fetchAsBuffer = 89210;
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.10 }); // 89.2.10
it('89.2.11 negative emtpy string value for fetchAsBuffer', function(done) { it('89.2.11 negative emtpy string value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = ' '; oracledb.fetchAsBuffer = ' ';
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.11 }); // 89.2.11
it('89.2.12 negative arbitary string value for fetchAsBuffer', function(done) { it('89.2.12 negative arbitary string value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsBuffer = "89.2.12"; oracledb.fetchAsBuffer = "89.2.12";
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.12 }); // 89.2.12
it('89.2.13 negative date value for fetchAsBuffer', function(done) { it('89.2.13 negative date value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
var dt = new Date (); let dt = new Date ();
oracledb.fetchAsBuffer = dt; oracledb.fetchAsBuffer = dt;
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.13 }); // 89.2.13
it('89.2.14 negative arbitary buffer value for fetchAsBuffer', function(done) { it('89.2.14 negative arbitary buffer value for fetchAsBuffer', function() {
should.throws( assert.throws(
function() { function() {
var buf = assist.createBuffer (10) ; let buf = assist.createBuffer(10) ;
oracledb.fetchAsBuffer = buf; oracledb.fetchAsBuffer = buf;
}, },
/NJS-004:/ /NJS-004:/
); );
done();
}); // 89.2.14 }); // 89.2.14
}); // 89.2 }); // 89.2

View File

@ -32,17 +32,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('91. fetchBlobAsBuffer4.js', function() { describe('91. fetchBlobAsBuffer4.js', function() {
let connection = null; let connection = null;
var insertID = 1; // assume id for insert into db starts from 1 let insertID = 1; // assume id for insert into db starts from 1
var proc_blob_in_tab = "BEGIN \n" + const proc_blob_in_tab = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -62,662 +60,471 @@ describe('91. fetchBlobAsBuffer4.js', function() {
" '); \n" + " '); \n" +
"END; "; "END; ";
before(function(done) { before(async function() {
async.series([ connection = await oracledb.getConnection(dbConfig);
function(cb) { await connection.execute(proc_blob_in_tab);
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
});
},
function(cb) {
connection.execute(
proc_blob_in_tab,
function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // before }); // before
after(function(done) { after(async function() {
async.series([
function(cb) {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
connection.execute( await connection.execute("DROP TABLE nodb_blob_1 PURGE");
"DROP TABLE nodb_blob_1 PURGE", await connection.close();
function(err) {
should.not.exist(err);
cb();
});
},
function(cb) {
connection.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // after }); // after
var executeSQL = function(sql, callback) { const insertTable = async function(sql, bindVar) {
connection.execute( const result = await connection.execute(sql, bindVar);
sql, assert.strictEqual(result.rowsAffected, 1);
function(err) {
should.not.exist(err);
return callback();
}
);
};
var insertTable = function(sql, bindVar, callback) {
connection.execute(
sql,
bindVar,
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 1);
callback();
}
);
}; };
describe('91.1 PLSQL FUNCTION RETURN BLOB to BUFFER', function() { describe('91.1 PLSQL FUNCTION RETURN BLOB to BUFFER', function() {
beforeEach('set oracledb.fetchAsBuffer', function(done) { beforeEach('set oracledb.fetchAsBuffer', function() {
oracledb.fetchAsBuffer = [ oracledb.BLOB ]; oracledb.fetchAsBuffer = [ oracledb.BLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
done();
}); // afterEach }); // afterEach
it('91.1.1 bind by position - 1', function(done) { it('91.1.1 bind by position - 1', async function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" +
"IS \n" + "IS \n" +
" tmpLOB4 BLOB; \n" + " tmpLOB4 BLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" + " select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB4; \n" + " RETURN tmpLOB4; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :i3); end;"; const sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :i3); end;";
var proc_drop = "DROP FUNCTION nodb_blobs_out_94"; const proc_drop = "DROP FUNCTION nodb_blobs_out_94";
var len = 400; let len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.1.1"; let specialStr = "91.1.1";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, content ], [ { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, content ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
var compareBuffer = assist.compare2Buffers(content, resultVal);
should.strictEqual(compareBuffer, true);
cb();
}
); );
}, let resultVal = result.outBinds[0];
function(cb) { assert.deepStrictEqual(content, resultVal);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.1.1 }); // 91.1.1
it('91.1.2 bind by name - 1', function(done) { it('91.1.2 bind by name - 1', async function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" +
"IS \n" + "IS \n" +
" tmpLOB4 BLOB; \n" + " tmpLOB4 BLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" + " select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB4; \n" + " RETURN tmpLOB4; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :c); end;"; const sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :c); end;";
var proc_drop = "DROP FUNCTION nodb_blobs_out_94"; const proc_drop = "DROP FUNCTION nodb_blobs_out_94";
var len = 400; let len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.1.2"; let specialStr = "91.1.2";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN }, c: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN },
output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
} }
); );
}, let resultVal = result.outBinds.output;
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.1.2 }); // 91.1.2
it('91.1.3 bind by position - 2', function(done) { it('91.1.3 bind by position - 2', async function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" +
"IS \n" + "IS \n" +
" tmpLOB4 BLOB; \n" + " tmpLOB4 BLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" + " select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB4; \n" + " RETURN tmpLOB4; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :c); end;"; const sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :c); end;";
var proc_drop = "DROP FUNCTION nodb_blobs_out_94"; const proc_drop = "DROP FUNCTION nodb_blobs_out_94";
var len = 400; let len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.1.3"; let specialStr = "91.1.3";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null ], [ { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
}
); );
}, let resultVal = result.outBinds[0];
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.1.3 }); // 91.1.3
it('91.1.4 bind by name - 2', function(done) { it('91.1.4 bind by name - 2', async function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN RAW) RETURN BLOB \n" +
"IS \n" + "IS \n" +
" tmpLOB4 BLOB; \n" + " tmpLOB4 BLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" + " select blob into tmpLOB4 from nodb_blob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB4; \n" + " RETURN tmpLOB4; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :c); end;"; const sqlRun = "begin :output := nodb_blobs_out_94 (:i1, :i2, :c); end;";
var proc_drop = "DROP FUNCTION nodb_blobs_out_94"; const proc_drop = "DROP FUNCTION nodb_blobs_out_94";
var len = 400; let len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.1.4"; let specialStr = "91.1.4";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN }, c: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN },
output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
} }
); );
}, let resultVal = result.outBinds.output;
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.1.4 }); // 91.1.4
}); // 91.1 }); // 91.1
describe('91.2 PLSQL PROCEDURE BIND OUT BLOB to BUFFER', function() { describe('91.2 PLSQL PROCEDURE BIND OUT BLOB to BUFFER', function() {
var proc = "CREATE OR REPLACE PROCEDURE nodb_blobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C1 IN RAW, C2 OUT BLOB) \n" + const proc = "CREATE OR REPLACE PROCEDURE nodb_blobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C1 IN RAW, C2 OUT BLOB) \n" +
"AS \n" + "AS \n" +
"BEGIN \n" + "BEGIN \n" +
" select blob into C2 from nodb_blob_1 where num_1 = ID_1;\n" + " select blob into C2 from nodb_blob_1 where num_1 = ID_1;\n" +
"END;"; "END;";
var sqlRun = "begin nodb_blobs_out_92 (:i1, :i2, :c1, :c2); end;"; const sqlRun = "begin nodb_blobs_out_92 (:i1, :i2, :c1, :c2); end;";
var proc_drop = "DROP PROCEDURE nodb_blobs_out_92"; const proc_drop = "DROP PROCEDURE nodb_blobs_out_92";
beforeEach('set oracledb.fetchAsBuffer', function(done) { beforeEach('set oracledb.fetchAsBuffer', function() {
oracledb.fetchAsBuffer = [ oracledb.BLOB ]; oracledb.fetchAsBuffer = [ oracledb.BLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
done();
}); // afterEach }); // afterEach
it('91.2.1 bind by position - 1', function(done) { it('91.2.1 bind by position - 1', async function() {
var len = 500; let len = 500;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.2.1"; let specialStr = "91.2.1";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) { const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
executeSQL(proc, cb); let bindVar = {
},
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ sequence, null, content, { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } ], [ sequence, null, content, { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
}
); );
}, let resultVal = result.outBinds[0];
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.2.1 }); // 91.2.1
it('91.2.2 bind by name - 1', function(done) { it('91.2.2 bind by name - 1', async function() {
var len = 400; let len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.2.2"; let specialStr = "91.2.2";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN },
c2: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } c2: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.c2;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
} }
); );
}, let resultVal = result.outBinds.c2;
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.2.2 }); // 91.2.2
it('91.2.3 bind by position - 2', function(done) { it('91.2.3 bind by position - 2', async function() {
var len = 500; let len = 500;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.2.3"; let specialStr = "91.2.3";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ sequence, sequence, null, { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } ], [ sequence, sequence, null, { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
}
); );
}, let resultVal = result.outBinds[0];
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.2.3 }); // 91.2.3
it('91.2.4 bind by name - 2', function(done) { it('91.2.4 bind by name - 2', async function() {
var len = 400; let len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.2.4"; let specialStr = "91.2.4";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ await connection.execute(proc);
function(cb) {
executeSQL(proc, cb); const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
}, let bindVar = {
function(cb) {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } c2: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.c2;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
} }
); );
}, let resultVal = result.outBinds.c2;
function(cb) { assert.deepStrictEqual(resultVal, content);
executeSQL(proc_drop, cb);
} await connection.execute(proc_drop);
], done);
}); // 91.2.4 }); // 91.2.4
}); // 91.2 }); // 91.2
describe('91.3 PLSQL FUNCTION RETURN BLOB to RAW', function() { describe('91.3 PLSQL FUNCTION RETURN BLOB to RAW', function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN VARCHAR2) RETURN RAW \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_blobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN VARCHAR2) RETURN RAW \n" +
"IS \n" + "IS \n" +
" tmpLOB2 BLOB; \n" + " tmpLOB2 BLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select blob into tmpLOB2 from nodb_blob_1 where num_1 = ID_1;\n" + " select blob into tmpLOB2 from nodb_blob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB2; \n" + " RETURN tmpLOB2; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_blobs_out_92 (:i1, :i2, :c); end;"; const sqlRun = "begin :output := nodb_blobs_out_92 (:i1, :i2, :c); end;";
var proc_drop = "DROP FUNCTION nodb_blobs_out_92"; const proc_drop = "DROP FUNCTION nodb_blobs_out_92";
before(function(done) { before(async function() {
executeSQL(proc, done); await connection.execute(proc);
}); // before }); // before
after(function(done) { after(async function() {
executeSQL(proc_drop, done); await connection.execute(proc_drop);
}); // after }); // after
beforeEach('set oracledb.fetchAsBuffer', function(done) { beforeEach('set oracledb.fetchAsBuffer', function() {
oracledb.fetchAsBuffer = [ oracledb.BLOB ]; oracledb.fetchAsBuffer = [ oracledb.BLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsBuffer = []; oracledb.fetchAsBuffer = [];
done();
}); // afterEach }); // afterEach
it('91.3.1 bind by name - 1', function(done) { it('91.3.1 bind by name - 1', async function() {
var len = 1000; let len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.3.1"; let specialStr = "91.3.1";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN }, c: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN },
output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
} }
); );
} let resultVal = result.outBinds.output;
], done); assert.deepStrictEqual(resultVal, content);
}); // 91.3.1 }); // 91.3.1
it('91.3.2 bind by position - 1', function(done) { it('91.3.2 bind by position - 1', async function() {
var len = 1000; let len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.3.2"; let specialStr = "91.3.2";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ [
{ type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, content { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, content
], ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); assert.deepStrictEqual(resultVal, content);
}); // 91.3.2 }); // 91.3.2
it('91.3.3 bind by name - 2', function(done) { it('91.3.3 bind by name - 2', async function() {
var len = 1000; let len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.3.3"; let specialStr = "91.3.3";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN }, c: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN },
output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
} }
); );
} let resultVal = result.outBinds.output;
], done); assert.deepStrictEqual(resultVal, content);
}); // 91.3.3 }); // 91.3.3
it('91.3.4 bind by position - 2', function(done) { it('91.3.4 bind by position - 2', async function() {
var len = 1000; let len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "91.3.4"; let specialStr = "91.3.4";
var strBuf = random.getRandomString(len, specialStr); let strBuf = random.getRandomString(len, specialStr);
var content = Buffer.from(strBuf, "utf-8"); let content = Buffer.from(strBuf, "utf-8");
async.series([ const sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_blob_1 (num_1, num_2, content, blob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len } c2: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ [
{ type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null
], ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); assert.deepStrictEqual(resultVal, content);
}); // 91.3.4 }); // 91.3.4
}); // 91.3 }); // 91.3

View File

@ -109,7 +109,7 @@ describe('85. fetchClobAsString2.js', function() {
const compareStrings = function(resultVal, specialStr, content, contentLength) { const compareStrings = function(resultVal, specialStr, content, contentLength) {
let specialStrLen = specialStr.length; let specialStrLen = specialStr.length;
let resultLen = resultVal.length; let resultLen = resultVal.length;
assert.equal(resultLen, contentLength); assert.strictEqual(resultLen, contentLength);
assert.strictEqual(resultVal.substring(0, specialStrLen), specialStr); assert.strictEqual(resultVal.substring(0, specialStrLen), specialStr);
assert.strictEqual(resultVal.substring(resultLen - specialStrLen, resultLen), specialStr); assert.strictEqual(resultVal.substring(resultLen - specialStrLen, resultLen), specialStr);
}; };
@ -137,7 +137,7 @@ describe('85. fetchClobAsString2.js', function() {
); );
let resultVal = result.rows[0][1]; let resultVal = result.rows[0][1];
if (specialStr === null) { if (specialStr === null) {
assert.equal(resultVal, null); assert.strictEqual(resultVal, null);
} else { } else {
compareStrings(resultVal, specialStr, insertContent, insertContentLength); compareStrings(resultVal, specialStr, insertContent, insertContentLength);
} }
@ -543,7 +543,7 @@ describe('85. fetchClobAsString2.js', function() {
); );
let resultVal = result.rows[0].C; let resultVal = result.rows[0].C;
if (specialStr === null) { if (specialStr === null) {
assert.equal(resultVal, null); assert.strictEqual(resultVal, null);
} else { } else {
compareStrings(resultVal, specialStr, insertContent, insertContentLength); compareStrings(resultVal, specialStr, insertContent, insertContentLength);
} }
@ -824,7 +824,7 @@ describe('85. fetchClobAsString2.js', function() {
let resultVal = row.C; let resultVal = row.C;
if (specialStr === null) { if (specialStr === null) {
assert.equal(resultVal, null); assert.strictEqual(resultVal, null);
} else { } else {
compareStrings(resultVal, specialStr, insertContent, insertContentLength); compareStrings(resultVal, specialStr, insertContent, insertContentLength);
} }
@ -1092,7 +1092,7 @@ describe('85. fetchClobAsString2.js', function() {
); );
let resultVal = result.rows[0][1]; let resultVal = result.rows[0][1];
if (specialStr === null) { if (specialStr === null) {
assert.equal(resultVal, null); assert.strictEqual(resultVal, null);
} else { } else {
compareStrings(resultVal, specialStr, insertContent, insertContentLength); compareStrings(resultVal, specialStr, insertContent, insertContentLength);
} }
@ -1370,7 +1370,7 @@ describe('85. fetchClobAsString2.js', function() {
let resultVal = row[1]; let resultVal = row[1];
if (specialStr === null) { if (specialStr === null) {
assert.equal(resultVal, null); assert.strictEqual(resultVal, null);
} else { } else {
compareStrings(resultVal, specialStr, insertContent, insertContentLength); compareStrings(resultVal, specialStr, insertContent, insertContentLength);
} }

View File

@ -34,16 +34,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const async = require('async'); const assert = require('assert');
const should = require('should');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
describe('86. fetchClobAsString3.js', function() { describe('86. fetchClobAsString3.js', function() {
let connection = null; let connection = null;
var insertID = 1; // assume id for insert into db starts from 1 let insertID = 1; // assume id for insert into db starts from 1
var proc_create_table2 = "BEGIN \n" + const proc_create_table2 = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -61,330 +60,234 @@ describe('86. fetchClobAsString3.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
var drop_table2 = "DROP TABLE nodb_clob2 PURGE"; const drop_table2 = "DROP TABLE nodb_clob2 PURGE";
var defaultStmtCache = oracledb.stmtCacheSize; let defaultStmtCache = oracledb.stmtCacheSize;
before('get one connection', function(done) { before('get one connection', async function() {
oracledb.stmtCacheSize = 0; oracledb.stmtCacheSize = 0;
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.not.exist(err);
connection = conn;
done();
});
}); // before }); // before
after('release connection', function(done) { after('release connection', async function() {
oracledb.stmtCacheSize = defaultStmtCache; oracledb.stmtCacheSize = defaultStmtCache;
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); // after }); // after
var insertIntoClobTable2 = function(id, content1, content2, callback) { const insertIntoClobTable2 = async function(id, content1, content2) {
connection.execute( let result = await connection.execute(
"INSERT INTO nodb_clob2 VALUES (:ID, :C1, :C2)", "INSERT INTO nodb_clob2 VALUES (:ID, :C1, :C2)",
[ id, content1, content2 ], [ id, content1, content2 ]
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 1);
callback();
}
); );
assert.strictEqual(result.rowsAffected, 1);
}; };
describe('86.1 fetch multiple CLOBs and result set', function() { describe('86.1 fetch multiple CLOBs and result set', function() {
before('create Table and populate', function(done) { before('create Table and populate', async function() {
connection.execute( await connection.execute(proc_create_table2);
proc_create_table2,
function(err) {
should.not.exist(err);
done() ;
}
);
}); // before }); // before
after('drop table', function(done) { after('drop table', async function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
connection.execute( await connection.execute(drop_table2);
drop_table2,
function(err) {
should.not.exist(err);
done();
}
);
}); // after }); // after
beforeEach('set oracledb.fetchAsString', function(done) { beforeEach('set oracledb.fetchAsString', function() {
oracledb.fetchAsString = [ oracledb.CLOB ]; oracledb.fetchAsString = [ oracledb.CLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
done();
}); // afterEach }); // afterEach
it('86.1.1 fetch multiple CLOB columns as String', function(done) { it('86.1.1 fetch multiple CLOB columns as String', async function() {
var id = insertID++; let id = insertID++;
var specialStr_1 = '86.1.1_1'; let specialStr_1 = '86.1.1_1';
var contentLength_1 = 26; const contentLength_1 = 26;
var content_1 = random.getRandomString(contentLength_1, specialStr_1); let content_1 = random.getRandomString(contentLength_1, specialStr_1);
var specialStr_2 = '86.1.1_2'; let specialStr_2 = '86.1.1_2';
var contentLength_2 = 100; const contentLength_2 = 100;
var content_2 = random.getRandomString(contentLength_2, specialStr_2); let content_2 = random.getRandomString(contentLength_2, specialStr_2);
async.series([ await insertIntoClobTable2(id, content_1, content_2);
function(cb) {
insertIntoClobTable2(id, content_1, content_2, cb);
},
function(cb) {
connection.execute(
"SELECT ID, C1, C2 from nodb_clob2",
function(err, result) {
should.not.exist(err);
var specialStrLen_1 = specialStr_1.length;
var resultLen_1 = result.rows[0][1].length;
should.equal(result.rows[0][1].length, contentLength_1);
should.strictEqual(result.rows[0][1].substring(0, specialStrLen_1), specialStr_1);
should.strictEqual(result.rows[0][1].substring(resultLen_1 - specialStrLen_1, resultLen_1), specialStr_1);
var specialStrLen_2 = specialStr_2.length; let result = await connection.execute("SELECT ID, C1, C2 from nodb_clob2");
var resultLen_2 = result.rows[0][2].length; let specialStrLen_1 = specialStr_1.length;
should.equal(result.rows[0][2].length, contentLength_2); let resultLen_1 = result.rows[0][1].length;
should.strictEqual(result.rows[0][2].substring(0, specialStrLen_2), specialStr_2); assert.strictEqual(result.rows[0][1].length, contentLength_1);
should.strictEqual(result.rows[0][2].substring(resultLen_2 - specialStrLen_2, resultLen_2), specialStr_2); assert.strictEqual(result.rows[0][1].substring(0, specialStrLen_1), specialStr_1);
cb(); assert.strictEqual(result.rows[0][1].substring(resultLen_1 - specialStrLen_1, resultLen_1), specialStr_1);
}
);
}
], done);
let specialStrLen_2 = specialStr_2.length;
let resultLen_2 = result.rows[0][2].length;
assert.strictEqual(result.rows[0][2].length, contentLength_2);
assert.strictEqual(result.rows[0][2].substring(0, specialStrLen_2), specialStr_2);
assert.strictEqual(result.rows[0][2].substring(resultLen_2 - specialStrLen_2, resultLen_2), specialStr_2);
}); // 86.1.1 }); // 86.1.1
it('86.1.2 fetch two CLOB columns, one as string, another streamed', function(done) { it('86.1.2 fetch two CLOB columns, one as string, another streamed', async function() {
var id = insertID++; let id = insertID++;
var specialStr_1 = '86.1.2_1'; const specialStr_1 = '86.1.2_1';
var contentLength_1 = 30; const contentLength_1 = 30;
var content_1 = random.getRandomString(contentLength_1, specialStr_1); let content_1 = random.getRandomString(contentLength_1, specialStr_1);
var specialStr_2 = '86.1.2_2'; const specialStr_2 = '86.1.2_2';
var contentLength_2 = 50; const contentLength_2 = 50;
var content_2 = random.getRandomString(contentLength_2, specialStr_2); let content_2 = random.getRandomString(contentLength_2, specialStr_2);
async.series([ await insertIntoClobTable2(id, content_1, content_2);
function(cb) {
insertIntoClobTable2(id, content_1, content_2, cb); let result = await connection.execute(
},
function(cb) {
connection.execute(
"SELECT ID, C1 from nodb_clob2 where ID = :id", "SELECT ID, C1 from nodb_clob2 where ID = :id",
{ id: id }, { id: id }
function(err, result) {
should.not.exist(err);
var specialStrLen_1 = specialStr_1.length;
var resultLen_1 = result.rows[0][1].length;
should.equal(result.rows[0][1].length, contentLength_1);
should.strictEqual(result.rows[0][1].substring(0, specialStrLen_1), specialStr_1);
should.strictEqual(result.rows[0][1].substring(resultLen_1 - specialStrLen_1, resultLen_1), specialStr_1);
cb();
}
); );
}, let specialStrLen_1 = specialStr_1.length;
function(cb) { let resultLen_1 = result.rows[0][1].length;
assert.strictEqual(result.rows[0][1].length, contentLength_1);
assert.strictEqual(result.rows[0][1].substring(0, specialStrLen_1), specialStr_1);
assert.strictEqual(result.rows[0][1].substring(resultLen_1 - specialStrLen_1, resultLen_1), specialStr_1);
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
result = await connection.execute(
connection.execute(
"SELECT C2 from nodb_clob2 where ID = :id", "SELECT C2 from nodb_clob2 where ID = :id",
{ id: id }, { id: id }
function(err, result) { );
should.not.exist(err); assert.notStrictEqual(result.rows.length, 0);
(result.rows.length).should.not.eql(0);
var lob = result.rows[0][0];
should.exist(lob);
let lob = result.rows[0][0];
assert(lob);
// set the encoding so we get a 'string' not a 'String' // set the encoding so we get a 'string' not a 'String'
lob.setEncoding('utf8'); lob.setEncoding('utf8');
var clobData = ''; let clobData = await lob.getData();
let specialStrLen_2 = specialStr_2.length;
lob.on('data', function(chunk) { let resultLen_2 = clobData.length;
clobData += chunk; assert.strictEqual(clobData.length, contentLength_2);
}); assert.strictEqual(clobData.substring(0, specialStrLen_2), specialStr_2);
assert.strictEqual(clobData.substring(resultLen_2 - specialStrLen_2, resultLen_2), specialStr_2);
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event.");
});
lob.on('end', function() {
should.not.exist(err);
var specialStrLen_2 = specialStr_2.length;
var resultLen_2 = clobData.length;
should.equal(clobData.length, contentLength_2);
should.strictEqual(clobData.substring(0, specialStrLen_2), specialStr_2);
should.strictEqual(clobData.substring(resultLen_2 - specialStrLen_2, resultLen_2), specialStr_2);
cb();
});
}
);
}
], done);
}); // 86.1.2 }); // 86.1.2
it('86.1.3 works with Restult Set', function(done) { it('86.1.3 works with Restult Set', async function() {
var id = insertID++; let id = insertID++;
var specialStr_1 = '86.1.3'; let specialStr_1 = '86.1.3';
var contentLength_1 = 387; let contentLength_1 = 387;
var content_1 = random.getRandomString(contentLength_1, specialStr_1); let content_1 = random.getRandomString(contentLength_1, specialStr_1);
async.series([ let doClose = async function(rs) {
function(cb) { await rs.close();
var sql = "insert into nodb_clob2(id, c1) values (:i, :c)"; };
connection.execute(
let fetchOneRowFromRS = async function(rs) {
let row = await rs.getRow();
if (!row) {
await doClose(rs);
} else {
let specialStrLen_1 = specialStr_1.length;
let resultLen_1 = row[0].length;
assert.strictEqual(row[0].length, contentLength_1);
assert.strictEqual(
row[0].substring(0, specialStrLen_1),
specialStr_1
);
assert.strictEqual(
row[0].substring(resultLen_1 - specialStrLen_1, resultLen_1),
specialStr_1
);
await fetchOneRowFromRS(rs);
}
};
let sql = "insert into nodb_clob2(id, c1) values (:i, :c)";
await connection.execute(
sql, sql,
{ {
i: id, i: id,
c: content_1 c: content_1
},
function(err) {
should.not.exist(err);
cb();
} }
); );
},
function(cb) { let result = await connection.execute(
connection.execute(
"select c1 from nodb_clob2 where id = :1", "select c1 from nodb_clob2 where id = :1",
[id], [id],
{ resultSet: true }, { resultSet: true }
function(err, result) {
should.not.exist(err);
fetchOneRowFromRS(result.resultSet, cb);
}
); );
} await fetchOneRowFromRS(result.resultSet);
], done);
var fetchOneRowFromRS = function(rs, callback) {
rs.getRow(
function(err, row) {
if (err) {
should.not.exist(err);
doClose(rs, callback);
} else if (!row) {
doClose(rs, callback);
} else {
var specialStrLen_1 = specialStr_1.length;
var resultLen_1 = row[0].length;
should.equal(row[0].length, contentLength_1);
should.strictEqual(
row[0].substring(0, specialStrLen_1),
specialStr_1
);
should.strictEqual(
row[0].substring(resultLen_1 - specialStrLen_1, resultLen_1),
specialStr_1
);
fetchOneRowFromRS(rs, callback);
}
}
);
};
var doClose = function(rs, callback) {
rs.close(function(err) {
should.not.exist(err);
callback();
});
};
}); // 86.1.3 }); // 86.1.3
}); // 86.1 }); // 86.1
describe('86.2 types support for fetchAsString property', function() { describe('86.2 types support for fetchAsString property', function() {
afterEach ('clear the by-type specification', function(done) { afterEach ('clear the by-type specification', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
done ();
}); });
it('86.2.1 String not supported in fetchAsString', function(done) { it('86.2.1 String not supported in fetchAsString', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ oracledb.STRING ]; oracledb.fetchAsString = [ oracledb.STRING ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 86.2.1 }); // 86.2.1
it('86.2.2 BLOB not supported in fetchAsString', function(done) { it('86.2.2 BLOB not supported in fetchAsString', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ oracledb.BLOB ]; oracledb.fetchAsString = [ oracledb.BLOB ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 86.2.2 }); // 86.2.2
it('86.2.3 Cursor not supported in fetchAsString', function(done) { it('86.2.3 Cursor not supported in fetchAsString', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ oracledb.CURSOR ]; oracledb.fetchAsString = [ oracledb.CURSOR ];
}, },
/NJS-021: invalid type for conversion specified/ /NJS-021: invalid type for conversion specified/
); );
done();
}); // 86.2.3 }); // 86.2.3
it('86.2.4 Buffer supported in fetchAsString', function(done) { it('86.2.4 Buffer supported in fetchAsString', function() {
should.doesNotThrow( assert.doesNotThrow(
function() { function() {
oracledb.fetchAsString = [ oracledb.BUFFER ]; oracledb.fetchAsString = [ oracledb.BUFFER ];
} }
); );
should.strictEqual(oracledb.fetchAsString.length, 1); assert.strictEqual(oracledb.fetchAsString.length, 1);
should.strictEqual(oracledb.fetchAsString[0], oracledb.BUFFER); assert.strictEqual(oracledb.fetchAsString[0], oracledb.BUFFER);
done();
}); // 86.2.4 }); // 86.2.4
it('86.2.5 Number supported in fetchAsString', function(done) { it('86.2.5 Number supported in fetchAsString', function() {
should.doesNotThrow( assert.doesNotThrow(
function() { function() {
oracledb.fetchAsString = [ oracledb.NUMBER ]; oracledb.fetchAsString = [ oracledb.NUMBER ];
} }
); );
should.strictEqual(oracledb.fetchAsString.length, 1); assert.strictEqual(oracledb.fetchAsString.length, 1);
should.strictEqual(oracledb.fetchAsString[0], oracledb.NUMBER); assert.strictEqual(oracledb.fetchAsString[0], oracledb.NUMBER);
done();
}); // 86.2.5 }); // 86.2.5
it('86.2.6 Date supported in fetchAsString', function(done) { it('86.2.6 Date supported in fetchAsString', function() {
should.doesNotThrow( assert.doesNotThrow(
function() { function() {
oracledb.fetchAsString = [ oracledb.DATE ]; oracledb.fetchAsString = [ oracledb.DATE ];
} }
); );
should.strictEqual(oracledb.fetchAsString.length, 1); assert.strictEqual(oracledb.fetchAsString.length, 1);
should.strictEqual(oracledb.fetchAsString[0], oracledb.DATE); assert.strictEqual(oracledb.fetchAsString[0], oracledb.DATE);
done();
}); // 86.2.6 }); // 86.2.6
it('86.2.7 CLOB supported in fetchAsString', function(done) { it('86.2.7 CLOB supported in fetchAsString', function() {
should.doesNotThrow( assert.doesNotThrow(
function() { function() {
oracledb.fetchAsString = [ oracledb.CLOB ]; oracledb.fetchAsString = [ oracledb.CLOB ];
} }
); );
should.strictEqual(oracledb.fetchAsString.length, 1); assert.strictEqual(oracledb.fetchAsString.length, 1);
should.strictEqual(oracledb.fetchAsString[0], oracledb.CLOB); assert.strictEqual(oracledb.fetchAsString[0], oracledb.CLOB);
done();
}); // 86.2.7 }); // 86.2.7
it('86.2.8 undefined in fetchAsString will throw NJS-021', function() { it('86.2.8 undefined in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ undefined ]; oracledb.fetchAsString = [ undefined ];
}, },
@ -393,7 +296,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.8 }); // 86.2.8
it('86.2.9 Random string in fetchAsString will throw NJS-021', function() { it('86.2.9 Random string in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ "foobar" ]; oracledb.fetchAsString = [ "foobar" ];
}, },
@ -402,7 +305,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.9 }); // 86.2.9
it('86.2.10 Random integer in fetchAsString will throw NJS-021', function() { it('86.2.10 Random integer in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ 31415 ]; oracledb.fetchAsString = [ 31415 ];
}, },
@ -411,7 +314,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.10 }); // 86.2.10
it('86.2.11 Negative integer in fetchAsString will throw NJS-021', function() { it('86.2.11 Negative integer in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ -1 ]; oracledb.fetchAsString = [ -1 ];
}, },
@ -420,7 +323,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.11 }); // 86.2.11
it('86.2.12 Random float in fetchAsString will throw NJS-021', function() { it('86.2.12 Random float in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ 3.1415 ]; oracledb.fetchAsString = [ 3.1415 ];
}, },
@ -429,7 +332,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.12 }); // 86.2.12
it('86.2.13 Array in fetchAsString will throw NJS-021', function() { it('86.2.13 Array in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ [3] ]; oracledb.fetchAsString = [ [3] ];
}, },
@ -438,7 +341,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.13 }); // 86.2.13
it('86.2.14 Object in fetchAsString will throw NJS-021', function() { it('86.2.14 Object in fetchAsString will throw NJS-021', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = [ {1:1} ]; oracledb.fetchAsString = [ {1:1} ];
}, },
@ -447,7 +350,7 @@ describe('86. fetchClobAsString3.js', function() {
}); // 86.2.14 }); // 86.2.14
it('86.2.15 Non-Array as fetchAsString will throw NJS-004', function() { it('86.2.15 Non-Array as fetchAsString will throw NJS-004', function() {
should.throws( assert.throws(
function() { function() {
oracledb.fetchAsString = 1; oracledb.fetchAsString = 1;
}, },

View File

@ -32,16 +32,15 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
describe('90. fetchClobAsString4.js', function() { describe('90. fetchClobAsString4.js', function() {
let connection = null; let connection = null;
var insertID = 1; // assume id for insert into db starts from 1 let insertID = 1; // assume id for insert into db starts from 1
var proc_clob_in_tab = "BEGIN \n" + const proc_clob_in_tab = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -61,579 +60,416 @@ describe('90. fetchClobAsString4.js', function() {
" '); \n" + " '); \n" +
"END; "; "END; ";
before(function(done) { before(async function() {
async.series([ connection = await oracledb.getConnection(dbConfig);
function(cb) { await connection.execute(proc_clob_in_tab);
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
});
},
function(cb) {
connection.execute(
proc_clob_in_tab,
function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // before }); // before
after(function(done) { after(async function() {
async.series([
function(cb) {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
connection.execute( await connection.execute("DROP TABLE nodb_clob_1 PURGE");
"DROP TABLE nodb_clob_1 PURGE", await connection.close();
function(err) {
should.not.exist(err);
cb();
});
},
function(cb) {
connection.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // after }); // after
var executeSQL = function(sql, callback) { const insertTable = async function(insertSql, bindVar) {
connection.execute( let result = await connection.execute(insertSql, bindVar);
sql, assert.strictEqual(result.rowsAffected, 1);
function(err) {
should.not.exist(err);
return callback();
}
);
}; };
var insertTable = function(insertSql, bindVar, callback) { let verifyResult = function(resultVal, specialStr, originalStr) {
connection.execute( let resultLength = resultVal.length;
insertSql, let specStrLength = specialStr.length;
bindVar, assert.strictEqual(resultLength, originalStr.length);
function(err, result) { assert.strictEqual(resultVal.substring(0, specStrLength), specialStr);
should.not.exist(err); assert.strictEqual(resultVal.substring(resultLength - specStrLength, resultLength), specialStr);
should.strictEqual(result.rowsAffected, 1);
callback();
}
);
};
var verifyResult = function(resultVal, specialStr, originalStr) {
var resultLength = resultVal.length;
var specStrLength = specialStr.length;
should.strictEqual(resultLength, originalStr.length);
should.strictEqual(resultVal.substring(0, specStrLength), specialStr);
should.strictEqual(resultVal.substring(resultLength - specStrLength, resultLength), specialStr);
}; };
describe('90.1 PLSQL FUNCTION RETURN CLOB to STRING', function() { describe('90.1 PLSQL FUNCTION RETURN CLOB to STRING', function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_clobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN VARCHAR2) RETURN CLOB \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_clobs_out_94 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN VARCHAR2) RETURN CLOB \n" +
"IS \n" + "IS \n" +
" tmpLOB4 CLOB; \n" + " tmpLOB4 CLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select clob into tmpLOB4 from nodb_clob_1 where num_1 = ID_1;\n" + " select clob into tmpLOB4 from nodb_clob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB4; \n" + " RETURN tmpLOB4; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_clobs_out_94 (:i1, :i2, :c); end;"; const sqlRun = "begin :output := nodb_clobs_out_94 (:i1, :i2, :c); end;";
var proc_drop = "DROP FUNCTION nodb_clobs_out_94"; const proc_drop = "DROP FUNCTION nodb_clobs_out_94";
before(function(done) { before(async function() {
executeSQL(proc, done); await connection.execute(proc);
}); });
after(function(done) { after(async function() {
executeSQL(proc_drop, done); await connection.execute(proc_drop);
}); });
beforeEach('set oracledb.fetchAsString', function(done) { beforeEach('set oracledb.fetchAsString', function() {
oracledb.fetchAsString = [ oracledb.CLOB ]; oracledb.fetchAsString = [ oracledb.CLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
done();
}); // afterEach }); // afterEach
it('90.1.1 bind by position - 1', function(done) { it('90.1.1 bind by position - 1', async function() {
var len = 400; const len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.1.1"; const specialStr = "90.1.1";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, clobStr], [ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, clobStr]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
verifyResult(resultVal, specialStr, clobStr);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.1.1 }); // 90.1.1
it('90.1.2 bind by name - 1', function(done) { it('90.1.2 bind by name - 1', async function() {
var len = 400; const len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.1.2"; const specialStr = "90.1.2";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
}, let result = await connection.execute(
function(cb) {
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN }, c: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN },
output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
verifyResult(resultVal, specialStr, clobStr);
cb();
} }
); );
} let resultVal = result.outBinds.output;
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.1.2 }); // 90.1.2
it('90.1.3 bind by position - 2', function(done) { it('90.1.3 bind by position - 2', async function() {
var len = 400; const len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.1.2"; const specialStr = "90.1.2";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null ], [ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
verifyResult(resultVal, specialStr, clobStr);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.1.3 }); // 90.1.3
it('90.1.4 bind by name - 2', function(done) { it('90.1.4 bind by name - 2', async function() {
var len = 400; const len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.1.4"; const specialStr = "90.1.4";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: null, type: oracledb.STRING, dir: oracledb.BIND_IN }, c: { val: null, type: oracledb.STRING, dir: oracledb.BIND_IN },
output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
verifyResult(resultVal, specialStr, clobStr);
cb();
} }
); );
} let resultVal = result.outBinds.output;
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.1.4 }); // 90.1.4
}); // 90.1 }); // 90.1
describe('90.2 PLSQL PROCEDURE BIND OUT CLOB to STRING', function() { describe('90.2 PLSQL PROCEDURE BIND OUT CLOB to STRING', function() {
var proc = "CREATE OR REPLACE PROCEDURE nodb_clobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C1 IN VARCHAR2, C2 OUT CLOB) \n" + const proc = "CREATE OR REPLACE PROCEDURE nodb_clobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C1 IN VARCHAR2, C2 OUT CLOB) \n" +
"AS \n" + "AS \n" +
"BEGIN \n" + "BEGIN \n" +
" select clob into C2 from nodb_clob_1 where num_1 = ID_1;\n" + " select clob into C2 from nodb_clob_1 where num_1 = ID_1;\n" +
"END;"; "END;";
var sqlRun = "begin nodb_clobs_out_92 (:i1, :i2, :c1, :c2); end;"; const sqlRun = "begin nodb_clobs_out_92 (:i1, :i2, :c1, :c2); end;";
var proc_drop = "DROP PROCEDURE nodb_clobs_out_92"; const proc_drop = "DROP PROCEDURE nodb_clobs_out_92";
before(function(done) { before(async function() {
executeSQL(proc, done); await connection.execute(proc);
}); });
after(function(done) { after(async function() {
executeSQL(proc_drop, done); await connection.execute(proc_drop);
}); });
beforeEach('set oracledb.fetchAsString', function(done) { beforeEach('set oracledb.fetchAsString', function() {
oracledb.fetchAsString = [ oracledb.CLOB ]; oracledb.fetchAsString = [ oracledb.CLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
done();
}); // afterEach }); // afterEach
it('90.2.1 bind by position - 1', function(done) { it('90.2.1 bind by position - 1', async function() {
var len = 500; const len = 500;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.2.1"; const specialStr = "90.2.1";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ sequence, null, { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN }, { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } ], [ sequence, null, { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN }, { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
verifyResult(resultVal, specialStr, clobStr);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.2.1 }); // 90.2.1
it('90.2.2 bind by name - 1', function(done) { it('90.2.2 bind by name - 1', async function() {
var len = 400; const len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.2.2"; const specialStr = "90.2.2";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN },
c2: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } c2: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.c2;
verifyResult(resultVal, specialStr, clobStr);
cb();
} }
); );
} let resultVal = result.outBinds.c2;
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.2.2 }); // 90.2.2
it('90.2.3 bind by position - 2', function(done) { it('90.2.3 bind by position - 2', async function() {
var len = 500; const len = 500;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.2.3"; const specialStr = "90.2.3";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ sequence, sequence, null, { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } ], [ sequence, sequence, null, { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
verifyResult(resultVal, specialStr, clobStr);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.2.3 }); // 90.2.3
it('90.2.4 bind by name - 2', function(done) { it('90.2.4 bind by name - 2', async function() {
var len = 400; const len = 400;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.2.4"; const specialStr = "90.2.4";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: null, type: oracledb.STRING, dir: oracledb.BIND_IN }, c1: { val: null, type: oracledb.STRING, dir: oracledb.BIND_IN },
c2: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } c2: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.c2;
verifyResult(resultVal, specialStr, clobStr);
cb();
} }
); );
} let resultVal = result.outBinds.c2;
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.2.4 }); // 90.2.4
}); // 90.2 }); // 90.2
describe('90.3 PLSQL FUNCTION RETURN CLOB to VARCHAR2', function() { describe('90.3 PLSQL FUNCTION RETURN CLOB to VARCHAR2', function() {
var proc = "CREATE OR REPLACE FUNCTION nodb_clobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN VARCHAR2) RETURN VARCHAR2 \n" + const proc = "CREATE OR REPLACE FUNCTION nodb_clobs_out_92 (ID_1 IN NUMBER, ID_2 IN NUMBER, C IN VARCHAR2) RETURN VARCHAR2 \n" +
"IS \n" + "IS \n" +
" tmpLOB2 CLOB; \n" + " tmpLOB2 CLOB; \n" +
"BEGIN \n" + "BEGIN \n" +
" select clob into tmpLOB2 from nodb_clob_1 where num_1 = ID_1;\n" + " select clob into tmpLOB2 from nodb_clob_1 where num_1 = ID_1;\n" +
" RETURN tmpLOB2; \n" + " RETURN tmpLOB2; \n" +
"END;"; "END;";
var sqlRun = "begin :output := nodb_clobs_out_92 (:i1, :i2, :c); end;"; const sqlRun = "begin :output := nodb_clobs_out_92 (:i1, :i2, :c); end;";
var proc_drop = "DROP FUNCTION nodb_clobs_out_92"; const proc_drop = "DROP FUNCTION nodb_clobs_out_92";
before(function(done) { before(async function() {
executeSQL(proc, done); await connection.execute(proc);
}); // before }); // before
after(function(done) { after(async function() {
executeSQL(proc_drop, done); await connection.execute(proc_drop);
}); // after }); // after
beforeEach('set oracledb.fetchAsString', function(done) { beforeEach('set oracledb.fetchAsString', function() {
oracledb.fetchAsString = [ oracledb.CLOB ]; oracledb.fetchAsString = [ oracledb.CLOB ];
done();
}); // beforeEach }); // beforeEach
afterEach('clear the By type specification', function(done) { afterEach('clear the By type specification', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
done();
}); // afterEach }); // afterEach
it('90.3.1 bind by name - 1', function(done) { it('90.3.1 bind by name - 1', async function() {
var len = 1000; const len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.3.1"; const specialStr = "90.3.1";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN }, c: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN },
output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
verifyResult(resultVal, specialStr, clobStr);
cb();
} }
); );
} let resultVal = result.outBinds.output;
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.3.1 }); // 90.3.1
it('90.3.2 bind by position - 1', function(done) { it('90.3.2 bind by position - 1', async function() {
var len = 1000; const len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.3.1"; const specialStr = "90.3.1";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, clobStr ], [ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, null, clobStr ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
verifyResult(resultVal, specialStr, clobStr);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.3.2 }); // 90.3.2
it('90.3.3 bind by name - 2', function(done) { it('90.3.3 bind by name - 2', async function() {
var len = 1000; const len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.3.3"; const specialStr = "90.3.3";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
{ {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: null, type: oracledb.STRING, dir: oracledb.BIND_IN }, c: { val: null, type: oracledb.STRING, dir: oracledb.BIND_IN },
output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len } output: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
verifyResult(resultVal, specialStr, clobStr);
cb();
} }
); );
} let resultVal = result.outBinds.output;
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.3.3 }); // 90.3.3
it('90.3.4 bind by position - 2', function(done) { it('90.3.4 bind by position - 2', async function() {
var len = 1000; const len = 1000;
var sequence = insertID++; let sequence = insertID++;
var specialStr = "90.3.4"; const specialStr = "90.3.4";
var clobStr = random.getRandomString(len, specialStr); let clobStr = random.getRandomString(len, specialStr);
async.series([ let sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
function(cb) { let bindVar = {
var sql = "INSERT INTO nodb_clob_1 (num_1, num_2, content, clob) VALUES (:i1, :i2, :c1, :c2)";
var bindVar = {
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN }, i2: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }, c1: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len },
c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len } c2: { val: clobStr, type: oracledb.STRING, dir: oracledb.BIND_IN, maxSize: len }
}; };
insertTable(sql, bindVar, cb); await insertTable(sql, bindVar);
},
function(cb) { let result = await connection.execute(
connection.execute(
sqlRun, sqlRun,
[ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null ], [ { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: len }, sequence, sequence, null ]
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds[0];
verifyResult(resultVal, specialStr, clobStr);
cb();
}
); );
} let resultVal = result.outBinds[0];
], done); verifyResult(resultVal, specialStr, clobStr);
}); // 90.3.4 }); // 90.3.4
}); // 90.3 }); // 90.3

View File

@ -35,7 +35,6 @@ const oracledb = require('oracledb');
const assert = require('assert'); const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const assist = require('./dataTypeAssist.js');
describe('245. fetchLobAsStrBuf.js', function() { describe('245. fetchLobAsStrBuf.js', function() {
let connection = null; let connection = null;
@ -163,13 +162,13 @@ describe('245. fetchLobAsStrBuf.js', function() {
lob.on('end', function() { lob.on('end', function() {
if (originalBuffer == "EMPTY_BLOB") { if (originalBuffer == "EMPTY_BLOB") {
let nullBuffer = Buffer.from('', "utf-8"); let nullBuffer = Buffer.from('', "utf-8");
assert.strictEqual(assist.compare2Buffers(blobData, nullBuffer), true); assert.deepStrictEqual(blobData, nullBuffer);
} else { } else {
assert.strictEqual(totalLength, originalBuffer.length); assert.strictEqual(totalLength, originalBuffer.length);
let specStrLength = specialStr.length; let specStrLength = specialStr.length;
assert.strictEqual(blobData.toString('utf8', 0, specStrLength), specialStr); assert.strictEqual(blobData.toString('utf8', 0, specStrLength), specialStr);
assert.strictEqual(blobData.toString('utf8', (totalLength - specStrLength), totalLength), specialStr); assert.strictEqual(blobData.toString('utf8', (totalLength - specStrLength), totalLength), specialStr);
assert.strictEqual(assist.compare2Buffers(blobData, originalBuffer), true); assert.deepStrictEqual(blobData, originalBuffer);
} }
resolve(); resolve();
}); });

View File

@ -34,19 +34,18 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const async = require('async'); const assert = require('assert');
const should = require('should');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
describe('116. fetchUrowidAsString.js', function() { describe('116. fetchUrowidAsString.js', function() {
let connection = null; let connection = null;
var tableName = "nodb_rowid"; const tableName = "nodb_rowid";
var dataArray = random.getRandomNumArray(30); let dataArray = random.getRandomNumArray(30);
var numRows = dataArray.length; // number of rows to return from each call to getRows() let numRows = dataArray.length; // number of rows to return from each call to getRows()
var proc_create_table = "BEGIN \n" + const proc_create_table = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n" +
@ -63,621 +62,444 @@ describe('116. fetchUrowidAsString.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
var drop_table = "DROP TABLE " + tableName + " PURGE"; const drop_table = "DROP TABLE " + tableName + " PURGE";
before('get one connection', function(done) { before('get one connection', async function() {
oracledb.getConnection(dbConfig, function(err, conn) { connection = await oracledb.getConnection(dbConfig);
should.not.exist(err);
connection = conn;
done();
});
}); });
after('release connection', function(done) { after('release connection', async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
var insertData = function(connection, tableName, callback) { const insertData = async function(connection, tableName) {
async.eachSeries(dataArray, function(element, cb) { for (let element in dataArray) {
var sql = "INSERT INTO " + tableName + "(num) VALUES(" + element + ")"; const sql = "INSERT INTO " + tableName + "(num) VALUES(" + element + ")";
connection.execute( await connection.execute(sql);
sql,
function(err) {
should.not.exist(err);
cb();
} }
);
}, function(err) {
should.not.exist(err);
callback();
});
}; };
var updateDate = function(connection, tableName, callback) { const updateData = async function(connection, tableName) {
async.eachSeries(dataArray, function(element, cb) { for (let element in dataArray) {
var sql = "UPDATE " + tableName + " T SET content = T.ROWID where num = " + element; const sql = "UPDATE " + tableName + " T SET content = T.ROWID where num = " + element;
connection.execute( await connection.execute(sql);
sql,
function(err) {
should.not.exist(err);
cb();
} }
);
}, function(err) {
should.not.exist(err);
callback();
});
}; };
describe('116.1 works with fetchInfo option', function() { describe('116.1 works with fetchInfo option', function() {
var maxRowBak = oracledb.maxRows; let maxRowBak = oracledb.maxRows;
var option = { fetchInfo: { "CONTENT": { type: oracledb.STRING } } }; let option = { fetchInfo: { "CONTENT": { type: oracledb.STRING } } };
before(function(done) { before(async function() {
async.series([ await connection.execute(proc_create_table);
function makeTable(callback) { await insertData(connection, tableName);
connection.execute( await updateData(connection, tableName);
proc_create_table,
function(err) {
should.not.exist(err);
callback();
}
);
},
function insertRow(callback) {
insertData(connection, tableName, callback);
},
function fillRowid(callback) {
updateDate(connection, tableName, callback);
}
], done);
}); });
after(function(done) { after(async function() {
oracledb.maxRows = maxRowBak; oracledb.maxRows = maxRowBak;
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('116.1.1 fetchInfo', function(done) { it('116.1.1 fetchInfo', async function() {
test1(option, false, false, done); await test1(option, false);
}); });
it('116.1.2 fetchInfo, and oracledb.maxRows < actual number of rows', function(done) { it('116.1.2 fetchInfo, and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.1.3 fetchInfo, and oracledb.maxRows = actual number of rows', function(done) { it('116.1.3 fetchInfo, and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.1.4 fetchInfo, and oracledb.maxRows > actual number of rows', function(done) { it('116.1.4 fetchInfo, and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.1.5 fetchInfo, queryStream() and oracledb.maxRows < actual number of rows', function(done) { it('116.1.5 fetchInfo, queryStream() and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.1.6 fetchInfo, queryStream() and oracledb.maxRows = actual number of rows', function(done) { it('116.1.6 fetchInfo, queryStream() and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.1.7 fetchInfo, queryStream() and oracledb.maxRows > actual number of rows', function(done) { it('116.1.7 fetchInfo, queryStream() and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.1.8 fetchInfo, resultSet = true', function(done) { it('116.1.8 fetchInfo, resultSet = true', async function() {
var option_rs = { let option_rs = {
resultSet: true, resultSet: true,
fetchInfo: { "CONTENT": { type: oracledb.STRING } } fetchInfo: { "CONTENT": { type: oracledb.STRING } }
}; };
test2(option_rs, false, false, done); await test2(option_rs, false);
}); });
}); });
describe('116.2 works with fetchInfo and outFormat = OBJECT', function() { describe('116.2 works with fetchInfo and outFormat = OBJECT', function() {
var maxRowBak = oracledb.maxRows; let maxRowBak = oracledb.maxRows;
var option = { let option = {
outFormat: oracledb.OUT_FORMAT_OBJECT, outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchInfo: { "CONTENT": { type: oracledb.STRING } } fetchInfo: { "CONTENT": { type: oracledb.STRING } }
}; };
before(function(done) { before(async function() {
async.series([ await connection.execute(proc_create_table);
function makeTable(callback) { await insertData(connection, tableName);
connection.execute( await updateData(connection, tableName);
proc_create_table,
function(err) {
should.not.exist(err);
callback();
});
},
function insertRow(callback) {
insertData(connection, tableName, callback);
},
function fillRowid(callback) {
updateDate(connection, tableName, callback);
}
], done);
}); });
after(function(done) { after(async function() {
oracledb.maxRows = maxRowBak; oracledb.maxRows = maxRowBak;
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('116.2.1 fetchInfo with outFormat = OBJECT', function(done) { it('116.2.1 fetchInfo with outFormat = OBJECT', async function() {
test1(option, true, false, done); await test1(option, true);
}); });
it('116.2.2 fetchInfo, outFormat = OBJECT, and resultSet = true', function(done) { it('116.2.2 fetchInfo, outFormat = OBJECT, and resultSet = true', async function() {
var option_rs = { let option_rs = {
resultSet: true, resultSet: true,
outFormat: oracledb.OUT_FORMAT_OBJECT, outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchInfo: { "CONTENT": { type: oracledb.STRING } } fetchInfo: { "CONTENT": { type: oracledb.STRING } }
}; };
test2(option_rs, true, false, done); await test2(option_rs, true);
}); });
it('116.2.3 fetchInfo, outFormat = OBJECT, and oracledb.maxRows < actual number of rows', function(done) { it('116.2.3 fetchInfo, outFormat = OBJECT, and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.2.4 fetchInfo, outFormat = OBJECT, and oracledb.maxRows = actual number of rows', function(done) { it('116.2.4 fetchInfo, outFormat = OBJECT, and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.2.5 fetchInfo, outFormat = OBJECT, and oracledb.maxRows > actual number of rows', function(done) { it('116.2.5 fetchInfo, outFormat = OBJECT, and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.2.6 fetchInfo, outFormat = OBJECT, queryStream() and oracledb.maxRows < actual number of rows', function(done) { it('116.2.6 fetchInfo, outFormat = OBJECT, queryStream() and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.2.7 fetchInfo, outFormat = OBJECT, queryStream() and oracledb.maxRows = actual number of rows', function(done) { it('116.2.7 fetchInfo, outFormat = OBJECT, queryStream() and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.2.8 fetchInfo, outFormat = OBJECT, queryStream() and oracledb.maxRows > actual number of rows', function(done) { it('116.2.8 fetchInfo, outFormat = OBJECT, queryStream() and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
}); });
describe('116.3 works with fetchInfo and outFormat = ARRAY', function() { describe('116.3 works with fetchInfo and outFormat = ARRAY', function() {
var maxRowBak = oracledb.maxRows; let maxRowBak = oracledb.maxRows;
var option = { let option = {
outFormat: oracledb.OUT_FORMAT_ARRAY, outFormat: oracledb.OUT_FORMAT_ARRAY,
fetchInfo: { "CONTENT": { type: oracledb.STRING } } fetchInfo: { "CONTENT": { type: oracledb.STRING } }
}; };
before(function(done) { before(async function() {
async.series([ await connection.execute(proc_create_table);
function makeTable(callback) { await insertData(connection, tableName);
connection.execute( await updateData(connection, tableName);
proc_create_table,
function(err) {
should.not.exist(err);
callback();
});
},
function insertRow(callback) {
insertData(connection, tableName, callback);
},
function fillRowid(callback) {
updateDate(connection, tableName, callback);
}
], done);
}); });
after(function(done) { after(async function() {
oracledb.maxRows = maxRowBak; oracledb.maxRows = maxRowBak;
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('116.3.1 fetchInfo', function(done) { it('116.3.1 fetchInfo', async function() {
test1(option, false, true, done); await test1(option, false);
}); });
it('116.3.2 fetchInfo, and oracledb.maxRows < actual number of rows', function(done) { it('116.3.2 fetchInfo, and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.3.3 fetchInfo, and oracledb.maxRows = actual number of rows', function(done) { it('116.3.3 fetchInfo, and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.3.4 fetchInfo, and oracledb.maxRows > actual number of rows', function(done) { it('116.3.4 fetchInfo, and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.3.5 fetchInfo, queryStream() and oracledb.maxRows < actual number of rows', function(done) { it('116.3.5 fetchInfo, queryStream() and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.3.6 fetchInfo, queryStream() and oracledb.maxRows = actual number of rows', function(done) { it('116.3.6 fetchInfo, queryStream() and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.3.7 fetchInfo, queryStream() and oracledb.maxRows > actual number of rows', function(done) { it('116.3.7 fetchInfo, queryStream() and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.3.8 fetchInfo, resultSet = true', function(done) { it('116.3.8 fetchInfo, resultSet = true', async function() {
var option_rs = { let option_rs = {
resultSet: true, resultSet: true,
outFormat: oracledb.OUT_FORMAT_ARRAY, outFormat: oracledb.OUT_FORMAT_ARRAY,
fetchInfo: { "CONTENT": { type: oracledb.STRING } } fetchInfo: { "CONTENT": { type: oracledb.STRING } }
}; };
test2(option_rs, false, true, done); await test2(option_rs, false);
}); });
}); });
describe('116.4 fetch as string by default', function() { describe('116.4 fetch as string by default', function() {
var maxRowBak = oracledb.maxRows; let maxRowBak = oracledb.maxRows;
var option = {}; let option = {};
before(function(done) { before(async function() {
async.series([ await connection.execute(proc_create_table);
function makeTable(callback) { await insertData(connection, tableName);
connection.execute( await updateData(connection, tableName);
proc_create_table,
function(err) {
should.not.exist(err);
callback();
});
},
function insertRow(callback) {
insertData(connection, tableName, callback);
},
function fillRowid(callback) {
updateDate(connection, tableName, callback);
}
], done);
}); });
after(function(done) { after(async function() {
oracledb.maxRows = maxRowBak; oracledb.maxRows = maxRowBak;
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('116.4.1 fetch by default', function(done) { it('116.4.1 fetch by default', async function() {
test1(option, false, false, done); await test1(option, false);
}); });
it('116.4.2 oracledb.maxRows < actual number of rows', function(done) { it('116.4.2 oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.4.3 oracledb.maxRows = actual number of rows', function(done) { it('116.4.3 oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.4.4 oracledb.maxRows > actual number of rows', function(done) { it('116.4.4 oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.4.5 queryStream() and oracledb.maxRows < actual number of rows', function(done) { it('116.4.5 queryStream() and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.4.6 queryStream() and oracledb.maxRows = actual number of rows', function(done) { it('116.4.6 queryStream() and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.4.7 queryStream() and oracledb.maxRows > actual number of rows', function(done) { it('116.4.7 queryStream() and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.4.8 resultSet = true', function(done) { it('116.4.8 resultSet = true', async function() {
var option_rs = { let option_rs = {
resultSet: true, resultSet: true,
}; };
test2(option_rs, false, false, done); await test2(option_rs, false);
}); });
}); });
describe('116.5 fetch as string by default with outFormat = OBJECT', function() { describe('116.5 fetch as string by default with outFormat = OBJECT', function() {
var maxRowBak = oracledb.maxRows; let maxRowBak = oracledb.maxRows;
var option = { outFormat: oracledb.OUT_FORMAT_OBJECT }; let option = { outFormat: oracledb.OUT_FORMAT_OBJECT };
before(function(done) { before(async function() {
async.series([ await connection.execute(proc_create_table);
function makeTable(callback) { await insertData(connection, tableName);
connection.execute( await updateData(connection, tableName);
proc_create_table,
function(err) {
should.not.exist(err);
callback();
});
},
function insertRow(callback) {
insertData(connection, tableName, callback);
},
function fillRowid(callback) {
updateDate(connection, tableName, callback);
}
], done);
}); });
after(function(done) { after(async function() {
oracledb.maxRows = maxRowBak; oracledb.maxRows = maxRowBak;
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('116.5.1 fetch by default', function(done) { it('116.5.1 fetch by default', async function() {
test1(option, true, false, done); await test1(option, true);
}); });
it('116.5.2 oracledb.maxRows < actual number of rows', function(done) { it('116.5.2 oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.5.3 oracledb.maxRows = actual number of rows', function(done) { it('116.5.3 oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.5.4 oracledb.maxRows > actual number of rows', function(done) { it('116.5.4 oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.5.5 queryStream() and oracledb.maxRows < actual number of rows', function(done) { it('116.5.5 queryStream() and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.5.6 queryStream() and oracledb.maxRows = actual number of rows', function(done) { it('116.5.6 queryStream() and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.5.7 queryStream() and oracledb.maxRows > actual number of rows', function(done) { it('116.5.7 queryStream() and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.5.8 resultSet = true', function(done) { it('116.5.8 resultSet = true', async function() {
var option_rs = { let option_rs = {
resultSet: true, resultSet: true,
outFormat: oracledb.OUT_FORMAT_OBJECT outFormat: oracledb.OUT_FORMAT_OBJECT
}; };
test2(option_rs, true, false, done); await test2(option_rs, true);
}); });
}); });
describe('116.6 fetch as string by default with outFormat = ARRAY', function() { describe('116.6 fetch as string by default with outFormat = ARRAY', function() {
var maxRowBak = oracledb.maxRows; let maxRowBak = oracledb.maxRows;
var option = { outFormat: oracledb.OUT_FORMAT_ARRAY }; let option = { outFormat: oracledb.OUT_FORMAT_ARRAY };
before(function(done) { before(async function() {
async.series([ await connection.execute(proc_create_table);
function makeTable(callback) { await insertData(connection, tableName);
connection.execute( await updateData(connection, tableName);
proc_create_table,
function(err) {
should.not.exist(err);
callback();
});
},
function insertRow(callback) {
insertData(connection, tableName, callback);
},
function fillRowid(callback) {
updateDate(connection, tableName, callback);
}
], done);
}); });
after(function(done) { after(async function() {
oracledb.maxRows = maxRowBak; oracledb.maxRows = maxRowBak;
connection.execute( await connection.execute(drop_table);
drop_table,
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('116.6.1 fetch by default', function(done) { it('116.6.1 fetch by default', async function() {
test1(option, false, true, done); await test1(option, false);
}); });
it('116.6.2 oracledb.maxRows < actual number of rows', function(done) { it('116.6.2 oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.6.3 oracledb.maxRows = actual number of rows', function(done) { it('116.6.3 oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.6.4 oracledb.maxRows > actual number of rows', function(done) { it('116.6.4 oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testMaxRow(option, done); await testMaxRow(option);
}); });
it('116.6.5 queryStream() and oracledb.maxRows < actual number of rows', function(done) { it('116.6.5 queryStream() and oracledb.maxRows < actual number of rows', async function() {
oracledb.maxRows = numRows - 1; oracledb.maxRows = numRows - 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.6.6 queryStream() and oracledb.maxRows = actual number of rows', function(done) { it('116.6.6 queryStream() and oracledb.maxRows = actual number of rows', async function() {
oracledb.maxRows = numRows; oracledb.maxRows = numRows;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.6.7 queryStream() and oracledb.maxRows > actual number of rows', function(done) { it('116.6.7 queryStream() and oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = numRows + 1; oracledb.maxRows = numRows + 1;
testQueryStream(option, done); await testQueryStream(option);
}); });
it('116.6.8 resultSet = true', function(done) { it('116.6.8 resultSet = true', async function() {
var option_rs = { let option_rs = {
resultSet: true, resultSet: true,
outFormat: oracledb.OUT_FORMAT_ARRAY, outFormat: oracledb.OUT_FORMAT_ARRAY,
}; };
test2(option_rs, false, false, done); await test2(option_rs, false);
}); });
}); });
function test1(option, object, array, callback) { async function test1(option, object) {
async.eachSeries(dataArray, function(element, cb) { for (let element in dataArray) {
var sql = "select content,rowid from " + tableName + " where num = " + element; const sql = "select content,rowid from " + tableName + " where num = " + element;
connection.execute( let result = await connection.execute(sql, [], option);
sql, let resultVal_1 = result.rows[0][0];
[], let resultVal_2 = result.rows[0][1];
option,
function(err, result) {
should.not.exist(err);
var resultVal_1 = result.rows[0][0];
var resultVal_2 = result.rows[0][1];
if (object === true) { if (object === true) {
resultVal_1 = result.rows[0].CONTENT; resultVal_1 = result.rows[0].CONTENT;
resultVal_2 = result.rows[0].ROWID; resultVal_2 = result.rows[0].ROWID;
} }
should.strictEqual(typeof resultVal_1, "string"); assert.strictEqual(typeof resultVal_1, "string");
should.strictEqual(resultVal_1, resultVal_2); assert.strictEqual(resultVal_1, resultVal_2);
cb();
} }
);
}, function(err) {
should.not.exist(err);
callback();
});
} }
function test2(option, object, array, callback) { async function test2(option, object) {
async.eachSeries(dataArray, function(element, cb) { for (let element in dataArray) {
var sql = "select content,rowid from " + tableName + " where num = " + element; const sql = "select content,rowid from " + tableName + " where num = " + element;
connection.execute( let result = await connection.execute(sql, [], option);
sql, let row = await result.resultSet.getRow();
[], let resultVal_1 = row[0];
option, let resultVal_2 = row[1];
function(err, result) {
should.not.exist(err);
result.resultSet.getRow(
function(err, row) {
var resultVal_1 = row[0];
var resultVal_2 = row[1];
if (object === true) { if (object === true) {
resultVal_1 = row.CONTENT; resultVal_1 = row.CONTENT;
resultVal_2 = row.ROWID; resultVal_2 = row.ROWID;
} }
should.strictEqual(typeof resultVal_1, "string"); assert.strictEqual(typeof resultVal_1, "string");
should.strictEqual(resultVal_1, resultVal_2); assert.strictEqual(resultVal_1, resultVal_2);
result.resultSet.close(function(err) {
should.not.exist(err); await result.resultSet.close();
cb();
});
} }
);
}
);
}, function(err) {
should.not.exist(err);
callback();
});
} }
function testMaxRow(option, callback) { async function testMaxRow(option) {
var sql = "select CONTENT from " + tableName; let sql = "select CONTENT from " + tableName;
connection.execute( let result = await connection.execute(sql, [], option);
sql, let rowExpected = (oracledb.maxRows >= numRows) ? numRows : oracledb.maxRows;
[], assert.strictEqual(result.rows.length, rowExpected);
option,
function(err, result) {
should.not.exist(err);
var rowExpected = (oracledb.maxRows >= numRows) ? numRows : oracledb.maxRows;
should.strictEqual(result.rows.length, rowExpected);
callback();
}
);
} }
function testQueryStream(option, callback) { async function testQueryStream(option) {
var sql = "select CONTENT from " + tableName; const sql = "select CONTENT from " + tableName;
var stream = connection.queryStream( const stream = await connection.queryStream(sql, [], option);
sql,
[],
option
);
var result = [];
stream.on('data', function(data) {
should.exist(data);
result.push(data);
});
let result = [];
await new Promise((resolve, reject) => {
stream.on('error', reject);
stream.on('end', function() { stream.on('end', function() {
should.strictEqual(result.length, numRows); assert.strictEqual(result.length, numRows);
stream.destroy(); stream.destroy();
}); });
stream.on('close', resolve);
stream.on('close', function() { stream.on('data', function(data) {
callback(); assert(data);
result.push(data);
}); });
});
} }
}); });

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2019, 2022, Oracle and/or its affiliates. */ /* Copyright (c) 2019, 2023, Oracle and/or its affiliates. */
/****************************************************************************** /******************************************************************************
* *
@ -63,7 +63,6 @@ describe('192. implicitResults.js', function() {
if (!isRunnable) { if (!isRunnable) {
this.skip(); this.skip();
return;
} else { } else {
try { try {
const conn = await oracledb.getConnection(dbConfig); const conn = await oracledb.getConnection(dbConfig);

View File

@ -33,37 +33,26 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('158. insertAll.js', function() { describe('158. insertAll.js', function() {
let conn; let conn;
before(function(done) { before(async function() {
oracledb.getConnection( conn = await oracledb.getConnection(dbConfig);
dbConfig,
function(err, connection) {
should.not.exist(err);
conn = connection;
done();
}
);
}); });
after(function(done) { after(async function() {
conn.close(function(err) { await conn.close();
should.not.exist(err);
done();
});
}); });
it('158.1 original case from the issue', function(done) { it('158.1 original case from the issue', async function() {
var dataLength = 35000; let dataLength = 35000;
var doCreate = function(cb) { //Create the table
var proc = "BEGIN \n" + const proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -80,156 +69,94 @@ describe('158. insertAll.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
conn.execute( await conn.execute(proc);
proc,
function(err) {
should.not.exist(err);
cb();
}
);
};
var doDrop = function(cb) { // insert data (including LOB) into the table
var sql = "DROP TABLE nodb_tab_insertall PURGE"; const myval = 'a'.repeat(dataLength);
conn.execute( let sql = "INSERT ALL INTO nodb_tab_insertall \n" +
sql,
function(err) {
should.not.exist(err);
cb();
}
);
};
var doInsert = function(cb) {
var myval = 'a'.repeat(dataLength);
var sql = "INSERT ALL INTO nodb_tab_insertall \n" +
" WITH nt AS (SELECT 1, :C FROM DUAL) \n" + " WITH nt AS (SELECT 1, :C FROM DUAL) \n" +
" SELECT * FROM nt"; " SELECT * FROM nt";
conn.execute( let result = await conn.execute(
sql, sql,
{ c: { val: myval, type: oracledb.CLOB } }, { c: { val: myval, type: oracledb.CLOB } }
function(err, result) {
should.not.exist(err);
(result.rowsAffected).should.be.exactly(1);
cb();
}
); );
}; assert.strictEqual(result.rowsAffected, 1);
var doQuery = function(cb) { // Run a select query to get the inserted LOB's length
var sql = "select dbms_lob.getlength(val) from nodb_tab_insertall"; sql = "select dbms_lob.getlength(val) from nodb_tab_insertall";
conn.execute( result = await conn.execute(sql);
sql, let buf = result.rows[0][0];
function(err, result) { assert.strictEqual(buf, dataLength);
should.not.exist(err);
var buf = result.rows[0][0];
should.strictEqual(buf, dataLength);
cb();
}
);
};
async.series([ // Drop the table
doCreate, sql = "DROP TABLE nodb_tab_insertall PURGE";
doInsert, await conn.execute(sql);
doQuery,
doDrop
], done);
}); // 158.1 }); // 158.1
it('158.2 inserts into one table', function(done) { it('158.2 inserts into one table', async function() {
async.series([ await makeTab1();
makeTab1, let sql = "INSERT ALL \n" +
function dotest(cb) {
var sql = "INSERT ALL \n" +
" INTO nodb_tab_ia1 (id, content) VALUES (100, :a) \n" + " INTO nodb_tab_ia1 (id, content) VALUES (100, :a) \n" +
" INTO nodb_tab_ia1 (id, content) VALUES (200, :b) \n" + " INTO nodb_tab_ia1 (id, content) VALUES (200, :b) \n" +
" INTO nodb_tab_ia1 (id, content) VALUES (300, :c) \n" + " INTO nodb_tab_ia1 (id, content) VALUES (300, :c) \n" +
"SELECT * FROM DUAL"; "SELECT * FROM DUAL";
conn.execute( let result = await conn.execute(
sql, sql,
['Changjie', 'Shelly', 'Chris'], ['Changjie', 'Shelly', 'Chris']
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 3);
cb();
}
); );
}, assert.strictEqual(result.rowsAffected, 3);
function doverify(cb) {
var sql = "select content from nodb_tab_ia1 order by id"; sql = "select content from nodb_tab_ia1 order by id";
conn.execute( result = await conn.execute(sql);
sql, assert.deepStrictEqual(
function(err, result) {
should.not.exist(err);
should.deepEqual(
result.rows, result.rows,
[ [ 'Changjie' ], [ 'Shelly' ], [ 'Chris' ] ] [ [ 'Changjie' ], [ 'Shelly' ], [ 'Chris' ] ]
); );
cb();
} //Drop the table
); sql = "DROP TABLE nodb_tab_ia1 PURGE";
}, await conn.execute(sql);
dropTab1
], done);
}); // 158.2 }); // 158.2
it('158.3 inserts into multiple tables', function(done) { it('158.3 inserts into multiple tables', async function() {
async.series([ await makeTab1();
makeTab1, await makeTab2();
makeTab2,
function dotest(cb) { let sql = "INSERT ALL \n" +
var sql = "INSERT ALL \n" +
" INTO nodb_tab_ia1 (id, content) VALUES (100, :a) \n" + " INTO nodb_tab_ia1 (id, content) VALUES (100, :a) \n" +
" INTO nodb_tab_ia1 (id, content) VALUES (200, :b) \n" + " INTO nodb_tab_ia1 (id, content) VALUES (200, :b) \n" +
" INTO nodb_tab_ia2 (id, content) VALUES (300, :c) \n" + " INTO nodb_tab_ia2 (id, content) VALUES (300, :c) \n" +
"SELECT * FROM DUAL"; "SELECT * FROM DUAL";
conn.execute( let result = await conn.execute(
sql, sql,
['Redwood city', 'Sydney', 'Shenzhen'], ['Redwood city', 'Sydney', 'Shenzhen']
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 3);
cb();
}
); );
}, assert.strictEqual(result.rowsAffected, 3);
function doverify1(cb) {
var sql = "select content from nodb_tab_ia1 order by id"; sql = "select content from nodb_tab_ia1 order by id";
conn.execute( result = await conn.execute(sql);
sql, assert.deepStrictEqual(
function(err, result) {
should.not.exist(err);
should.deepEqual(
result.rows, result.rows,
[ [ 'Redwood city' ], [ 'Sydney' ]] [ [ 'Redwood city' ], [ 'Sydney' ]]
); );
cb();
} sql = "select content from nodb_tab_ia2 order by id";
); result = await conn.execute(sql);
}, assert.deepStrictEqual(
function doverify2(cb) {
var sql = "select content from nodb_tab_ia2 order by id";
conn.execute(
sql,
function(err, result) {
should.not.exist(err);
should.deepEqual(
result.rows, result.rows,
[ [ 'Shenzhen' ]] [ [ 'Shenzhen' ]]
); );
cb();
} //Drop the tables
); sql = "DROP TABLE nodb_tab_ia1 PURGE";
}, await conn.execute(sql);
dropTab1, sql = "DROP TABLE nodb_tab_ia2 PURGE";
dropTab2 await conn.execute(sql);
], done);
}); // 158.3 }); // 158.3
var makeTab1 = function(cb) { const makeTab1 = async function() {
var proc = "BEGIN \n" + const proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -246,28 +173,11 @@ describe('158. insertAll.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
conn.execute( await conn.execute(proc);
proc,
function(err) {
should.not.exist(err);
cb();
}
);
}; // makeTab1 }; // makeTab1
var dropTab1 = function(cb) { const makeTab2 = async function() {
var sql = "DROP TABLE nodb_tab_ia1 PURGE"; const proc = "BEGIN \n" +
conn.execute(
sql,
function(err) {
should.not.exist(err);
cb();
}
);
};
var makeTab2 = function(cb) {
var proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -284,24 +194,7 @@ describe('158. insertAll.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
conn.execute( await conn.execute(proc);
proc,
function(err) {
should.not.exist(err);
cb();
}
);
};
var dropTab2 = function(cb) {
var sql = "DROP TABLE nodb_tab_ia2 PURGE";
conn.execute(
sql,
function(err) {
should.not.exist(err);
cb();
}
);
}; };
}); });

View File

@ -105,4 +105,35 @@ describe('54. lobClose.js', function() {
); );
}); // 54.4 }); // 54.4
it('54.5 temp LOBs should be freed in next rpc', async function() {
const conn2 = await oracledb.getConnection(dbConfig);
let tempLOBArray = [];
const numLOBs = 20;
const query = "select cache_lobs+nocache_lobs from v$temporary_lobs where sid = sys_context('USERENV','SID')";
// Create multiple temp LOB's
for (let i = 0; i < numLOBs; i++) {
tempLOBArray[i] = await conn2.createLob(oracledb.CLOB);
}
// Check number of opened temp LOB's
let result = await conn2.execute(query);
let numTempLOBs = result.rows[0][0];
assert.strictEqual(numTempLOBs, numLOBs);
// Destroy multiple temp LOB's
for (let i = 0; i < numLOBs; i++) {
await new Promise((resolve) => {
tempLOBArray[i].once('close', resolve);
tempLOBArray[i].destroy();
});
}
// temp LOB's should be freed on roundtrip (like execute) as piggybacks are sent for closing temp LOB's
result = await conn2.execute(query);
numTempLOBs = result.rows[0][0];
assert.strictEqual(numTempLOBs, 0);
await conn2.close();
}); // 54.5
}); });

View File

@ -38,7 +38,6 @@ const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const testsUtil = require('./testsUtil.js'); const testsUtil = require('./testsUtil.js');
const assist = require('./dataTypeAssist.js');
describe('132. longrawProcedureBind_in.js', function() { describe('132. longrawProcedureBind_in.js', function() {
@ -228,7 +227,7 @@ describe('132. longrawProcedureBind_in.js', function() {
if (expected == null) { if (expected == null) {
assert.strictEqual(result.rows[0][1], expected); assert.strictEqual(result.rows[0][1], expected);
} else { } else {
assist.compare2Buffers(result.rows[0][1], expected); assert.deepStrictEqual(result.rows[0][1], expected);
} }
}; };

View File

@ -37,7 +37,6 @@ const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const testsUtil = require('./testsUtil.js'); const testsUtil = require('./testsUtil.js');
const assist = require('./dataTypeAssist.js');
describe('133. longrawProcedureBind_inout.js', function() { describe('133. longrawProcedureBind_inout.js', function() {
@ -182,7 +181,7 @@ describe('133. longrawProcedureBind_inout.js', function() {
if (expectedBuf == null) { if (expectedBuf == null) {
assert.strictEqual(result.outBinds.c, expectedBuf); assert.strictEqual(result.outBinds.c, expectedBuf);
} else { } else {
assist.compare2Buffers(result.outBinds.c, expectedBuf); assert.deepStrictEqual(result.outBinds.c, expectedBuf);
} }
}; };
@ -204,7 +203,7 @@ describe('133. longrawProcedureBind_inout.js', function() {
if (expectedBuf == null) { if (expectedBuf == null) {
assert.strictEqual(result.outBinds.c, expectedBuf); assert.strictEqual(result.outBinds.c, expectedBuf);
} else { } else {
assist.compare2Buffers(result.outBinds.c, expectedBuf); assert.deepStrictEqual(result.outBinds.c, expectedBuf);
} }
}; };

View File

@ -37,7 +37,6 @@ const assert = require('assert');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
const random = require('./random.js'); const random = require('./random.js');
const testsUtil = require('./testsUtil.js'); const testsUtil = require('./testsUtil.js');
const assist = require('./dataTypeAssist.js');
describe('134. longrawProcedureBind_out.js', function() { describe('134. longrawProcedureBind_out.js', function() {
@ -214,7 +213,7 @@ describe('134. longrawProcedureBind_out.js', function() {
if (expectedBuf == null) { if (expectedBuf == null) {
assert.strictEqual(result.outBinds.c, expectedBuf); assert.strictEqual(result.outBinds.c, expectedBuf);
} else { } else {
assist.compare2Buffers(result.outBinds.c, expectedBuf); assert.deepStrictEqual(result.outBinds.c, expectedBuf);
} }
}; };

View File

@ -32,26 +32,17 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('157. maxRows.js', function() { describe('157. maxRows.js', function() {
let connection = null; let connection = null;
var totalAmount = 107; let totalAmount = 107;
before(function(done) { before(async function() {
async.series([ connection = await oracledb.getConnection(dbConfig);
function getConn(cb) { let proc = "BEGIN \n" +
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
});
},
function createTab(cb) {
var proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -68,17 +59,9 @@ describe('157. maxRows.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
await connection.execute(proc);
connection.execute( proc = "DECLARE \n" +
proc,
function(err) {
should.not.exist(err);
cb();
}
);
},
function insertData(cb) {
var proc = "DECLARE \n" +
" x NUMBER := 0; \n" + " x NUMBER := 0; \n" +
" n VARCHAR2(20); \n" + " n VARCHAR2(20); \n" +
"BEGIN \n" + "BEGIN \n" +
@ -88,136 +71,82 @@ describe('157. maxRows.js', function() {
" INSERT INTO nodb_tab_conn_emp2 VALUES (x, n); \n" + " INSERT INTO nodb_tab_conn_emp2 VALUES (x, n); \n" +
" END LOOP; \n" + " END LOOP; \n" +
"END; "; "END; ";
await connection.execute(proc);
connection.execute(
proc,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); // before() }); // before()
after(function(done) { after(async function() {
async.series([ await connection.execute("DROP TABLE nodb_tab_conn_emp2 PURGE");
function(cb) { await connection.close();
connection.execute(
"DROP TABLE nodb_tab_conn_emp2 PURGE",
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // after() }); // after()
// restore oracledb.maxRows to its default value // restore oracledb.maxRows to its default value
afterEach(function(done) { afterEach(function() {
var defaultValue = 0; let defaultValue = 0;
oracledb.maxRows = defaultValue; oracledb.maxRows = defaultValue;
done();
}); });
var verifyRows = function(rows, amount) { let verifyRows = function(rows, amount) {
for (var i = 0; i < amount; i++) { for (let i = 0; i < amount; i++) {
should.strictEqual(rows[i][0], (i + 1)); assert.strictEqual(rows[i][0], (i + 1));
should.strictEqual(rows[i][1], ("staff " + String(i + 1))); assert.strictEqual(rows[i][1], ("staff " + String(i + 1)));
} }
}; };
var sqlQuery = "SELECT * FROM nodb_tab_conn_emp2 ORDER BY id"; let sqlQuery = "SELECT * FROM nodb_tab_conn_emp2 ORDER BY id";
it('157.1 Default maxRows == 0, which means unlimited', function(done) { it('157.1 Default maxRows == 0, which means unlimited', async function() {
should.strictEqual(oracledb.maxRows, 0); assert.strictEqual(oracledb.maxRows, 0);
connection.execute( const result = await connection.execute(sqlQuery);
sqlQuery, assert(result);
function(err, result) { assert.strictEqual(result.rows.length, totalAmount);
should.not.exist(err);
should.exist(result);
should.strictEqual(result.rows.length, totalAmount);
verifyRows(result.rows, totalAmount); verifyRows(result.rows, totalAmount);
done();
}
);
}); });
it("157.2 specify the value at execution", function(done) { it("157.2 specify the value at execution", async function() {
var fetchAmount = 25; let fetchAmount = 25;
connection.execute( const result = await connection.execute(
sqlQuery, sqlQuery,
{}, {},
{ maxRows: fetchAmount }, { maxRows: fetchAmount }
function(err, result) { );
should.not.exist(err); assert(result);
should.exist(result); assert.strictEqual(result.rows.length, fetchAmount);
should.strictEqual(result.rows.length, fetchAmount);
verifyRows(result.rows, fetchAmount); verifyRows(result.rows, fetchAmount);
done();
}
);
}); });
it('157.3 equals to the total amount of rows', function(done) { it('157.3 equals to the total amount of rows', async function() {
connection.execute( const result = await connection.execute(
sqlQuery, sqlQuery,
{}, {},
{ maxRows: totalAmount }, { maxRows: totalAmount }
function(err, result) { );
should.not.exist(err); assert(result);
should.exist(result); assert.strictEqual(result.rows.length, totalAmount);
should.strictEqual(result.rows.length, totalAmount);
verifyRows(result.rows, totalAmount); verifyRows(result.rows, totalAmount);
done(); });
}
it('157.4 cannot set it to be a negative number', async function() {
await assert.rejects(
async () => {
await connection.execute(sqlQuery, {}, { maxRows: -5 });
},
// NJS-007: invalid value for "maxRows" in parameter 3
/NJS-007:/
); );
}); });
it('157.4 cannot set it to be a negative number', function(done) { it('157.5 sets it to be large value', async function() {
connection.execute( const result = await connection.execute(sqlQuery, {}, { maxRows: 500000 });
sqlQuery, assert(result);
{},
{ maxRows: -5 },
function(err, result) {
should.exist(err);
should.not.exist(result);
should.strictEqual(
err.message,
'NJS-007: invalid value for "maxRows" in parameter 3'
);
done();
}
);
});
it('157.5 sets it to be large value', function(done) {
connection.execute(
sqlQuery,
{},
{ maxRows: 500000 },
function(err, result) {
should.not.exist(err);
should.exist(result);
verifyRows(result.rows, totalAmount); verifyRows(result.rows, totalAmount);
done();
}
);
}); });
it('157.6 shows 12c new way to limit the number of records fetched by queries', function(done) { it('157.6 shows 12c new way to limit the number of records fetched by queries', async function() {
var myoffset = 2; // number of rows to skip let myoffset = 2; // number of rows to skip
var mymaxnumrows = 6; // number of rows to fetch let mymaxnumrows = 6; // number of rows to fetch
var sql = "SELECT * FROM nodb_tab_conn_emp2 ORDER BY id"; let sql = "SELECT * FROM nodb_tab_conn_emp2 ORDER BY id";
if (connection.oracleServerVersion >= 1201000000) { if (connection.oracleServerVersion >= 1201000000) {
// 12c row-limiting syntax // 12c row-limiting syntax
@ -229,47 +158,29 @@ describe('157. maxRows.js', function() {
+ "WHERE ROWNUM <= :maxnumrows + :offset) WHERE MY_RNUM > :offset"; + "WHERE ROWNUM <= :maxnumrows + :offset) WHERE MY_RNUM > :offset";
} }
connection.execute( const result = await connection.execute(
sql, sql,
{ offset: myoffset, maxnumrows: mymaxnumrows }, { offset: myoffset, maxnumrows: mymaxnumrows },
{ maxRows: 150 }, { maxRows: 150 }
function(err, result) {
should.not.exist(err);
(result.rows.length).should.eql(mymaxnumrows);
done();
}
); );
assert.strictEqual(result.rows.length, mymaxnumrows);
}); // 157.6 }); // 157.6
it('157.7 oracledb.maxRows > 0 && oracledb.maxRows < totalAmount', function(done) { it('157.7 oracledb.maxRows > 0 && oracledb.maxRows < totalAmount', async function() {
var testValue = 100; let testValue = 100;
oracledb.maxRows = testValue; oracledb.maxRows = testValue;
connection.execute( let result = await connection.execute(sqlQuery);
sqlQuery, let expectedAmount = testValue;
function(err, result) {
should.not.exist(err);
var expectedAmount = testValue;
verifyRows(result.rows, expectedAmount); verifyRows(result.rows, expectedAmount);
done();
}
);
}); // 157.7 }); // 157.7
it('157.8 oracledb.maxRows > 0, execute() with maxRows=0', function(done) { it('157.8 oracledb.maxRows > 0, execute() with maxRows=0', async function() {
oracledb.maxRows = 100; oracledb.maxRows = 100;
connection.execute( let result = await connection.execute(sqlQuery, {}, { maxRows: 0 });
sqlQuery, let expectedAmount = totalAmount;
{},
{ maxRows: 0 },
function(err, result) {
should.not.exist(err);
var expectedAmount = totalAmount;
verifyRows(result.rows, expectedAmount); verifyRows(result.rows, expectedAmount);
done();
}
);
}); // 157.8 }); // 157.8
}); });

View File

@ -26,40 +26,24 @@
* 68. multipleLobInsertion.js * 68. multipleLobInsertion.js
* *
* DESCRIPTION * DESCRIPTION
* Testing external authentication functionality. * Testing multiple insertions of Large Objects including BLOB and CLOB
*
* Note that enabling the externalAuth feature requires configuration on the
* database besides setting "externalAuth" attribute to be true. Please refer
* to API documentation about configuration.
* https://node-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#extauth
* *
*****************************************************************************/ *****************************************************************************/
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should');
const async = require('async');
const fs = require('fs'); const fs = require('fs');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('68. multipleLobInsertion.js', function() { describe('68. multipleLobInsertion.js', function() {
let connection = null; let connection = null;
before(function(done) { before(async function() {
async.series([ connection = await oracledb.getConnection(dbConfig);
function getConn(cb) {
oracledb.getConnection( // create the BLOB table
dbConfig, let proc = "BEGIN \n" +
function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
}
);
},
function createTabBLOB(cb) {
var proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -80,17 +64,10 @@ describe('68. multipleLobInsertion.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
await connection.execute(proc);
connection.execute( // create the CLOB table
proc, proc = "BEGIN \n" +
function(err) {
should.not.exist(err);
cb();
}
);
},
function createTabCLOB(cb) {
var proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
@ -111,106 +88,37 @@ describe('68. multipleLobInsertion.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
await connection.execute(proc);
connection.execute(
proc,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); // before }); // before
after(function(done) { after(async function() {
async.series([ await connection.execute("DROP TABLE nodb_multi_clob PURGE");
function(cb) { await connection.execute("DROP TABLE nodb_multi_blob PURGE");
connection.execute( await connection.close();
"DROP TABLE nodb_multi_clob PURGE",
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
"DROP TABLE nodb_multi_blob PURGE",
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // after }); // after
var lobInsert = function(sql, bindv, inFileName, cb) { const lobInsert = async function(sql, bindv, inFileName) {
const result = await connection.execute(sql, bindv, { autoCommit: false });
connection.execute( for (let item in result.outBinds) {
sql, const lob = result.outBinds[item][0];
bindv, const inStream = fs.createReadStream(inFileName);
{ autoCommit: false }, await new Promise((resolve, reject) => {
function(err, result) { inStream.on('error', reject);
should.not.exist(err); lob.on('error', reject);
lob.on('finish', resolve);
var lobArr = new Array();
// put lobbv1..5 to lobArr
for (var item in result.outBinds) {
lobArr.push(result.outBinds[item][0]);
}
async.eachSeries(
lobArr,
function(lob, callback) {
var inStream = fs.createReadStream(inFileName);
inStream.pipe(lob); inStream.pipe(lob);
// one task completes
lob.on('finish', function() {
return callback();
});
lob.on('error', function(err) {
return callback(err);
});
inStream.on('error', function(err) {
return callback(err);
});
},
function(err) {
should.not.exist(err);
connection.commit(function(err) {
should.not.exist(err);
return cb();
}); });
} }
); // async.eachSeries await connection.commit();
}
);
}; };
it('68.1 inserts multiple BLOBs', function(done) { it('68.1 inserts multiple BLOBs', async function() {
var sql = "insert into nodb_multi_blob values(1, " + const sql = "insert into nodb_multi_blob values(1, " +
" EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB() ) " + " EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB(), EMPTY_BLOB() ) " +
" returning b1, b2, b3, b4, b5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5"; " returning b1, b2, b3, b4, b5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5";
var bindvars = { const bindvars = {
lobbv1: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }, lobbv1: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
lobbv2: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }, lobbv2: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
lobbv3: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }, lobbv3: { type: oracledb.BLOB, dir: oracledb.BIND_OUT },
@ -218,19 +126,19 @@ describe('68. multipleLobInsertion.js', function() {
lobbv5: { type: oracledb.BLOB, dir: oracledb.BIND_OUT } lobbv5: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }
}; };
var inFileName = './test/fuzzydinosaur.jpg'; const inFileName = './test/fuzzydinosaur.jpg';
lobInsert(sql, bindvars, inFileName, done); await lobInsert(sql, bindvars, inFileName);
}); // 68.1 }); // 68.1
it('68.2 inserts multiple CLOBs', function(done) { it('68.2 inserts multiple CLOBs', async function() {
var sql = "insert into nodb_multi_clob values(1, " + const sql = "insert into nodb_multi_clob values(1, " +
" EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB() ) " + " EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB() ) " +
" returning c1, c2, c3, c4, c5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5"; " returning c1, c2, c3, c4, c5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5";
var bindvars = { const bindvars = {
lobbv1: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }, lobbv1: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
lobbv2: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }, lobbv2: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
lobbv3: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }, lobbv3: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
@ -238,10 +146,10 @@ describe('68. multipleLobInsertion.js', function() {
lobbv5: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } lobbv5: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }
}; };
var inFileName = './test/clobexample.txt'; const inFileName = './test/clobexample.txt';
lobInsert(sql, bindvars, inFileName, done); await lobInsert(sql, bindvars, inFileName);
}); }); // 68.2
}); });

View File

@ -252,3 +252,4 @@ spec:
- test/aq4.js - test/aq4.js
- test/procAndFuncs.js - test/procAndFuncs.js
- test/poolTimeout.js - test/poolTimeout.js
- test/binding_buffer_string.js

View File

@ -32,28 +32,18 @@
'use strict'; 'use strict';
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('15. resultsetToStream.js', function() { describe('15. resultsetToStream.js', function() {
let connection = null; let connection = null;
var rowsAmount = 217; const rowsAmount = 217;
before(function(done) {
async.series([ before(async function() {
function getConn(cb) { connection = await oracledb.getConnection(dbConfig);
oracledb.getConnection(
dbConfig, let proc = "BEGIN \n" +
function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
}
);
},
function createTab(cb) {
var proc = "BEGIN \n" +
" DECLARE \n" + " DECLARE \n" +
" e_table_missing EXCEPTION; \n" + " e_table_missing EXCEPTION; \n" +
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n " + " PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n " +
@ -71,17 +61,9 @@ describe('15. resultsetToStream.js', function() {
" ) \n" + " ) \n" +
" '); \n" + " '); \n" +
"END; "; "END; ";
await connection.execute(proc);
connection.execute( proc = "DECLARE \n" +
proc,
function(err) {
should.not.exist(err);
cb();
}
);
},
function insertRows(cb) {
var proc = "DECLARE \n" +
" x NUMBER := 0; \n" + " x NUMBER := 0; \n" +
" n VARCHAR2(20); \n" + " n VARCHAR2(20); \n" +
" clobData CLOB; \n" + " clobData CLOB; \n" +
@ -93,77 +75,43 @@ describe('15. resultsetToStream.js', function() {
" DBMS_LOB.WRITE(clobData, 20, 1, '12345678901234567890'); \n" + " DBMS_LOB.WRITE(clobData, 20, 1, '12345678901234567890'); \n" +
" END LOOP; \n" + " END LOOP; \n" +
"end; "; "end; ";
await connection.execute(proc);
connection.execute(
proc,
function(err) {
should.not.exist(err);
cb();
}
);
}
], done);
}); // before }); // before
after(function(done) { after(async function() {
async.series([ await connection.execute("DROP TABLE nodb_rs2stream PURGE");
function(callback) { await connection.close();
connection.execute(
"DROP TABLE nodb_rs2stream PURGE",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.close(function(err) {
should.not.exist(err);
callback();
});
},
], done);
}); // after }); // after
describe('15.1 Testing ResultSet.toQueryStream', function() { describe('15.1 Testing ResultSet.toQueryStream', function() {
it('15.1.1 should allow resultsets to be converted to streams', function(done) {
connection.execute( it('15.1.1 should allow resultsets to be converted to streams', async function() {
const result = await connection.execute(
'begin \n' + 'begin \n' +
' open :cursor for select employees_name from nodb_rs2stream; \n' + ' open :cursor for select employees_name from nodb_rs2stream; \n' +
'end;', 'end;',
{ {
cursor: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } cursor: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
var stream = result.outBinds.cursor.toQueryStream();
stream.on('error', function(error) {
console.log(error);
should.fail(error, null, 'Error event should not be triggered');
});
var counter = 0;
stream.on('data', function(data) {
should.exist(data);
counter++;
});
stream.on('end', function() {
should.equal(counter, rowsAmount);
stream.destroy();
});
stream.on('close', function() {
done();
});
} }
); );
const stream = result.outBinds.cursor.toQueryStream();
let counter = 0;
await new Promise((resolve, reject) => {
stream.on('error', reject);
stream.on('end', stream.destroy);
stream.on('close', resolve);
stream.on('data', function(data) {
assert(data);
counter++;
}); });
}); });
assert.strictEqual(counter, rowsAmount);
}); // 15.1.1
}); // 15.1
describe('15.2 Testing ResultSet/QueryStream conversion errors', function() { describe('15.2 Testing ResultSet/QueryStream conversion errors', function() {
it('15.2.1 should prevent conversion to stream after getRow is invoked', async function() { it('15.2.1 should prevent conversion to stream after getRow is invoked', async function() {
const sql = ` const sql = `
begin begin
@ -175,15 +123,13 @@ describe('15. resultsetToStream.js', function() {
const result = await connection.execute(sql, binds); const result = await connection.execute(sql, binds);
const cursor = result.outBinds.cursor; const cursor = result.outBinds.cursor;
await cursor.getRow(); await cursor.getRow();
try { await assert.throws(
const stream = cursor.toQueryStream(); () => cursor.toQueryStream(),
should.not.exist(stream);
} catch (err) {
(err.message).should.startWith('NJS-041:');
// NJS-041: cannot convert to stream after invoking methods // NJS-041: cannot convert to stream after invoking methods
} /NJS-041:/
);
await cursor.close(); await cursor.close();
}); }); // 15.2.1
it('15.2.2 should prevent conversion to stream after getRows is invoked', async function() { it('15.2.2 should prevent conversion to stream after getRows is invoked', async function() {
const sql = ` const sql = `
@ -196,14 +142,13 @@ describe('15. resultsetToStream.js', function() {
const result = await connection.execute(sql, binds); const result = await connection.execute(sql, binds);
const cursor = result.outBinds.cursor; const cursor = result.outBinds.cursor;
await cursor.getRows(5); await cursor.getRows(5);
try { assert.throws(
const stream = cursor.toQueryStream(); () => cursor.toQueryStream(),
should.not.exist(stream); // NJS-041: cannot convert to stream after invoking methods
} catch (err) { /NJS-041:/
(err.message).should.startWith('NJS-041:'); );
}
await cursor.close(); await cursor.close();
}); }); // 15.2.2
it('15.2.3 should prevent conversion to stream after close is invoked', async function() { it('15.2.3 should prevent conversion to stream after close is invoked', async function() {
const sql = ` const sql = `
@ -216,126 +161,86 @@ describe('15. resultsetToStream.js', function() {
const result = await connection.execute(sql, binds); const result = await connection.execute(sql, binds);
const cursor = result.outBinds.cursor; const cursor = result.outBinds.cursor;
await cursor.close(); await cursor.close();
try { assert.throws(
() => cursor.toQueryStream(),
// NJS-041: cannot convert to stream after invoking methods
/NJS-041:/
);
}); // 15.2.3
it('15.2.4 should prevent invoking getRow after conversion to stream', async function() {
const sql = `
begin
open :cursor for select employees_name from nodb_rs2stream;
end;`;
const binds = {
cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT }
};
const result = await connection.execute(sql, binds);
const cursor = result.outBinds.cursor;
const stream = cursor.toQueryStream(); const stream = cursor.toQueryStream();
should.not.exist(stream); await assert.rejects(
} catch (err) { async () => await cursor.getRow(),
(err.message).should.startWith('NJS-041:');
}
});
it('15.2.4 should prevent invoking getRow after conversion to stream', function(done) {
connection.execute(
'begin \n' +
' open :cursor for select employees_name from nodb_rs2stream; \n' +
'end;',
{
cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
var cursor = result.outBinds.cursor;
var stream = cursor.toQueryStream();
stream.on('close', done);
stream.on('error', function(err) {
should.not.exist(err);
});
cursor.getRow(function(err) {
(err.message).should.startWith('NJS-042:');
// NJS-042: cannot invoke methods after converting to stream // NJS-042: cannot invoke methods after converting to stream
stream.destroy(); /NJS-042:/
});
}
); );
}); stream.destroy();
}); // 15.2.4
it('15.2.5 should prevent invoking getRows after conversion to stream', function(done) { it('15.2.5 should prevent invoking getRows after conversion to stream', async function() {
connection.execute( const sql = `
'begin \n' + begin
' open :cursor for select employees_name from nodb_rs2stream; \n' + open :cursor for select employees_name from nodb_rs2stream;
'end;', end;`;
{ const binds = {
cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT } cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT }
}, };
function(err, result) { const result = await connection.execute(sql, binds);
should.not.exist(err); const cursor = result.outBinds.cursor;
const stream = cursor.toQueryStream();
var cursor = result.outBinds.cursor; await assert.rejects(
var stream = cursor.toQueryStream(); async () => await cursor.getRows(5),
// NJS-042: cannot invoke methods after converting to stream
stream.on('close', done); /NJS-042:/
stream.on('error', function(err) {
should.not.exist(err);
});
cursor.getRows(5, function(err) {
(err.message).should.startWith('NJS-042:');
stream.destroy();
});
}
); );
}); stream.destroy();
}); // 15.2.5
it('15.2.6 should prevent invoking close after conversion to stream', function(done) { it('15.2.6 should prevent invoking close after conversion to stream', async function() {
connection.execute( const sql = `
'begin \n' + begin
' open :cursor for select employees_name from nodb_rs2stream; \n' + open :cursor for select employees_name from nodb_rs2stream;
'end;', end;`;
{ const binds = {
cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT } cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT }
}, };
function(err, result) { const result = await connection.execute(sql, binds);
should.not.exist(err); const cursor = result.outBinds.cursor;
const stream = cursor.toQueryStream();
var cursor = result.outBinds.cursor; await assert.rejects(
var stream = cursor.toQueryStream(); async () => await cursor.close(),
// NJS-042: cannot invoke methods after converting to stream
stream.on('close', done); /NJS-042:/
stream.on('error', function(err) {
should.not.exist(err);
});
cursor.close(function(err) {
(err.message).should.startWith('NJS-042:');
stream.destroy();
});
}
); );
}); stream.destroy();
}); // 15.2.6
it('15.2.7 should prevent calling toQueryStream more than once', function(done) { it('15.2.7 should prevent calling toQueryStream more than once', async function() {
connection.execute( const sql = `
'begin \n' + begin
' open :cursor for select employees_name from nodb_rs2stream; \n' + open :cursor for select employees_name from nodb_rs2stream;
'end;', end;`;
{ const binds = {
cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT } cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT }
}, };
function(err, result) { const result = await connection.execute(sql, binds);
should.not.exist(err); const cursor = result.outBinds.cursor;
const stream = cursor.toQueryStream();
var cursor = result.outBinds.cursor; assert.throws(
() => cursor.toQueryStream(),
// First conversion to stream /NJS-043:/
var stream = cursor.toQueryStream();
stream.on('close', done);
stream.on('error', function(err) {
should.not.exist(err);
});
try {
// Second conversion to stream
stream = cursor.toQueryStream();
} catch (err) {
(err.message).should.startWith('NJS-043:');
stream.destroy();
}
}
); );
stream.destroy();
}); // 15.2.7 }); // 15.2.7
}); // 15.2 }); // 15.2

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. */ /* Copyright (c) 2017, 2023, Oracle and/or its affiliates. */
/****************************************************************************** /******************************************************************************
* *
@ -30,9 +30,6 @@
*****************************************************************************/ *****************************************************************************/
'use strict'; 'use strict';
const should = require('should');
const async = require('async');
const sql = exports; const sql = exports;
module.exports = sql; module.exports = sql;
@ -71,95 +68,3 @@ sql.createTable = function(tableName, dataType) {
END;`; END;`;
return sql; return sql;
}; };
sql.createAllTable = function(tableName, dataTypeArray) {
let sql = `BEGIN
DECLARE
e_table_missing EXCEPTION;
PRAGMA EXCEPTION_INIT(e_table_missing, -00942);
BEGIN
EXECUTE IMMEDIATE ('DROP TABLE ` + tableName + ` PURGE' );
EXCEPTION
WHEN e_table_missing
THEN NULL;
END;
EXECUTE IMMEDIATE ( '
CREATE TABLE ` + tableName + ` (
id NUMBER, `;
async.eachSeries(dataTypeArray, function(element, cb) {
const index = dataTypeArray.indexOf(element);
const length = dataTypeArray.length;
const col_name = "col_" + (index + 1);
let col_type = element;
let isLast;
if (col_type === "CHAR") {
element = element + "(2000)";
}
if (col_type === "NCHAR") {
element = element + "(1000)";
}
if (col_type === "VARCHAR2") {
element = element + "(4000)";
}
if (col_type === "RAW") {
element = element + "(2000)";
}
isLast = (index == (length - 1)) ? true : false;
sql = appendSql(sql, col_name, element, isLast);
cb();
}, function(err) {
should.not.exist(err);
});
sql = sql +
` )
');
END;`;
return sql;
};
sql.executeSql = function(connection, sql, bindVar, option, callback) {
connection.execute(
sql,
bindVar,
option,
function(err) {
if (err) {
let stack = new Error().stack;
console.error(err);
console.error(stack);
}
should.not.exist(err);
callback(err);
}
);
};
sql.createRowid = function(connection, rowid_type, object_number, relative_fno, block_number, row_number, callback) {
// Parameter Description
// rowid_type Type (restricted or extended), set the rowid_type parameter to 0 for a restricted ROWID. Set it to 1 to create an extended ROWID.
// If you specify rowid_type as 0, then the required object_number parameter is ignored, and ROWID_CREATE returns a restricted ROWID.
// object_number The data object number for the ROWID. For a restricted ROWID, use the ROWID_OBJECT_UNDEFINED constant.
// relative_fno The relative file number for the ROWID.
// block_number The block number for the ROWID.
// row_number The row number for the ROWID.
let myRowid = "";
connection.execute(
"select DBMS_ROWID.ROWID_CREATE(" + rowid_type + ", " + object_number + ", " + relative_fno + ", " + block_number + ", " + row_number + ") create_rowid from dual",
function(err, result) {
should.not.exist(err);
myRowid = result.rows[0][0];
callback(myRowid);
}
);
};
const appendSql = function(sql, col_name, col_type, isLast) {
if (isLast === true) {
sql = sql + " " + col_name + " " + col_type + " \n";
} else {
sql = sql + " " + col_name + " " + col_type + ", \n";
}
return sql;
};

View File

@ -1,172 +0,0 @@
/* Copyright (c) 2017, 2022, 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
* sql.js
*
* DESCRIPTION
* generate sql
*****************************************************************************/
'use strict';
const should = require('should');
const async = require('async');
const sql = exports;
module.exports = sql;
sql.createTable = function(tableName, dataType) {
let element = dataType;
if (dataType === "CHAR") {
element = element + "(1000)";
}
if (dataType === "NCHAR") {
element = element + "(1000)";
}
if (dataType === "VARCHAR2") {
element = element + "(1000)";
}
if (dataType === "RAW") {
element = element + "(1000)";
}
const sql = `BEGIN
DECLARE
e_table_missing EXCEPTION;
PRAGMA EXCEPTION_INIT(e_table_missing, -00942);
BEGIN
EXECUTE IMMEDIATE ('DROP TABLE ` + tableName + ` PURGE' );
EXCEPTION
WHEN e_table_missing
THEN NULL;
END;
EXECUTE IMMEDIATE ( '
CREATE TABLE ` + tableName + ` (
id NUMBER,
content ` + element + `
)
');
END;`;
return sql;
};
sql.createAllTable = function(tableName, dataTypeArray) {
let sql = `BEGIN
DECLARE
e_table_missing EXCEPTION;
PRAGMA EXCEPTION_INIT(e_table_missing, -00942);
BEGIN
EXECUTE IMMEDIATE ('DROP TABLE ` + tableName + ` PURGE' );
EXCEPTION
WHEN e_table_missing
THEN NULL;
END;
EXECUTE IMMEDIATE ( '
CREATE TABLE ` + tableName + ` (
id NUMBER, `;
async.eachSeries(dataTypeArray, function(element, cb) {
const index = dataTypeArray.indexOf(element);
const length = dataTypeArray.length;
const col_name = "col_" + (index + 1);
let col_type = element;
let isLast;
if (col_type === "CHAR") {
element = element + "(2000)";
}
if (col_type === "NCHAR") {
element = element + "(1000)";
}
if (col_type === "VARCHAR2") {
element = element + "(4000)";
}
if (col_type === "RAW") {
element = element + "(2000)";
}
isLast = (index == (length - 1)) ? true : false;
sql = appendSql(sql, col_name, element, isLast);
cb();
}, function(err) {
should.not.exist(err);
});
sql = sql +
` )
');
END;`;
return sql;
};
// sql.executeSql = function(connection, sql, bindVar, option, callback) {
// connection.execute(sql,
// bindVar,
// option,
// function(err) {
// if (err) {
// let stack = new Error().stack;
// console.error(err);
// console.error(stack);
// }
// should.not.exist(err);
// callback(err);
// }
// );
// };
sql.executeSql = async function(connection, sql, bindVar, option) {
try {
await connection.execute(sql, bindVar, option);
} catch (err) {
should.not.exist(err);
}
};
sql.createRowid = function(connection, rowid_type, object_number, relative_fno, block_number, row_number, callback) {
// Parameter Description
// rowid_type Type (restricted or extended), set the rowid_type parameter to 0 for a restricted ROWID. Set it to 1 to create an extended ROWID.
// If you specify rowid_type as 0, then the required object_number parameter is ignored, and ROWID_CREATE returns a restricted ROWID.
// object_number The data object number for the ROWID. For a restricted ROWID, use the ROWID_OBJECT_UNDEFINED constant.
// relative_fno The relative file number for the ROWID.
// block_number The block number for the ROWID.
// row_number The row number for the ROWID.
let myRowid = "";
connection.execute(
"select DBMS_ROWID.ROWID_CREATE(" + rowid_type + ", " + object_number + ", " + relative_fno + ", " + block_number + ", " + row_number + ") create_rowid from dual",
function(err, result) {
should.not.exist(err);
myRowid = result.rows[0][0];
callback(myRowid);
}
);
};
const appendSql = function(sql, col_name, col_type, isLast) {
if (isLast === true) {
sql = sql + " " + col_name + " " + col_type + " \n";
} else {
sql = sql + " " + col_name + " " + col_type + ", \n";
}
return sql;
};

View File

@ -34,36 +34,26 @@
"use strict"; "use strict";
const oracledb = require('oracledb'); const oracledb = require('oracledb');
const should = require('should'); const assert = require('assert');
const async = require('async');
const dbConfig = require('./dbconfig.js'); const dbConfig = require('./dbconfig.js');
describe('64. sqlWithWarnings.js', function() { describe('64. sqlWithWarnings.js', function() {
let connection = null; let connection = null;
before('get one connection', function(done) { before('get one connection', async function() {
oracledb.getConnection(dbConfig, connection = await oracledb.getConnection(dbConfig);
function(err, conn) {
should.not.exist(err);
connection = conn;
done();
}
);
}); });
after('release connection', function(done) { after('release connection', async function() {
connection.close(function(err) { await connection.close();
should.not.exist(err);
done();
});
}); });
describe('64.1 test case offered by GitHub user', function() { describe('64.1 test case offered by GitHub user', function() {
var tableName = "nodb_aggregate"; const tableName = "nodb_aggregate";
before('prepare table', function(done) { before('prepare table', async function() {
var sqlCreateTab = const sqlCreateTab =
"BEGIN " + "BEGIN " +
" DECLARE " + " DECLARE " +
" e_table_missing EXCEPTION; " + " e_table_missing EXCEPTION; " +
@ -81,86 +71,39 @@ describe('64. sqlWithWarnings.js', function() {
" '); " + " '); " +
"END; "; "END; ";
async.series([ await connection.execute(sqlCreateTab);
function(cb) { await connection.execute("INSERT INTO " + tableName + " VALUES(1)");
connection.execute( await connection.execute("INSERT INTO " + tableName + " VALUES(null)");
sqlCreateTab, await connection.commit();
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
"INSERT INTO " + tableName + " VALUES(1)",
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.execute(
"INSERT INTO " + tableName + " VALUES(null)",
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.commit(function(err) {
should.not.exist(err);
cb();
});
}
], done);
}); // before }); // before
after(function(done) { after(async function() {
connection.execute( await connection.execute("DROP TABLE " + tableName + " PURGE");
"DROP TABLE " + tableName + " PURGE",
function(err) {
should.not.exist(err);
done();
}
);
}); });
it('64.1.1 Executes an aggregate query which causes warnings', function(done) { it('64.1.1 Executes an aggregate query which causes warnings', async function() {
connection.execute( await connection.execute(
"SELECT MAX(NUM_COL) AS NUM_COL FROM " + tableName, "SELECT MAX(NUM_COL) AS NUM_COL FROM " + tableName,
[], [],
{ maxRows: 1 }, { maxRows: 1 }
function(err) {
should.not.exist(err);
done();
}
); );
}); }); // 64.1.1
}); // 64.1 }); // 64.1
describe('64.2 PL/SQL - Success With Info', function() { describe('64.2 PL/SQL - Success With Info', function() {
var plsqlWithWarning = const plsqlWithWarning =
" CREATE OR REPLACE PROCEDURE get_emp_rs_inout " + " CREATE OR REPLACE PROCEDURE get_emp_rs_inout " +
" (p_in IN NUMBER, p_out OUT SYS_REFCURSOR ) AS " + " (p_in IN NUMBER, p_out OUT SYS_REFCURSOR ) AS " +
" BEGIN " + " BEGIN " +
" OPEN p_out FOR SELECT * FROM nodb_sql_emp " + " OPEN p_out FOR SELECT * FROM nodb_sql_emp " +
" END;"; " END;";
it('64.2.1 Execute SQL Statement to create PLSQL procedure with warnings', function(done) { it('64.2.1 Execute SQL Statement to create PLSQL procedure with warnings', async function() {
connection.should.be.an.Object; assert.strictEqual(typeof connection, "object");
connection.execute ( await connection.execute (plsqlWithWarning);
plsqlWithWarning, }); // 64.2.1
function(err) {
should.not.exist (err);
done();
}
);
});
}); // 64.2 }); // 64.2