Test files refactored

This commit is contained in:
Sharad Chandran R 2023-03-14 12:03:48 +05:30
parent 87e106a7a5
commit 782d16f697
27 changed files with 1123 additions and 2308 deletions

View File

@ -37,8 +37,7 @@
'use strict';
const oracledb = require('oracledb');
const async = require('async');
const should = require('should');
const assert = require('assert');
const stream = require('stream');
const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js');
@ -46,161 +45,87 @@ const assist = require('./dataTypeAssist.js');
describe('60. clobPlsqlString.js', function() {
let connection = null;
var tableName = "nodb_myclobs";
const tableName = `nodb_myclobs`;
before('get one connection, prepare table', function(done) {
async.series([
function(callback) {
oracledb.getConnection(
dbConfig,
function(err, conn) {
should.not.exist(err);
connection = conn;
callback();
}
);
},
function(callback) {
assist.createTable(connection, tableName, callback);
}
], done);
before('get one connection, prepare table', async function() {
connection = await oracledb.getConnection(dbConfig);
await connection.execute(assist.sqlCreateTable(tableName));
}); // before
after('release connection', function(done) {
async.series([
function(callback) {
connection.execute(
"DROP TABLE nodb_myclobs purge",
function(err) {
should.not.exist(err);
callback();
}
);
},
function(callback) {
connection.close(function(err) {
should.not.exist(err);
callback();
});
}
], done);
after('release connection', async function() {
await connection.execute(`DROP TABLE nodb_myclobs purge`);
await connection.close();
}); // after
describe('60.1 BIND OUT as STRING', function() {
before('insert data', function(done) {
connection.execute(
"INSERT INTO nodb_myclobs (num, content) VALUES (1, 'abcdefghijklmnopqrstuvwxyz')",
function(err) {
should.not.exist(err);
done();
}
);
before('insert data', async function() {
await connection.execute(`INSERT INTO nodb_myclobs (num, content) VALUES (1, 'abcdefghijklmnopqrstuvwxyz')`);
}); // before
it('60.1.1 PL/SQL OUT CLOB parameters can also be bound as STRING', function(done) {
connection.execute(
"BEGIN SELECT content INTO :cbv FROM nodb_myclobs WHERE num = :id; END;",
it('60.1.1 PL/SQL OUT CLOB parameters can also be bound as STRING', async function() {
let result = await connection.execute(`BEGIN SELECT content INTO :cbv FROM nodb_myclobs WHERE num = :id; END;`,
{
id: 1,
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT}
},
function(err, result) {
should.not.exist(err);
(result.outBinds.cbv).should.be.a.String();
(result.outBinds.cbv).should.eql('abcdefghijklmnopqrstuvwxyz');
done();
}
);
});
assert.strictEqual(typeof result.outBinds.cbv, "string");
assert.strictEqual(result.outBinds.cbv, 'abcdefghijklmnopqrstuvwxyz');
}); // 60.1.1
it('60.1.2 The returned length is limited to the maximum size', function(done) {
connection.execute(
"BEGIN SELECT content INTO :cbv FROM nodb_myclobs WHERE num = :id; END;",
{
id: 1,
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 5 }
it('60.1.2 The returned length is limited to the maximum size', async function() {
await assert.rejects(
async () => {
await connection.execute(`BEGIN SELECT content INTO :cbv FROM nodb_myclobs WHERE num = :id; END;`,
{
id: 1,
cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 5 }});
},
function(err, result) {
should.exist(err);
(err.message).should.startWith('ORA-06502'); // PL/SQL: numeric or value error
should.not.exist(result);
done();
}
/ORA-06502:/ // PL/SQL: numeric or value error
);
}); // 60.1.2
}); // 60.1
describe('60.2 BIND OUT as CLOB', function() {
var dataLength = 1000000;
var rawData = assist.createCharString(dataLength);
const dataLength = 1000000;
const rawData = assist.createCharString(dataLength);
it('60.2.1 maxSize option does not take effect when bind out type is clob', function(done) {
async.series([
function doInsert(callback) {
connection.execute(
"INSERT INTO " + tableName + " VALUES (2, EMPTY_CLOB()) RETURNING content INTO :lobbv",
{ lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
{ autoCommit: false },
function(err, result) {
should.not.exist(err);
it('60.2.1 maxSize option does not take effect when bind out type is clob', async function() {
var lob = result.outBinds.lobbv[0];
lob.on('error', function(err) {
should.not.exist(err);
return callback(err);
});
let result = await connection.execute(
`INSERT INTO ` + tableName + ` VALUES (2, EMPTY_CLOB()) RETURNING content INTO :lobbv`,
{ lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
{ autoCommit: false });
var inStream = new stream.Readable();
inStream._read = function noop() {};
inStream.push(rawData);
inStream.push(null);
const lob = result.outBinds.lobbv[0];
inStream.on('error', function(err) {
should.not.exist(err);
return callback(err);
});
await new Promise((resolve, reject) => {
inStream.on('end', function() {
connection.commit(function(err) {
should.not.exist(err);
callback();
});
});
lob.on("error", reject);
inStream.pipe(lob);
}
);
},
function doQuery(callback) {
connection.execute(
"BEGIN SELECT content INTO :bv FROM " + tableName + " WHERE num = 2; END;",
{ bv: {dir: oracledb.BIND_OUT, type: oracledb.CLOB} },
{ maxRows: 500 },
function(err, result) {
should.not.exist(err);
let inStream = new stream.Readable();
inStream._read = function noop() {};
inStream.push(rawData);
inStream.push(null);
var content = '';
var lob = result.outBinds.bv;
lob.setEncoding('utf8');
inStream.on('error', reject);
lob.on('data', function(chunk) {
content += chunk;
});
inStream.on('end', resolve);
lob.on('end', function() {
(content.length).should.be.exactly(dataLength);
(content).should.eql(rawData);
callback();
});
inStream.pipe(lob);
});
await connection.commit();
lob.on('error', function(err) {
should.not.exist(err);
});
}
);
}
], done);
});
}); // 60.2
result = await connection.execute(
"BEGIN SELECT content INTO :bv FROM " + tableName + " WHERE num = 2; END;",
{ bv: {dir: oracledb.BIND_OUT, type: oracledb.CLOB} },
{ maxRows: 500 }
);
const content = await result.outBinds.bv.getData();
assert.strictEqual(content.length, dataLength);
assert.strictEqual(content, rawData);
}); // 60.2
});
});

View File

@ -32,10 +32,9 @@
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const async = require('async');
const assert = require('assert');
var assist = exports;
const assist = exports;
/* Mapping between table names and data types */
assist.allDataTypeNames =
@ -618,7 +617,7 @@ assist.schema = {
/******************************* Helper Functions ***********************************/
var StringBuffer = function() {
const StringBuffer = function() {
this.buffer = [];
this.index = 0;
};
@ -636,11 +635,11 @@ StringBuffer.prototype = {
};
assist.createCharString = function(size) {
var buffer = new StringBuffer();
var scSize = assist.data.specialChars.length;
var scIndex = 0;
var cIndex = 0;
for (var i = 0; i < size; i++) {
const buffer = new StringBuffer();
const scSize = assist.data.specialChars.length;
let scIndex = 0;
let cIndex = 0;
for (let i = 0; i < size; i++) {
if (i % 10 == 0) {
buffer.append(assist.data.specialChars[scIndex].substr(0, 1));
scIndex = (scIndex + 1) % scSize;
@ -653,22 +652,22 @@ assist.createCharString = function(size) {
};
assist.createBuffer = function(size) {
var array = [];
for (var i = 0; i < size; i++) {
var b = Math.floor(Math.random() * 256); // generate a random integer among 0-255
const array = [];
for (let i = 0; i < size; i++) {
const b = Math.floor(Math.random() * 256); // generate a random integer among 0-255
array.push(b);
}
return Buffer.from(array, "utf-8");
};
assist.createSchemaString = function(size) {
var buffer = new StringBuffer();
var scIndex = 0;
var cIndex = 0;
var nIndex = 0;
var schema_prefix = "\"";
const buffer = new StringBuffer();
const schema_prefix = "\"";
let scIndex = 0;
let cIndex = 0;
let nIndex = 0;
for (var i = 0; i < size - 2; i++) {
for (let i = 0; i < size - 2; i++) {
if (i % 3 == 0) {
scIndex = Math.floor(Math.random() * 30);
buffer.append(assist.schema.specialChars[scIndex]);
@ -680,93 +679,44 @@ assist.createSchemaString = function(size) {
buffer.append(assist.schema.numbers[nIndex]);
}
}
var schema = schema_prefix + buffer.toString() + schema_prefix;
return schema;
return schema_prefix + buffer.toString() + schema_prefix;
};
assist.compare2Buffers = function(originalBuf, compareBuf) {
var node01113plus = true; // assume node runtime version is higher than 0.11.13
var nodeVer = process.versions["node"].split(".");
if (nodeVer[0] === "0" && nodeVer[1] === "11" && nodeVer[2] < "13") {
node01113plus = false;
} else if (nodeVer[0] === "0" && nodeVer[1] < "11") {
node01113plus = false;
}
if (node01113plus === true) {
return originalBuf.equals(compareBuf);
} else {
return (originalBuf.toString('utf8') === compareBuf.toString('utf8'));
}
return originalBuf.equals(compareBuf);
};
assist.setUp = function(connection, tableName, array, done) {
async.series([
function(callback) {
assist.createTable(connection, tableName, callback);
},
function(callback) {
assist.insertDataArray(connection, tableName, array, callback);
}
], done);
assist.setUp = async function(connection, tableName, array) {
await assist.createTable(connection, tableName);
await assist.insertDataArray(connection, tableName, array);
};
assist.setUp4sql = function(connection, tableName, array, done) {
async.series([
function(callback) {
assist.createTable(connection, tableName, callback);
},
function(callback) {
assist.insertData4sql(connection, tableName, array, callback);
}
], done);
assist.setUp4sql = async function(connection, tableName, array) {
await assist.createTable(connection, tableName);
await assist.insertData4sql(connection, tableName, array);
};
assist.createTable = function(connection, tableName, done) {
var sqlCreate = assist.sqlCreateTable(tableName);
connection.execute(
sqlCreate,
function(err) {
should.not.exist(err);
done();
}
);
assist.createTable = async function(connection, tableName) {
const sqlCreate = assist.sqlCreateTable(tableName);
await connection.execute(sqlCreate);
};
assist.insertDataArray = function(connection, tableName, array, done) {
async.eachSeries(array, function(element, cb) {
// console.log(element.length);
connection.execute(
"INSERT INTO " + tableName + " VALUES(:no, :bindValue)",
assist.insertDataArray = async function(connection, tableName, array) {
await Promise.all(array.map(async function(element) {
await connection.execute(
`INSERT INTO ` + tableName + ` VALUES(:no, :bindValue)`,
{ no: array.indexOf(element), bindValue: element },
{ autoCommit: true },
function(err) {
should.not.exist(err);
cb();
}
);
}, function(err) {
should.not.exist(err);
done();
});
{ autoCommit: true });
}));
};
assist.insertData4sql = function(connection, tableName, array, done) {
async.eachSeries(array, function(element, cb) {
var sql = "INSERT INTO " + tableName + " VALUES(:no, " + element + " )";
connection.execute(
sql,
{ no: array.indexOf(element) },
function(err) {
should.not.exist(err);
cb();
}
);
}, function(err) {
should.not.exist(err);
done();
});
assist.insertData4sql = async function(connection, tableName, array) {
await Promise.all(array.map(async function(element) {
const sql = "INSERT INTO " + tableName + " VALUES(:no, " + element + " )";
const binds = { no: array.indexOf(element) };
await connection.execute(sql, binds);
}));
};
assist.sqlCreateTable = function(tableName) {
@ -774,7 +724,7 @@ assist.sqlCreateTable = function(tableName) {
// is disabled for tables with LONG & LONG RAW columns in all types of Oracle DB.
// (Note: HCC is enabled in Oracle ADB-S and ADB-D by default)
// When HCC is enabled, tables with LONG & LONG RAW columns cannot be created.
var createTab =
const createTab =
`BEGIN
DECLARE
e_table_missing EXCEPTION;
@ -799,253 +749,151 @@ assist.sqlCreateTable = function(tableName) {
/************************* Functions for Verifiction *********************************/
assist.dataTypeSupport = function(connection, tableName, array, done) {
connection.should.be.ok();
connection.execute(
"SELECT * FROM " + tableName + " ORDER BY num",
assist.dataTypeSupport = async function(connection, tableName, array) {
const result = await connection.execute(
`SELECT * FROM ` + tableName + ` ORDER BY num`,
[],
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
function(err, result) {
should.not.exist(err);
// console.log(result);
for (var i = 0; i < array.length; i++) {
// console.log(result.rows[i].CONTENT);
if ((typeof result.rows[i].CONTENT) === 'string')
result.rows[i].CONTENT.trim().should.eql(array[result.rows[i].NUM]);
else if ((typeof result.rows[i].CONTENT) === 'number')
result.rows[i].CONTENT.should.eql(array[result.rows[i].NUM]);
else if (Buffer.isBuffer(result.rows[i].CONTENT))
result.rows[i].CONTENT.toString('hex').should.eql(array[result.rows[i].NUM].toString('hex'));
else if (Object.prototype.toString.call(result.rows[i].CONTENT) === '[object Date]')
result.rows[i].CONTENT.getTime().should.eql(array[result.rows[i].NUM].getTime());
else if (typeof result.rows[i].CONTENT === 'object')
should.deepEqual(result.rows[i].CONTENT, assist.jsonExpectedResults[result.rows[i].NUM]);
else
should.not.exist(new Error('Uncaught data type!'));
}
done();
}
);
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
for (let i = 0; i < array.length; i++) {
// console.log(result.rows[i].CONTENT);
if ((typeof result.rows[i].CONTENT) === 'string')
assert.strictEqual(result.rows[i].CONTENT.trim(), array[result.rows[i].NUM]);
else if ((typeof result.rows[i].CONTENT) === 'number')
assert.strictEqual(result.rows[i].CONTENT, array[result.rows[i].NUM]);
else if (Buffer.isBuffer(result.rows[i].CONTENT))
assert.strictEqual(result.rows[i].CONTENT.toString('hex'), array[result.rows[i].NUM].toString('hex'));
else if (Object.prototype.toString.call(result.rows[i].CONTENT) === '[object Date]')
assert.strictEqual(result.rows[i].CONTENT.getTime(), array[result.rows[i].NUM].getTime());
else if (typeof result.rows[i].CONTENT === 'object')
assert.deepEqual(result.rows[i].CONTENT, assist.jsonExpectedResults[result.rows[i].NUM]);
else
assert.ifError(new Error('Uncaught data type!'));
}
};
assist.verifyResultSet = function(connection, tableName, array, done) {
connection.execute(
assist.verifyResultSet = async function(connection, tableName, array) {
const result = await connection.execute(
"SELECT * FROM " + tableName,
[],
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT },
function(err, result) {
should.not.exist(err);
(result.resultSet.metaData[0]).name.should.eql('NUM');
(result.resultSet.metaData[1]).name.should.eql('CONTENT');
fetchRowsFromRS(result.resultSet, array, done);
}
);
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT });
assert.strictEqual((result.resultSet.metaData[0]).name, 'NUM');
assert.strictEqual((result.resultSet.metaData[1]).name, 'CONTENT');
await fetchRowsFromRS(result.resultSet, array);
};
assist.verifyRefCursor = function(connection, tableName, array, done) {
var createProc =
"CREATE OR REPLACE PROCEDURE testproc (p_out OUT SYS_REFCURSOR) " +
"AS " +
"BEGIN " +
" OPEN p_out FOR " +
"SELECT * FROM " + tableName + "; " +
"END; ";
async.series([
function createProcedure(callback) {
connection.execute(
createProc,
function(err) {
should.not.exist(err);
callback();
}
);
},
function verify(callback) {
connection.execute(
"BEGIN testproc(:o); END;",
[
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
],
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
function(err, result) {
should.not.exist(err);
fetchRowsFromRS(result.outBinds[0], array, callback);
}
);
},
function dropProcedure(callback) {
connection.execute(
"DROP PROCEDURE testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
assist.verifyRefCursor = async function(connection, tableName, array) {
const createProc =
`CREATE OR REPLACE PROCEDURE testproc (p_out OUT SYS_REFCURSOR) ` +
`AS ` +
`BEGIN ` +
` OPEN p_out FOR ` +
`SELECT * FROM ` + tableName + `; ` +
`END; `;
await connection.execute(createProc);
const result = await connection.execute(
`BEGIN testproc(:o); END;`,
[
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
],
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
await fetchRowsFromRS(result.outBinds[0], array);
await connection.execute(`DROP PROCEDURE testproc`);
};
function fetchRowsFromRS(rs, array, cb) {
var numRows = 3;
rs.getRows(numRows, function(err, rows) {
if (rows.length > 0) {
for (var i = 0; i < rows.length; i++) {
if ((typeof rows[i].CONTENT) === 'string')
rows[i].CONTENT.trim().should.eql(array[rows[i].NUM]);
else if ((typeof rows[i].CONTENT) === 'number')
rows[i].CONTENT.should.eql(array[rows[i].NUM]);
else if (Buffer.isBuffer(rows[i].CONTENT))
rows[i].CONTENT.toString('hex').should.eql(array[rows[i].NUM].toString('hex'));
else if (Object.prototype.toString.call(rows[i].CONTENT) === '[object Date]')
rows[i].CONTENT.getTime().should.eql(array[rows[i].NUM].getTime());
else if (typeof rows[i].CONTENT === 'object')
should.deepEqual(rows[i].CONTENT, assist.jsonExpectedResults[rows[i].NUM]);
else
should.not.exist(new Error('Uncaught data type!'));
}
return fetchRowsFromRS(rs, array, cb);
} else {
rs.close(function(err) {
should.not.exist(err);
cb();
});
async function fetchRowsFromRS(rs, array) {
const numRows = 3;
const rows = await rs.getRows(numRows);
if (rows.length > 0) {
for (let i = 0; i < rows.length; i++) {
if ((typeof rows[i].CONTENT) === 'string')
assert.strictEqual(rows[i].CONTENT.trim(), array[rows[i].NUM]);
else if ((typeof rows[i].CONTENT) === 'number')
assert.strictEqual(rows[i].CONTENT, array[rows[i].NUM]);
else if (Buffer.isBuffer(rows[i].CONTENT))
assert.strictEqual(rows[i].CONTENT.toString('hex'), array[rows[i].NUM].toString('hex'));
else if (Object.prototype.toString.call(rows[i].CONTENT) === '[object Date]')
assert.strictEqual(rows[i].CONTENT.getTime(), array[rows[i].NUM].getTime());
else if (typeof rows[i].CONTENT === 'object')
assert.deepEqual(rows[i].CONTENT, assist.jsonExpectedResults[rows[i].NUM]);
else
assert.ifError(new Error('Uncaught data type!'));
}
});
return fetchRowsFromRS(rs, array);
} else {
await rs.close();
}
}
assist.selectOriginalData = function(connection, tableName, array, done) {
async.eachSeries(array, function(element, cb) {
connection.execute(
"SELECT * FROM " + tableName + " WHERE num = :no",
{ no: array.indexOf(element) },
function(err) {
should.not.exist(err);
// console.log(result.rows);
cb();
}
);
}, function(err) {
should.not.exist(err);
done();
});
assist.selectOriginalData = async function(connection, tableName, array) {
await Promise.all(array.map(async function(element) {
await connection.execute(
`SELECT * FROM ` + tableName + ` WHERE num = :no`,
{ no: array.indexOf(element) });
}));
};
/* Null value verfication */
assist.verifyNullValues = function(connection, tableName, done) {
var sqlInsert = "INSERT INTO " + tableName + " VALUES(:no, :bindValue)";
assist.verifyNullValues = async function(connection, tableName) {
const sqlInsert = `INSERT INTO ` + tableName + ` VALUES(:no, :bindValue)`;
connection.should.be.ok();
async.series([
function createTable(callback) {
var sqlCreate = assist.sqlCreateTable(tableName);
connection.execute(
sqlCreate,
function(err) {
should.not.exist(err);
callback();
}
);
},
function JSEmptyString(callback) {
var num = 1;
connection.execute(
sqlInsert,
{ no: num, bindValue: '' },
function(err) {
should.not.exist(err);
verifyNull(num, callback);
}
);
},
function JSNull(callback) {
var num = 2;
connection.execute(
sqlInsert,
{ no: num, bindValue: null },
function(err) {
should.not.exist(err);
verifyNull(num, callback);
}
);
},
function JSUndefined(callback) {
var num = 3;
var foobar; // undefined value
connection.execute(
sqlInsert,
{ no: num, bindValue: foobar },
function(err) {
should.not.exist(err);
verifyNull(num, callback);
}
);
},
function sqlNull(callback) {
var num = 4;
connection.execute(
"INSERT INTO " + tableName + " VALUES(:1, NULL)",
[num],
function(err) {
should.not.exist(err);
verifyNull(num, callback);
}
);
},
function sqlEmpty(callback) {
var num = 5;
connection.execute(
"INSERT INTO " + tableName + " VALUES(:1, '')",
[num],
function(err) {
should.not.exist(err);
verifyNull(num, callback);
}
);
},
function sqlNullColumn(callback) {
var num = 6;
connection.execute(
"INSERT INTO " + tableName + "(num) VALUES(:1)",
[num],
function(err) {
should.not.exist(err);
verifyNull(num, callback);
}
);
},
function dropTable(callback) {
connection.execute(
"DROP table " + tableName + " PURGE",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
const sqlCreate = await assist.sqlCreateTable(tableName);
await connection.execute(sqlCreate);
let num = 1;
await connection.execute(
sqlInsert,
{ no: num, bindValue: '' });
await verifyNull(num);
function verifyNull(id, cb) {
connection.execute(
"SELECT content FROM " + tableName + " WHERE num = :1",
[id],
function(err, result) {
should.not.exist(err);
// console.log(result);
result.rows.should.eql([ [null] ]);
cb();
}
);
num = 2;
await connection.execute(
sqlInsert,
{ no: num, bindValue: null });
await verifyNull(num);
num = 3;
await connection.execute(
sqlInsert,
{ no: num, bindValue: undefined });
await verifyNull(num);
num = 4;
await connection.execute(
`INSERT INTO ` + tableName + ` VALUES(:1, NULL)`,
[num]);
await verifyNull(num);
num = 5;
await connection.execute(
`INSERT INTO ` + tableName + ` VALUES(:1, '')`,
[num]);
await verifyNull(num);
num = 6;
await connection.execute(`INSERT INTO ` + tableName + `(num) VALUES(:1)`,
[num]);
await verifyNull(num);
await connection.execute(`DROP table ` + tableName + ` PURGE`);
async function verifyNull(id) {
const result = await connection.execute(`SELECT content FROM ` + tableName + ` WHERE num = :1`,
[id]);
assert.deepEqual(result.rows, [ [null] ]);
}
};
assist.compareNodejsVersion = function(nowVersion, comparedVersion) {
// return true if nowVersion > or = comparedVersion;
// else return false;
var now = nowVersion.split(".");
var compare = comparedVersion.split(".");
const now = nowVersion.split(".");
const compare = comparedVersion.split(".");
if (now[0] > compare[0]) {
return true;
} else if (now[0] === compare[0] && now[1] > compare[1]) {
@ -1059,126 +907,77 @@ assist.compareNodejsVersion = function(nowVersion, comparedVersion) {
}
};
assist.verifyRefCursorWithFetchInfo = function(connection, tableName, array, done) {
var createProc =
"CREATE OR REPLACE PROCEDURE testproc (p_out OUT SYS_REFCURSOR) " +
"AS " +
"BEGIN " +
" OPEN p_out FOR " +
"SELECT * FROM " + tableName + "; " +
"END; ";
async.series([
function createProcedure(callback) {
connection.execute(
createProc,
function(err) {
should.not.exist(err);
callback();
}
);
assist.verifyRefCursorWithFetchInfo = async function(connection, tableName, array) {
const createProc =
`CREATE OR REPLACE PROCEDURE testproc (p_out OUT SYS_REFCURSOR) ` +
`AS ` +
`BEGIN ` +
` OPEN p_out FOR ` +
`SELECT * FROM ` + tableName + `; ` +
`END; `;
await connection.execute(createProc);
const result = await connection.execute(
`begin testproc(:out); end;`,
{
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function verify(callback) {
connection.execute(
"begin testproc(:out); end;",
{
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchInfo:
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchInfo:
{
"CONTENT": { type: oracledb.STRING }
}
},
function(err, result) {
should.not.exist(err);
_verifyFetchedValues(connection, result.outBinds.out, array, tableName, callback);
}
);
},
function dropProcedure(callback) {
connection.execute(
"DROP PROCEDURE testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
});
await _verifyFetchedValues(connection, result.outBinds.out, array, tableName);
await connection.execute(`DROP PROCEDURE testproc`);
};
assist.verifyRefCursorWithFetchAsString = function(connection, tableName, array, done) {
var createProc =
"CREATE OR REPLACE PROCEDURE testproc (p_out OUT SYS_REFCURSOR) " +
"AS " +
"BEGIN " +
" OPEN p_out FOR " +
"SELECT * FROM " + tableName + "; " +
"END; ";
async.series([
function createProcedure(callback) {
connection.execute(
createProc,
function(err) {
should.not.exist(err);
callback();
}
);
assist.verifyRefCursorWithFetchAsString = async function(connection, tableName, array) {
const createProc =
`CREATE OR REPLACE PROCEDURE testproc (p_out OUT SYS_REFCURSOR) ` +
`AS ` +
`BEGIN ` +
` OPEN p_out FOR ` +
`SELECT * FROM ` + tableName + `; ` +
`END; `;
await connection.execute(createProc);
const result = await connection.execute(
`begin testproc(:out); end;`,
{
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function verify(callback) {
connection.execute(
"begin testproc(:out); end;",
{
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
function(err, result) {
should.not.exist(err);
_verifyFetchedValues(connection, result.outBinds.out, array, tableName, callback);
}
);
},
function dropProcedure(callback) {
connection.execute(
"DROP PROCEDURE testproc",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
await _verifyFetchedValues(connection, result.outBinds.out, array, tableName);
await connection.execute(`DROP PROCEDURE testproc`);
};
var _verifyFetchedValues = function(connection, rs, array, tableName, cb) {
var amount = array.length;
rs.getRows(amount, function(err, rows) {
async.eachSeries(
rows,
queryAndCompare,
function(err) {
should.not.exist(err);
rs.close(function(err) {
should.not.exist(err);
return cb();
});
}
);
});
const _verifyFetchedValues = async function(connection, rs, array, tableName) {
const amount = array.length;
const rows = await rs.getRows(amount);
var queryAndCompare = function(row, callback) {
var sql = "select content from " + tableName + " where num = " + row.NUM;
connection.execute(
const queryAndCompare = async function(row) {
const sql = `select content from ` + tableName + ` where num = ` + row.NUM;
const result = await connection.execute(
sql,
[],
{ fetchInfo: { "CONTENT": { type: oracledb.STRING } } },
function(err, result) {
should.strictEqual(row.CONTENT, result.rows[0][0]);
return callback(err);
}
);
{ fetchInfo: { "CONTENT": { type: oracledb.STRING } } });
assert.strictEqual(row.CONTENT, result.rows[0][0]);
};
}; // _verifyFetchedValues()
await Promise.all(rows.map(async function(row) {
await queryAndCompare(row);
}));
await rs.close();
}; // await _verifyFetchedValues()
module.exports = assist;

View File

@ -54,9 +54,8 @@ describe('31. dataTypeBinaryDouble.js', function() {
let numbers = assist.data.numbersForBinaryFloat.concat(assist.data.numbersForBinaryDouble);
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, numbers, resolve);
});
await assist.setUp(connection, tableName, numbers);
});
after(async function() {
@ -65,43 +64,37 @@ describe('31. dataTypeBinaryDouble.js', function() {
});
it('31.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, numbers, resolve);
});
await assist.dataTypeSupport(connection, tableName, numbers);
});
it('31.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, numbers, resolve);
});
await assist.verifyResultSet(connection, tableName, numbers);
});
it('31.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursor(connection, tableName, numbers);
});
it('31.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers);
});
it('31.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.NUMBER ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers);
});
});
describe('31.2 stores null value correctly', function() {
it('31.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -113,9 +106,8 @@ describe('31. dataTypeBinaryDouble.js', function() {
];
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, nums, resolve);
});
await assist.setUp(connection, tableName, nums);
});
after(async function() {

View File

@ -54,9 +54,7 @@ describe('30. dataTypeBinaryFloat.js', function() {
let numbers = assist.data.numbersForBinaryFloat;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, numbers, resolve);
});
await assist.setUp(connection, tableName, numbers);
});
after(async function() {
@ -65,43 +63,31 @@ describe('30. dataTypeBinaryFloat.js', function() {
});
it('30.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, numbers, resolve);
});
await assist.dataTypeSupport(connection, tableName, numbers);
});
it('30.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, numbers, resolve);
});
await assist.verifyResultSet(connection, tableName, numbers);
});
it('30.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursor(connection, tableName, numbers);
});
it('30.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers);
});
it('30.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.NUMBER ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers);
});
}); // 30.1
describe('30.2 stores null value correctly', function() {
it('30.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -115,9 +101,7 @@ describe('30. dataTypeBinaryFloat.js', function() {
];
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, nums, resolve);
});
await assist.setUp(connection, tableName, nums);
});
after(async function() {

View File

@ -53,9 +53,7 @@ describe('32. dataTypeDate.js', function() {
let dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -69,43 +67,31 @@ describe('32. dataTypeDate.js', function() {
if (dates[i].getMilliseconds() > 0)
dates[i].setMilliseconds(0);
}
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('32.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('32.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('32.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('32.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // 32.1 suite
describe('32.2 stores null value correctly', function() {
it('32.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -113,9 +99,7 @@ describe('32. dataTypeDate.js', function() {
let dates = assist.DATE_STRINGS;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, dates, resolve);
});
await assist.setUp4sql(connection, tableName, dates);
});
after(async function() {
@ -123,9 +107,7 @@ describe('32. dataTypeDate.js', function() {
});
it('32.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, dates, resolve);
});
await assist.selectOriginalData(connection, tableName, dates);
});
it('32.3.2 SELECT query - formatted data for comparison', async function() {

View File

@ -32,75 +32,59 @@
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const assist = require('./dataTypeAssist.js');
const dbConfig = require('./dbconfig.js');
describe('28. dataTypeFloat.js', function() {
let connection = null;
var tableName = "nodb_float";
var numbers = assist.data.numbers;
const tableName = "nodb_float";
const numbers = assist.data.numbers;
before('get one connection', function(done) {
oracledb.getConnection(dbConfig,
function(err, conn) {
assert.ifError(err);
connection = conn;
done();
}
);
before('get one connection', async function() {
connection = await oracledb.getConnection(dbConfig);
});
after('release connection', function(done) {
after('release connection', async function() {
oracledb.fetchAsString = [];
connection.close(function(err) {
assert.ifError(err);
done();
});
await connection.close();
});
describe('28.1 testing FLOAT data type', function() {
before('create table, insert data', function(done) {
assist.setUp(connection, tableName, numbers, done);
before('create table, insert data', async function() {
await assist.setUp(connection, tableName, numbers);
});
after(function(done) {
connection.execute(
"DROP table " + tableName + " PURGE",
function(err) {
assert.ifError(err);
done();
}
);
after(async function() {
await connection.execute(`DROP table ` + tableName + ` PURGE`);
});
it('28.1.1 works well with SELECT query', function(done) {
assist.dataTypeSupport(connection, tableName, numbers, done);
it('28.1.1 works well with SELECT query', async function() {
await assist.dataTypeSupport(connection, tableName, numbers);
});
it('28.1.2 works well with result set', function(done) {
assist.verifyResultSet(connection, tableName, numbers, done);
it('28.1.2 works well with result set', async function() {
await assist.verifyResultSet(connection, tableName, numbers);
});
it('28.1.3 works well with REF Cursor', function(done) {
assist.verifyRefCursor(connection, tableName, numbers, done);
it('28.1.3 works well with REF Cursor', async function() {
await assist.verifyRefCursor(connection, tableName, numbers);
});
it('28.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, done);
it('28.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers);
});
it('28.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
it('28.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.NUMBER ];
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, done);
await assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers);
});
});
describe('28.2 stores null value correctly', function() {
it('28.2.1 testing Null, Empty string and Undefined', function(done) {
assist.verifyNullValues(connection, tableName, done);
it('28.2.1 testing Null, Empty string and Undefined', async function() {
await assist.verifyNullValues(connection, tableName);
});
});
});

View File

@ -32,75 +32,59 @@
'use strict';
const oracledb = require('oracledb');
const assert = require('assert');
const assist = require('./dataTypeAssist.js');
const dbConfig = require('./dbconfig.js');
describe('29. dataTypeFloat2.js', function() {
let connection = null;
var tableName = "nodb_float2";
var numbers = assist.data.numbers;
const tableName = "nodb_float2";
const numbers = assist.data.numbers;
before('get one connection', function(done) {
oracledb.getConnection(dbConfig,
function(err, conn) {
assert.ifError(err);
connection = conn;
done();
}
);
before('get one connection', async function() {
connection = await oracledb.getConnection(dbConfig);
});
after('release connection', function(done) {
connection.close(function(err) {
assert.ifError(err);
done();
});
after('release connection', async function() {
await connection.close();
});
describe('29.1 testing FLOAT(p) data type', function() {
before('create table, insert data', function(done) {
assist.setUp(connection, tableName, numbers, done);
before('create table, insert data', async function() {
await assist.setUp(connection, tableName, numbers);
});
after(function(done) {
after(async function() {
oracledb.fetchAsString = [];
connection.execute(
"DROP table " + tableName + " PURGE",
function(err) {
assert.ifError(err);
done();
}
);
await connection.execute(`DROP table ` + tableName + ` PURGE`);
});
it('29.1.1 works well with SELECT query', function(done) {
assist.dataTypeSupport(connection, tableName, numbers, done);
it('29.1.1 works well with SELECT query', async function() {
await assist.dataTypeSupport(connection, tableName, numbers);
});
it('29.1.2 works well with result set', function(done) {
assist.verifyResultSet(connection, tableName, numbers, done);
it('29.1.2 works well with result set', async function() {
await assist.verifyResultSet(connection, tableName, numbers);
});
it('29.1.3 works well with REF Cursor', function(done) {
assist.verifyRefCursor(connection, tableName, numbers, done);
it('29.1.3 works well with REF Cursor', async function() {
await assist.verifyRefCursor(connection, tableName, numbers);
});
it('29.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', function(done) {
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, done);
it('29.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers);
});
it('29.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
it('29.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.NUMBER ];
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, done);
await assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers);
});
});
describe('29.2 stores null value correctly', function() {
it('29.2.1 testing Null, Empty string and Undefined', function(done) {
assist.verifyNullValues(connection, tableName, done);
it('29.2.1 testing Null, Empty string and Undefined', async function() {
await assist.verifyNullValues(connection, tableName);
});
});

File diff suppressed because it is too large Load Diff

View File

@ -53,9 +53,7 @@ describe('26. dataTypeNumber.js', function() {
describe('26.1 testing NUMBER data', function() {
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, numbers, resolve);
});
await assist.setUp(connection, tableName, numbers);
});
after(async function() {
@ -64,43 +62,31 @@ describe('26. dataTypeNumber.js', function() {
});
it('26.1.1 SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, numbers, resolve);
});
await assist.dataTypeSupport(connection, tableName, numbers);
});
it('26.1.2 resultSet stores NUMBER data correctly', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, numbers, resolve);
});
await assist.verifyResultSet(connection, tableName, numbers);
});
it('26.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursor(connection, tableName, numbers);
});
it('26.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, numbers);
});
it('26.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.NUMBER ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, numbers);
});
});
describe('26.2 stores null value correctly', function() {
it('26.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});

View File

@ -53,9 +53,7 @@ describe('27. dataTypeNumber2.js', function() {
describe('27.1 testing NUMBER(p, s) data', function() {
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, numbers, resolve);
});
await assist.setUp(connection, tableName, numbers);
});
after(async function() {
@ -109,9 +107,7 @@ describe('27. dataTypeNumber2.js', function() {
describe('27.2 stores null value correctly', function() {
it('27.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});

View File

@ -56,9 +56,7 @@ describe('25. dataTypeNvarchar2.js', function() {
describe('25.1 testing NVARCHAR2 data in various lengths', function() {
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, strs, resolve);
});
await assist.setUp(connection, tableName, strs);
});
after(async function() {
@ -66,35 +64,25 @@ describe('25. dataTypeNvarchar2.js', function() {
});
it('25.1.1 SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, strs, resolve);
});
await assist.dataTypeSupport(connection, tableName, strs);
});
it('25.1.2 resultSet stores NVARCHAR2 data correctly', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, strs, resolve);
});
await assist.verifyResultSet(connection, tableName, strs);
});
it('25.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, strs, resolve);
});
await assist.verifyRefCursor(connection, tableName, strs);
});
it('25.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, strs, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, strs);
});
});
describe('25.2 stores null value correctly', function() {
it('25.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
});

View File

@ -59,9 +59,7 @@ describe('42. dataTypeRaw.js', function() {
describe('42.1 testing RAW data in various lengths', function() {
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, bufs, resolve);
});
await assist.setUp(connection, tableName, bufs);
});
after(async function() {
@ -69,21 +67,15 @@ describe('42. dataTypeRaw.js', function() {
});
it('42.1.1 SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, bufs, resolve);
});
await assist.dataTypeSupport(connection, tableName, bufs);
});
it('42.1.2 resultSet stores RAW data correctly', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, bufs, resolve);
});
await assist.verifyResultSet(connection, tableName, bufs);
});
it('42.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, bufs, resolve);
});
await assist.verifyRefCursor(connection, tableName, bufs);
});
it('42.1.4 result set getRow() function works well with RAW', async function() {
@ -120,9 +112,7 @@ describe('42. dataTypeRaw.js', function() {
describe('42.2 stores null value correctly', function() {
it('42.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});

View File

@ -91,7 +91,9 @@ describe('39. dataTypeRowid.js', function() {
await connection.execute(
`update ` + tableName + ` set ROWID = CHARTOROWID('AAAspiAABAAAZnJAAE') where num = 1`);
},
/ORA-01747:/
/* ORA-01747: invalid user.table.column, table.column, or column specification
ORA-03050: invalid identifier: "ROWID" is a reserved word */
/ORA-01747: | ORA-03050:/
);
});
@ -141,7 +143,9 @@ describe('39. dataTypeRowid.js', function() {
await connection.execute(
`update ` + tableName + ` set ROWID = 'AAAspiAABAAAZnJAAE' where num = 1`);
},
/ORA-01747:/
/* ORA-01747: invalid user.table.column, table.column, or column specification
ORA-03050: invalid identifier: "ROWID" is a reserved word */
/ORA-01747: | ORA-03050:/
);
});
@ -151,7 +155,9 @@ describe('39. dataTypeRowid.js', function() {
await connection.execute(
`INSERT INTO ` + tableName + ` (num, ROWID) VALUES ('12345', 523lkhlf)`);
},
/ORA-01747:/
/* ORA-01747: invalid user.table.column, table.column, or column specification
ORA-03050: invalid identifier: "ROWID" is a reserved word */
/ORA-01747: | ORA-03050:/
);
});
});

View File

@ -39,7 +39,7 @@ const dbConfig = require('./dbconfig.js');
describe('33. dataTypeTimestamp1.js', function() {
let connection = null;
let tableName = "nodb_timestamp1";
const tableName = "nodb_timestamp1";
before('get one connection', async function() {
connection = await oracledb.getConnection(dbConfig);
@ -50,12 +50,10 @@ describe('33. dataTypeTimestamp1.js', function() {
});
describe('33.1 Testing JavaScript Date with database TIMESTAMP', function() {
let dates = assist.data.dates;
const dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -64,53 +62,39 @@ describe('33. dataTypeTimestamp1.js', function() {
});
it('33.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('33.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('33.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('33.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('33.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // end of 33.1 suite
describe('33.2 stores null value correctly', function() {
it('33.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
describe('33.3 testing TIMESTAMP without TIME ZONE', function() {
let timestamps = assist.TIMESTAMP_STRINGS;
const timestamps = assist.TIMESTAMP_STRINGS;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, timestamps, resolve);
});
await assist.setUp4sql(connection, tableName, timestamps);
});
after(async function() {
@ -118,15 +102,13 @@ describe('33. dataTypeTimestamp1.js', function() {
}); // after
it('33.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, timestamps, resolve);
});
await assist.selectOriginalData(connection, tableName, timestamps);
});
it('33.3.2 SELECT query - formatted data for comparison', async function() {
await Promise.all(timestamps.map(async function(timestamp) {
let bv = timestamps.indexOf(timestamp);
let result = await connection.execute(
const bv = timestamps.indexOf(timestamp);
const result = await connection.execute(
`SELECT num, TO_CHAR(content, 'DD-MM-YYYY HH24:MI:SS.FF') AS TS_DATA FROM ` + tableName + ` WHERE num = :no`,
{ no: bv },
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
@ -135,15 +117,13 @@ describe('33. dataTypeTimestamp1.js', function() {
});
it('33.3.3 returns scalar types from PL/SQL block', async function() {
let sql = "BEGIN SELECT systimestamp into :bv from dual; END;";
let binds = { bv: { dir: oracledb.BIND_OUT, type: oracledb.STRING } };
let options = { outFormat: oracledb.OUT_FORMAT_OBJECT };
let result = await connection.execute(sql,
binds,
options);
const sql = "BEGIN SELECT systimestamp into :bv from dual; END;";
const binds = { bv: { dir: oracledb.BIND_OUT, type: oracledb.STRING } };
const options = { outFormat: oracledb.OUT_FORMAT_OBJECT };
const result = await connection.execute(sql, binds, options);
assert(typeof result.outBinds.bv, "string");
});
}); // end of 33.3 suite
});

View File

@ -54,9 +54,7 @@ describe('34. dataTypeTimestamp2.js', function() {
let dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -65,43 +63,31 @@ describe('34. dataTypeTimestamp2.js', function() {
});
it('34.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('34.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('34.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('34.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('34.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // end of 34.1 suite
describe('34.2 stores null value correctly', function() {
it('34.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -109,9 +95,7 @@ describe('34. dataTypeTimestamp2.js', function() {
let timestamps = assist.TIMESTAMP_STRINGS;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, timestamps, resolve);
});
await assist.setUp4sql(connection, tableName, timestamps);
});
after(async function() {
@ -119,9 +103,7 @@ describe('34. dataTypeTimestamp2.js', function() {
}); // after
it('34.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, timestamps, resolve);
});
await assist.selectOriginalData(connection, tableName, timestamps);
});
it('34.3.2 SELECT query - formatted data for comparison', async function() {

View File

@ -55,9 +55,7 @@ describe('35. dataTypeTimestamp3.js', function() {
let dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -66,43 +64,31 @@ describe('35. dataTypeTimestamp3.js', function() {
});
it('35.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('35.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('35.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('35.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('35.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // end of 35.1 suite
describe('35.2 stores null value correctly', function() {
it('35.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -110,9 +96,7 @@ describe('35. dataTypeTimestamp3.js', function() {
let timestamps = assist.TIMESTAMP_TZ_STRINGS_1;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, timestamps, resolve);
});
await assist.setUp4sql(connection, tableName, timestamps);
});
after(async function() {
@ -120,9 +104,7 @@ describe('35. dataTypeTimestamp3.js', function() {
}); // after
it('35.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, timestamps, resolve);
});
await assist.selectOriginalData(connection, tableName, timestamps);
});
it('35.3.2 SELECT query - formatted data for comparison', async function() {

View File

@ -55,9 +55,7 @@ describe('36. dataTypeTimestamp4.js', function() {
let dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -66,43 +64,31 @@ describe('36. dataTypeTimestamp4.js', function() {
});
it('36.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('36.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('36.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('36.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('36.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // end of 36.1 suite
describe('36.2 stores null value correctly', function() {
it('36.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -110,9 +96,7 @@ describe('36. dataTypeTimestamp4.js', function() {
let timestamps = assist.TIMESTAMP_TZ_STRINGS_1;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, timestamps, resolve);
});
await assist.setUp4sql(connection, tableName, timestamps);
});
after(async function() {
@ -120,9 +104,7 @@ describe('36. dataTypeTimestamp4.js', function() {
}); // after
it('36.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, timestamps, resolve);
});
await assist.selectOriginalData(connection, tableName, timestamps);
});
it('36.3.2 SELECT query - formatted data for comparison', async function() {

View File

@ -53,9 +53,7 @@ describe('37. dataTypeTimestamp5.js', function() {
let dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -64,52 +62,38 @@ describe('37. dataTypeTimestamp5.js', function() {
});
it('37.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('37.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('37.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('37.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('37.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // end of 37.1 suite
describe('37.2 stores null value correctly', function() {
it('37.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
describe('37.3 testing TIMESTAMP WITH LOCAL TIME ZONE', function() {
let timestamps = assist.TIMESTAMP_TZ_STRINGS_2;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, timestamps, resolve);
});
await assist.setUp4sql(connection, tableName, timestamps);
});
after(async function() {
@ -117,9 +101,7 @@ describe('37. dataTypeTimestamp5.js', function() {
}); // after
it('37.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, timestamps, resolve);
});
await assist.selectOriginalData(connection, tableName, timestamps);
});
it('37.3.2 SELECT query - formatted data for comparison', async function() {

View File

@ -56,9 +56,7 @@ describe('38. dataTypeTimestamp6.js', function() {
let dates = assist.data.dates;
before('create table, insert data', async function() {
await new Promise((resolve) => {
assist.setUp(connection, tableName, dates, resolve);
});
await assist.setUp(connection, tableName, dates);
});
after(async function() {
@ -67,42 +65,30 @@ describe('38. dataTypeTimestamp6.js', function() {
});
it('38.1.1 works well with SELECT query', async function() {
await new Promise((resolve) => {
assist.dataTypeSupport(connection, tableName, dates, resolve);
});
await assist.dataTypeSupport(connection, tableName, dates);
});
it('38.1.2 works well with result set', async function() {
await new Promise((resolve) => {
assist.verifyResultSet(connection, tableName, dates, resolve);
});
await assist.verifyResultSet(connection, tableName, dates);
});
it('38.1.3 works well with REF Cursor', async function() {
await new Promise((resolve) => {
assist.verifyRefCursor(connection, tableName, dates, resolve);
});
await assist.verifyRefCursor(connection, tableName, dates);
});
it('38.1.4 columns fetched from REF CURSORS can be mapped by fetchInfo settings', async function() {
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchInfo(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchInfo(connection, tableName, dates);
});
it('38.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
await new Promise((resolve) => {
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, resolve);
});
await assist.verifyRefCursorWithFetchAsString(connection, tableName, dates);
});
}); // end of 37.1 suite
describe('38.2 stores null value correctly', function() {
it('38.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});
@ -110,9 +96,7 @@ describe('38. dataTypeTimestamp6.js', function() {
let timestamps = assist.TIMESTAMP_TZ_STRINGS_2;
before(async function() {
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, timestamps, resolve);
});
await assist.setUp4sql(connection, tableName, timestamps);
});
after(async function() {
@ -120,9 +104,7 @@ describe('38. dataTypeTimestamp6.js', function() {
}); // after
it('38.3.1 SELECT query - original data', async function() {
await new Promise((resolve) => {
assist.selectOriginalData(connection, tableName, timestamps, resolve);
});
await assist.selectOriginalData(connection, tableName, timestamps);
});
it('38.3.2 SELECT query - formatted data for comparison', async function() {

View File

@ -97,9 +97,7 @@ describe('113. dataTypeUrowid.js', function() {
describe('113.2 stores null value correctly', function() {
it('113.2.1 testing Null, Empty string and Undefined', async function() {
await new Promise((resolve) => {
assist.verifyNullValues(connection, tableName, resolve);
});
await assist.verifyNullValues(connection, tableName);
});
});

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
@ -337,9 +337,7 @@ describe('6. dmlReturning.js', function() {
beforeEach('get connection, prepare table', async function() {
connection = await oracledb.getConnection(dbConfig);
await new Promise((resolve) => {
assist.setUp4sql(connection, tableName, dates, resolve);
});
await assist.setUp4sql(connection, tableName, dates);
}); // before
afterEach('drop table, release connection', async function() {

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates. */
/* Copyright (c) 2017, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
@ -40,28 +40,28 @@ describe('19. fetchTimestampAsString.js', function() {
let connection = null;
before(async function() {
connection = await oracledb.getConnection(dbConfig);
await connection.execute(
"alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS.FF'");
await connection.execute(
"alter session set nls_timestamp_tz_format = 'YYYY-MM-DD HH24:MI:SS.FF'");
connection.execute(
`alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS.FF'`);
connection.execute(
`alter session set nls_timestamp_tz_format = 'YYYY-MM-DD HH24:MI:SS.FF'`);
});
after(async function() {
after(function() {
oracledb.fetchAsString = [];
await connection.close();
connection.close();
});
describe('19.1 TIMESTAMP', function() {
let tableName = "nodb_timestamp1";
let inData = assist.TIMESTAMP_STRINGS;
const tableName = `nodb_timestamp1`;
const inData = assist.TIMESTAMP_STRINGS;
before(function(done) {
assist.setUp4sql(connection, tableName, inData, done);
before(async function() {
await assist.setUp4sql(connection, tableName, inData);
});
after(async function() {
after(function() {
oracledb.fetchAsString = [];
await connection.execute("DROP table " + tableName + " PURGE");
connection.execute(`DROP table ` + tableName + ` PURGE`);
}); // after
afterEach(function() {
@ -69,46 +69,46 @@ describe('19. fetchTimestampAsString.js', function() {
});
it('19.1.1 fetchInfo option', async function() {
let ref = assist.content.timestamp_1_1;
const ref = assist.content.timestamp_1_1;
await test1(tableName, ref);
});
it('19.1.2 fetchInfo option, outFormat is OBJECT', async function() {
let ref = assist.content.timestamp_1_2;
const ref = assist.content.timestamp_1_2;
await test2(tableName, ref);
});
it('19.1.3 fetchInfo option, enables resultSet', async function() {
let ref = assist.content.timestamp_1_1;
const ref = assist.content.timestamp_1_1;
await test3(tableName, ref);
});
it('19.1.4 fetchInfo option, resultSet and OBJECT outFormat', async function() {
let ref = assist.content.timestamp_1_2;
const ref = assist.content.timestamp_1_2;
await test4(tableName, ref);
});
it('19.1.5 fetchAsString property', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_1_1;
const ref = assist.content.timestamp_1_1;
await test5(tableName, ref);
});
it('19.1.6 fetchAsString property and OBJECT outFormat', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_1_2;
const ref = assist.content.timestamp_1_2;
await test6(tableName, ref);
});
it('19.1.7 fetchAsString property, resultSet', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_1_1;
const ref = assist.content.timestamp_1_1;
await test7(tableName, ref);
});
it('19.1.8 fetchAsString property, resultSet and OBJECT outFormat', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_1_2;
const ref = assist.content.timestamp_1_2;
await test8(tableName, ref);
});
@ -116,21 +116,16 @@ describe('19. fetchTimestampAsString.js', function() {
describe('19.2 TIMESTAMP WITH TIME ZONE', function() {
let tableName = "nodb_timestamp3";
let inData = assist.TIMESTAMP_TZ_STRINGS_1;
const tableName = "nodb_timestamp3";
const inData = assist.TIMESTAMP_TZ_STRINGS_1;
before(function(done) {
assist.setUp4sql(connection, tableName, inData, done);
before(async function() {
await assist.setUp4sql(connection, tableName, inData);
});
after(async function() {
oracledb.fetchAsString = [];
await connection.execute(
"DROP table " + tableName + " PURGE",
function(err) {
assert.ifError(err);
}
);
await connection.execute(`DROP table ` + tableName + ` PURGE`);
}); // after
afterEach(function() {
@ -138,65 +133,64 @@ describe('19. fetchTimestampAsString.js', function() {
});
it('19.2.1 fetchInfo option', async function() {
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test1(tableName, ref);
});
it('19.2.2 fetchInfo option, outFormat is OBJECT', async function() {
let ref = assist.content.timestamp_3_2;
const ref = assist.content.timestamp_3_2;
await test2(tableName, ref);
});
it('19.2.3 fetchInfo option, enables resultSet', async function() {
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test3(tableName, ref);
});
it('19.2.4 fetchInfo option, resultSet and OBJECT outFormat', async function() {
let ref = assist.content.timestamp_3_2;
const ref = assist.content.timestamp_3_2;
await test4(tableName, ref);
});
it('19.2.5 fetchAsString property', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test5(tableName, ref);
});
it('19.2.6 fetchAsString property and OBJECT outFormat', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_3_2;
const ref = assist.content.timestamp_3_2;
await test6(tableName, ref);
});
it('19.2.7 fetchAsString property, resultSet', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test7(tableName, ref);
});
it('19.2.8 fetchAsString property, resultSet and OBJECT outFormat', async function() {
oracledb.fetchAsString = [ oracledb.DATE ];
let ref = assist.content.timestamp_3_2;
const ref = assist.content.timestamp_3_2;
await test8(tableName, ref);
});
}); // 19.2
describe('19.3 testing maxRows settings and queryStream() to fetch as string', function() {
let tableName = "nodb_timestamp3";
let inData = assist.TIMESTAMP_TZ_STRINGS_1;
let defaultLimit = oracledb.maxRows;
const tableName = "nodb_timestamp3";
const inData = assist.TIMESTAMP_TZ_STRINGS_1;
const defaultLimit = oracledb.maxRows;
before(function(done) {
before(async function() {
assert.strictEqual(defaultLimit, 0);
assist.setUp4sql(connection, tableName, inData, done);
await assist.setUp4sql(connection, tableName, inData);
});
after(async function() {
oracledb.fetchAsString = [];
await connection.execute(
"DROP table " + tableName + " PURGE");
await connection.execute(`DROP table ` + tableName + ` PURGE`);
}); // after
beforeEach(function() {
@ -209,39 +203,39 @@ describe('19. fetchTimestampAsString.js', function() {
it('19.3.1 works well when setting oracledb.maxRows > actual number of rows', async function() {
oracledb.maxRows = inData.length * 2;
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test1(tableName, ref);
});
it('19.3.2 maxRows = actual num of rows', async function() {
oracledb.maxRows = inData.length;
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test1(tableName, ref);
});
it('19.3.3 works when oracledb.maxRows < actual number of rows', async function() {
let half = Math.floor(inData.length / 2);
const half = Math.floor(inData.length / 2);
oracledb.maxRows = half;
let ref = assist.content.timestamp_3_1.slice(0, half);
const ref = assist.content.timestamp_3_1.slice(0, half);
await test1(tableName, ref);
});
it('19.3.4 uses queryStream() and maxRows > actual number of rows', async function() {
oracledb.maxRows = inData.length * 2;
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test9(tableName, ref);
});
it('19.3.5 uses queryStream() and maxRows = actual number of rows', async function() {
oracledb.maxRows = inData.length;
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test9(tableName, ref);
});
it('19.3.6 maxRows < actual rows. maxRows does not restrict queryStream()', async function() {
let half = Math.floor(inData.length / 2);
const half = Math.floor(inData.length / 2);
oracledb.maxRows = half;
let ref = assist.content.timestamp_3_1;
const ref = assist.content.timestamp_3_1;
await test9(tableName, ref);
});
@ -250,8 +244,8 @@ describe('19. fetchTimestampAsString.js', function() {
// fetchInfo option
async function test1(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{ fetchInfo: { "CONTENT": { type: oracledb.STRING } } });
@ -260,8 +254,8 @@ describe('19. fetchTimestampAsString.js', function() {
// fetchInfo option, outFormat is OBJECT
async function test2(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
@ -272,8 +266,8 @@ describe('19. fetchTimestampAsString.js', function() {
// fetchInfo option, resultSet
async function test3(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{
resultSet: true,
@ -284,7 +278,7 @@ describe('19. fetchTimestampAsString.js', function() {
await fetchRowFromRS(result.resultSet);
async function fetchRowFromRS(rs) {
let row = await rs.getRow();
const row = await rs.getRow();
if (row) {
assert.deepEqual(row, want[count]);
@ -297,8 +291,8 @@ describe('19. fetchTimestampAsString.js', function() {
}
async function test4(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
@ -310,7 +304,7 @@ describe('19. fetchTimestampAsString.js', function() {
await fetchRowFromRS(result.resultSet);
async function fetchRowFromRS(rs) {
let row = await rs.getRow();
const row = await rs.getRow();
if (row) {
assert.deepEqual(row, want[count]);
@ -323,22 +317,22 @@ describe('19. fetchTimestampAsString.js', function() {
}
async function test5(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num");
const result = await connection.execute(
`select content from ` + table + ` order by num`);
assert.deepEqual(result.rows, want);
}
async function test6(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
assert.deepEqual(result.rows, want);
}
async function test7(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{
resultSet: true
@ -348,7 +342,7 @@ describe('19. fetchTimestampAsString.js', function() {
await fetchRowFromRS(result.resultSet);
async function fetchRowFromRS(rs) {
let row = await rs.getRow();
const row = await rs.getRow();
if (row) {
assert.deepEqual(row, want[count]);
@ -361,8 +355,8 @@ describe('19. fetchTimestampAsString.js', function() {
}
async function test8(table, want) {
let result = await connection.execute(
"select content from " + table + " order by num",
const result = await connection.execute(
`select content from ` + table + ` order by num`,
[],
{
resultSet: true,
@ -373,7 +367,7 @@ describe('19. fetchTimestampAsString.js', function() {
await fetchRowFromRS(result.resultSet);
async function fetchRowFromRS(rs) {
let row = await rs.getRow();
const row = await rs.getRow();
if (row) {
assert.deepEqual(row, want[count]);
@ -386,14 +380,14 @@ describe('19. fetchTimestampAsString.js', function() {
}
async function test9(table, want) {
let sql = "select content from " + table + " order by num";
let stream = await connection.queryStream(
const sql = `select content from ` + table + ` order by num`;
const stream = await connection.queryStream(
sql,
[],
{ fetchInfo: { "CONTENT": { type: oracledb.STRING } } }
);
let result = [];
const result = [];
await new Promise((resolve, reject) => {
stream.on('error', function(error) {

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2018, 2022, Oracle and/or its affiliates. */
/* Copyright (c) 2018, 2023, Oracle and/or its affiliates. */
/******************************************************************************
*
@ -29,6 +29,7 @@
* Test parsing a statement and returns information about it.
*
*****************************************************************************/
'use strict';
const oracledb = require('oracledb');
@ -45,9 +46,7 @@ describe('162. getStmtInfo.js', function() {
before(async function() {
conn = await oracledb.getConnection(dbConfig);
await new Promise((resolve) => {
assist.setUp(conn, tableName, numbers, resolve);
});
await assist.setUp(conn, tableName, numbers);
});
after(async function() {
@ -110,9 +109,7 @@ describe('162. getStmtInfo.js', function() {
const info = await conn.getStatementInfo(sql);
assert.deepEqual(info.bindNames, []);
assert.strictEqual(info.statementType, oracledb.STMT_TYPE_UPDATE);
await new Promise((resolve) => {
assist.dataTypeSupport(conn, tableName, numbers, resolve);
});
await assist.dataTypeSupport(conn, tableName, numbers);
}); // 162.6
it('162.7 DELETE with data bind', async function() {
@ -127,9 +124,7 @@ describe('162. getStmtInfo.js', function() {
const info = await conn.getStatementInfo(sql);
assert.deepEqual(info.bindNames, []);
assert.strictEqual(info.statementType, oracledb.STMT_TYPE_DELETE);
await new Promise((resolve) => {
assist.dataTypeSupport(conn, tableName, numbers, resolve);
});
await assist.dataTypeSupport(conn, tableName, numbers);
}); // 162.8
it('162.9 DELETE with subquery', async function() {
@ -217,9 +212,7 @@ describe('162. getStmtInfo.js', function() {
it('162.17 DROP', async function() {
const tab = "nodb_date";
const sql = "drop table " + tab + " purge";
await new Promise((resolve) => {
assist.createTable(conn, tab, resolve);
});
await assist.createTable(conn, tab);
const info = await conn.getStatementInfo(sql);
assert.deepEqual(info.bindNames, []);
assert.strictEqual(info.statementType, oracledb.STMT_TYPE_DROP);

View File

@ -51,9 +51,13 @@ async function testConnection(description, additionalOptions = {}) {
async function cloudServiceCheck() {
const connection = await oracledb.getConnection(dbConfig);
let result = await connection.execute("select sys_context('userenv', 'cloud_service') from dual");
if (result.rows[0][0]) {
dbConfig.test.isCloudService = true;
// 'userenv' parameter is only available from Oracle DB 18c & later versions
if (connection.oracleServerVersion >= 1800000000) {
let result = await connection.execute("select \
sys_context('userenv', 'cloud_service') from dual");
if (result.rows[0][0]) {
dbConfig.test.isCloudService = true;
}
}
await connection.close();
}

View File

@ -37,8 +37,7 @@
const oracledb = require('oracledb');
const fs = require('fs');
const async = require('async');
const should = require('should');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js');
@ -46,463 +45,295 @@ describe('59. lobResultSet.js', function() {
let connection = null;
before('get one connection', function(done) {
oracledb.getConnection(dbConfig, function(err, conn) {
should.not.exist(err);
connection = conn;
done();
});
before('get one connection', async function() {
connection = await oracledb.getConnection(dbConfig);
});
after('release connection', function(done) {
connection.close(function(err) {
should.not.exist(err);
done();
});
after('release connection', async function() {
await connection.close();
});
describe('59.1 CLOB data', function() {
var insertID = 1;
var tableName = "nodb_myclobs";
var inFileName = './test/clobexample.txt';
before('create table', function(done) {
assist.createTable(connection, tableName, done);
let insertID = 1;
const tableName = "nodb_myclobs";
const inFileName = './test/clobexample.txt';
before('create table', async function() {
await connection.execute(assist.sqlCreateTable(tableName));
});
after('drop table', function(done) {
connection.execute(
"DROP table " + tableName + " PURGE",
function(err) {
should.not.exist(err);
done();
}
);
after('drop table', async function() {
await connection.execute(`DROP table ` + tableName + ` PURGE`);
});
function fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected, callback) {
resultSet.getRow(function(err, row) {
should.not.exist(err);
if (!row) {
resultSet.close(function(err) {
should.not.exist(err);
should.strictEqual(rowsFetched, rowsExpected);
callback();
});
} else {
var lob = row[1];
lob.setEncoding('utf8');
var text = "";
lob.on('data', function(chunk) {
text = text + chunk;
});
lob.on('end', function() {
rowsFetched++;
fs.readFile(inFileName, { encoding: 'utf8' }, function(err, originalData) {
should.not.exist(err);
should.strictEqual(text, originalData);
});
fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected, callback);
});
lob.on('error', function(err) {
console.log("lob.on 'error' event");
console.error(err.message);
});
}
});
async function fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected) {
const row = await resultSet.getRow();
if (!row) {
await resultSet.close();
assert.strictEqual(rowsFetched, rowsExpected);
} else {
rowsFetched++;
const text = await row[1].getData();
const originalData = fs.readFileSync(inFileName, { encoding: 'utf8' });
assert.strictEqual(text, originalData);
await fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected);
}
}
function streamIntoClob(id, cb) {
connection.execute(
async function streamIntoClob(id) {
const result = await connection.execute(
"INSERT INTO " + tableName + " VALUES (:n, EMPTY_CLOB()) RETURNING content INTO :lobbv",
{ n: id, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } },
function(err, result) {
should.not.exist(err);
var lob = result.outBinds.lobbv[0];
var inStream = fs.createReadStream(inFileName);
{ n: id, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } });
inStream.pipe(lob);
lob.on('finish', function() {
connection.commit(function(err) {
should.not.exist(err);
cb(); // insertion done
});
});
inStream.on('error', function(err) {
should.not.exist(err);
});
}
);
const lob = result.outBinds.lobbv[0];
const inStream = await fs.createReadStream(inFileName);
await new Promise((resolve, reject) => {
lob.on('error', reject);
lob.on('finish', resolve);
inStream.on('error', reject);
inStream.pipe(lob);
});
await connection.commit();
}
it('59.1.1 reads clob data one by one row from result set', function(done) {
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoClob(id_1, callback);
},
function(callback) {
streamIntoClob(id_2, callback);
},
function(callback) {
streamIntoClob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
}
], done);
it('59.1.1 reads clob data one by one row from result set', async function() {
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoClob(id_1);
await streamIntoClob(id_2);
await streamIntoClob(id_3);
const result = await connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
}); // 59.1.1
it('59.1.2 works with oracledb.maxRows > actual number of rows fetched', function(done) {
var maxRowsBak = oracledb.maxRows;
it('59.1.2 works with oracledb.maxRows > actual number of rows fetched', async function() {
const maxRowsBak = oracledb.maxRows;
oracledb.maxRows = 10;
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoClob(id_1, callback);
},
function(callback) {
streamIntoClob(id_2, callback);
},
function(callback) {
streamIntoClob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
},
function(callback) {
oracledb.maxRows = maxRowsBak;
callback();
}
], done);
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoClob(id_1);
await streamIntoClob(id_2);
await streamIntoClob(id_3);
const result = await connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
oracledb.maxRows = maxRowsBak;
}); // 59.1.2
it('59.1.3 works with oracledb.maxRows = actual number of rows fetched', function(done) {
var maxRowsBak = oracledb.maxRows;
it('59.1.3 works with oracledb.maxRows = actual number of rows fetched', async function() {
const maxRowsBak = oracledb.maxRows;
oracledb.maxRows = 3;
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoClob(id_1, callback);
},
function(callback) {
streamIntoClob(id_2, callback);
},
function(callback) {
streamIntoClob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
},
function(callback) {
oracledb.maxRows = maxRowsBak;
callback();
}
], done);
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoClob(id_1);
await streamIntoClob(id_2);
await streamIntoClob(id_3);
const result = await connection.execute(
`SELECT num, content FROM ` + tableName + ` where num = ` + id_1 + ` or num = ` + id_2 + ` or num = ` + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
oracledb.maxRows = maxRowsBak;
}); // 59.1.3
it('59.1.4 works with oracledb.maxRows < actual number of rows fetched', function(done) {
var maxRowsBak = oracledb.maxRows;
it('59.1.4 works with oracledb.maxRows < actual number of rows fetched', async function() {
const maxRowsBak = oracledb.maxRows;
oracledb.maxRows = 1;
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoClob(id_1, callback);
},
function(callback) {
streamIntoClob(id_2, callback);
},
function(callback) {
streamIntoClob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
},
function(callback) {
oracledb.maxRows = maxRowsBak;
callback();
}
], done);
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoClob(id_1);
await streamIntoClob(id_2);
await streamIntoClob(id_3);
const result = await connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
oracledb.maxRows = maxRowsBak;
}); // 59.1.4
}); // 59.1
describe('59.2 BLOB data', function() {
var insertID = 1;
var tableName = "nodb_myblobs";
var jpgFileName = "./test/fuzzydinosaur.jpg";
before('create table', function(done) {
assist.createTable(connection, tableName, done);
let insertID = 1;
const tableName = "nodb_myblobs";
const jpgFileName = "./test/fuzzydinosaur.jpg";
before('create table', async function() {
await connection.execute(assist.sqlCreateTable(tableName));
});
after('drop table', function(done) {
connection.execute(
"DROP table " + tableName + " PURGE",
function(err) {
should.not.exist(err);
done();
}
);
after('drop table', async function() {
await connection.execute(`DROP table ` + tableName + ` PURGE`);
});
function fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected, callback) {
resultSet.getRow(function(err, row) {
should.not.exist(err);
if (!row) {
resultSet.close(function(err) {
should.not.exist(err);
should.strictEqual(rowsFetched, rowsExpected);
rowsFetched = 0;
callback();
});
} else {
var lob = row[1];
var blobData = 0;
var totalLength = 0;
blobData = Buffer.alloc(0);
async function fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected) {
const row = await resultSet.getRow();
if (!row) {
await resultSet.close();
assert.strictEqual(rowsFetched, rowsExpected);
rowsFetched = 0;
} else {
rowsFetched++;
const blobData = await row[1].getData();
const originalData = fs.readFileSync(jpgFileName);
assert.deepEqual(originalData, blobData);
await fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected);
}
}
lob.on('data', function(chunk) {
totalLength = totalLength + chunk.length;
blobData = Buffer.concat([blobData, chunk], totalLength);
});
async function streamIntoBlob(id) {
const result = await connection.execute(
`INSERT INTO ` + tableName + ` VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv`,
{ n: id, lobbv: { type: oracledb.BLOB, dir: oracledb.BIND_OUT } });
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event.");
});
lob.on('end', function() {
fs.readFile(jpgFileName, function(err, originalData) {
should.not.exist(err);
should.strictEqual(totalLength, originalData.length);
originalData.should.eql(blobData);
});
rowsFetched++;
fetchOneRowFromRS(resultSet, rowsFetched, rowsExpected, callback);
});
}
const lob = result.outBinds.lobbv[0];
const inStream = await fs.createReadStream(jpgFileName);
await new Promise((resolve, reject) => {
inStream.on('error', reject);
lob.on('error', reject);
lob.on('finish', resolve);
inStream.pipe(lob);
});
await connection.commit();
}
function streamIntoBlob(id, cb) {
connection.execute(
"INSERT INTO " + tableName + " VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv",
{ n: id, lobbv: { type: oracledb.BLOB, dir: oracledb.BIND_OUT } },
function(err, result) {
should.not.exist(err);
var lob = result.outBinds.lobbv[0];
var inStream = fs.createReadStream(jpgFileName);
it('59.2.1 reads blob data one by one row from result set', async function() {
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
inStream.pipe(lob);
await streamIntoBlob(id_1);
lob.on('finish', function() {
connection.commit(function(err) {
should.not.exist(err);
cb(); // insertion done
});
});
await streamIntoBlob(id_2);
inStream.on('error', function(err) {
should.not.exist(err);
});
await streamIntoBlob(id_3);
}
);
}
const result = await connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
it('59.2.1 reads blob data one by one row from result set', function(done) {
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoBlob(id_1, callback);
},
function(callback) {
streamIntoBlob(id_2, callback);
},
function(callback) {
streamIntoBlob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
}
], done);
}); // 59.2.1
it('59.2.2 works with oracledb.maxRows > actual number of rows fetched', function(done) {
var maxRowsBak = oracledb.maxRows;
it('59.2.2 works with oracledb.maxRows > actual number of rows fetched', async function() {
const maxRowsBak = oracledb.maxRows;
oracledb.maxRows = 10;
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoBlob(id_1, callback);
},
function(callback) {
streamIntoBlob(id_2, callback);
},
function(callback) {
streamIntoBlob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
},
function(callback) {
oracledb.maxRows = maxRowsBak;
callback();
}
], done);
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoBlob(id_1);
await streamIntoBlob(id_2);
await streamIntoBlob(id_3);
const result = await connection.execute(
`SELECT num, content FROM ` + tableName + ` where num = ` + id_1 + ` or num = ` + id_2 + ` or num = ` + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
oracledb.maxRows = maxRowsBak;
}); // 59.2.2
it('59.2.3 works with oracledb.maxRows = actual number of rows fetched', function(done) {
var maxRowsBak = oracledb.maxRows;
it('59.2.3 works with oracledb.maxRows = actual number of rows fetched', async function() {
const maxRowsBak = oracledb.maxRows;
oracledb.maxRows = 3;
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoBlob(id_1, callback);
},
function(callback) {
streamIntoBlob(id_2, callback);
},
function(callback) {
streamIntoBlob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
},
function(callback) {
oracledb.maxRows = maxRowsBak;
callback();
}
], done);
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoBlob(id_1);
await streamIntoBlob(id_2);
await streamIntoBlob(id_3);
const result = await connection.execute(
`SELECT num, content FROM ` + tableName + ` where num = ` + id_1 + ` or num = ` + id_2 + ` or num = ` + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
oracledb.maxRows = maxRowsBak;
}); // 59.2.3
it('59.2.4 works with oracledb.maxRows < actual number of rows fetched', function(done) {
var maxRowsBak = oracledb.maxRows;
it('59.2.4 works with oracledb.maxRows < actual number of rows fetched', async function() {
const maxRowsBak = oracledb.maxRows;
oracledb.maxRows = 1;
var id_1 = insertID++;
var id_2 = insertID++;
var id_3 = insertID++;
async.series([
function(callback) {
streamIntoBlob(id_1, callback);
},
function(callback) {
streamIntoBlob(id_2, callback);
},
function(callback) {
streamIntoBlob(id_3, callback);
},
function(callback) {
connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true },
function(err, result) {
should.not.exist(err);
var actualRowsFetched = 0; // actual rows read from resultset
var rowsExpected = 3; // expected rows read from resultSet
fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected, callback);
}
);
},
function(callback) {
oracledb.maxRows = maxRowsBak;
callback();
}
], done);
const id_1 = insertID++;
const id_2 = insertID++;
const id_3 = insertID++;
await streamIntoBlob(id_1);
await streamIntoBlob(id_2);
await streamIntoBlob(id_3);
const result = await connection.execute(
"SELECT num, content FROM " + tableName + " where num = " + id_1 + " or num = " + id_2 + " or num = " + id_3,
[],
{ resultSet: true });
const actualRowsFetched = 0; // actual rows read from resultset
const rowsExpected = 3; // expected rows read from resultSet
await fetchOneRowFromRS(result.resultSet, actualRowsFetched, rowsExpected);
oracledb.maxRows = maxRowsBak;
}); // 59.2.4
}); // 59.2

View File

@ -744,9 +744,7 @@ describe('58. properties.js', function() {
before('get resultSet class', async function() {
connection = await oracledb.getConnection(dbConfig);
await new Promise((resolve) => {
assist.setUp(connection, tableName, numbers, resolve);
});
await assist.setUp(connection, tableName, numbers);
result = await connection.execute(
"SELECT * FROM " + tableName + " ORDER BY num",
[],

View File

@ -32,181 +32,109 @@
'use strict';
const oracledb = require('oracledb');
const should = require('should');
const async = require('async');
const assert = require('assert');
const dbConfig = require('./dbconfig.js');
const assist = require('./dataTypeAssist.js');
describe('53. resultSetClose.js', function() {
let connection = null;
var resultSet = null;
var tableName = "nodb_number";
var numbers = assist.data.numbers;
let resultSet = null;
let tableName = "nodb_number";
let numbers = assist.data.numbers;
before(function(done) {
async.series([
function getConn(cb) {
oracledb.getConnection(
dbConfig,
function(err, conn) {
should.not.exist(err);
connection = conn;
cb();
}
);
},
function(cb) {
assist.setUp(connection, tableName, numbers, cb);
},
function getResultSet(cb) {
connection.execute(
"SELECT * FROM " + tableName + " ORDER BY num",
[],
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT },
function(err, result) {
should.not.exist(err);
resultSet = result.resultSet;
cb();
}
);
},
function verifyMetaData(cb) {
should.exist(resultSet.metaData);
var t = resultSet.metaData;
should.equal(t[0].name, 'NUM');
should.equal(t[1].name, 'CONTENT');
cb();
},
function closeRS(cb) {
resultSet.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
before(async function() {
connection = await oracledb.getConnection(dbConfig);
await assist.setUp(connection, tableName, numbers);
let result = await connection.execute(
`SELECT * FROM ` + tableName + ` ORDER BY num`,
[],
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT });
resultSet = result.resultSet;
assert(resultSet.metaData);
let t = resultSet.metaData;
assert.strictEqual(t[0].name, 'NUM');
assert.strictEqual(t[1].name, 'CONTENT');
await resultSet.close();
}); // before
after(function(done) {
async.series([
function(cb) {
connection.execute(
"DROP TABLE " + tableName + " PURGE",
function(err) {
should.not.exist(err);
cb();
}
);
},
function(cb) {
connection.close(function(err) {
should.not.exist(err);
cb();
});
}
], done);
after(async function() {
await connection.execute(`DROP TABLE ` + tableName + ` PURGE`);
await connection.close();
}); // after
it('53.1 can not get metaData property', function() {
should.strictEqual(resultSet.metaData, undefined);
assert.strictEqual(resultSet.metaData, undefined);
}); // 53.1
it('53.2 can not call close() again', function(done) {
resultSet.close(function(err) {
should.exist(err);
should.strictEqual(
err.message,
'NJS-018: invalid ResultSet'
);
done();
});
it('53.2 can not call close() again', async function() {
await assert.rejects(
async () => {
await resultSet.close();
},
/NJS-018:/ //'NJS-018: invalid ResultSet'
);
}); // 53.2
it('53.3 can not call getRow()', function(done) {
resultSet.getRow(function(err, row) {
should.exist(err);
should.not.exist(row);
should.strictEqual(
err.message,
'NJS-018: invalid ResultSet'
);
done();
});
it('53.3 can not call getRow()', async function() {
await assert.rejects(
async () => {
await resultSet.getRow();
},
/NJS-018:/ //'NJS-018: invalid ResultSet'
);
}); // 53.3
it('53.4 can not call getRows()', function(done) {
var numRows = 3;
resultSet.getRows(numRows, function(err, rows) {
should.exist(err);
should.not.exist(rows);
should.strictEqual(
err.message,
'NJS-018: invalid ResultSet'
);
done();
});
it('53.4 can not call getRows()', async function() {
let numRows = 3;
await assert.rejects(
async () => {
await resultSet.getRows(numRows);
},
/NJS-018:/ //'NJS-018: invalid ResultSet'
);
}); // 53.4
it('53.5 can not call toQueryStream()', function() {
should.throws(
function() {
var qstream;
qstream = resultSet.toQueryStream();
should.not.exist(qstream);
it('53.5 can not call toQueryStream()', async function() {
await assert.rejects(
async () => {
await resultSet.toQueryStream();
},
/NJS-041: cannot convert ResultSet to QueryStream after invoking methods/
/NJS-041:/ //NJS-041: cannot convert ResultSet to QueryStream after invoking methods/
);
}); // 53.5
it('53.6 can call getRow() again in the callback of getRow()', function(done) {
it('53.6 can call getRow() again in the callback of getRow()', async function() {
var rs2 = null;
var tab = "nodb_float";
let rs2 = null;
let tab = "nodb_float";
async.series([
function(cb) {
assist.setUp(connection, tab, numbers, cb);
},
function getResultSet(cb) {
connection.execute(
"SELECT * FROM " + tab + " ORDER BY num",
[],
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT },
function(err, result) {
should.not.exist(err);
rs2 = result.resultSet;
cb();
}
);
},
function test(cb) {
rs2.getRow(function(err, row) {
should.not.exist(err);
should.exist(row);
await assist.setUp(connection, tab, numbers);
rs2.getRow(function(err, row2) {
should.not.exist(err);
should.exist(row2);
cb();
});
});
},
function closeRS(cb) {
rs2.close(function(err) {
should.not.exist(err);
cb();
});
},
function dropTable(callback) {
connection.execute(
"DROP TABLE " + tab + " PURGE",
function(err) {
should.not.exist(err);
callback();
}
);
}
], done);
let result = await connection.execute(
`SELECT * FROM ` + tab + ` ORDER BY num`,
[],
{ resultSet: true, outFormat: oracledb.OUT_FORMAT_OBJECT });
rs2 = result.resultSet;
let row = await rs2.getRow();
assert(row);
let row2 = await rs2.getRow();
assert(row2);
await rs2.close();
await connection.execute(`DROP TABLE ` + tab + ` PURGE`);
}); // 53.6
});