Refactor tests
This commit is contained in:
parent
a09de173af
commit
8f678f436c
|
@ -720,4 +720,36 @@ describe('4. binding.js', function() {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('4.12 binding in a cursor', function() {
|
||||
let connection = null;
|
||||
before(async function() {
|
||||
connection = await oracledb.getConnection(dbConfig);
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
it('4.12.1 test binding in a cursor', async function() {
|
||||
const sql = `begin
|
||||
open :cursor for select 'X' StringValue from dual;
|
||||
end;`;
|
||||
const bindVars = { cursor: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } };
|
||||
const result = await connection.execute(sql, bindVars);
|
||||
const cursor = result.outBinds.cursor;
|
||||
const expectedBind = {
|
||||
name: "STRINGVALUE",
|
||||
fetchType: oracledb.DB_TYPE_VARCHAR,
|
||||
dbType: oracledb.DB_TYPE_CHAR,
|
||||
dbTypeName: "CHAR",
|
||||
nullable: true,
|
||||
byteSize: 1
|
||||
};
|
||||
assert.deepEqual(cursor.metaData, [expectedBind]);
|
||||
|
||||
const rows = await cursor.getRows();
|
||||
assert.deepEqual(rows, [ [ 'X' ] ]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -36,237 +36,154 @@
|
|||
*****************************************************************************/
|
||||
'use strict';
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var should = require('should');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
var assist = require('./dataTypeAssist.js');
|
||||
const oracledb = require('oracledb');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const dbConfig = require('./dbconfig.js');
|
||||
const assist = require('./dataTypeAssist.js');
|
||||
|
||||
var inFileName = 'test/fuzzydinosaur.jpg'; // contains the image to be inserted
|
||||
var outFileName = 'test/blobstreamout.jpg';
|
||||
let inFileName = 'test/fuzzydinosaur.jpg'; // contains the image to be inserted
|
||||
let outFileName = 'test/blobstreamout.jpg';
|
||||
|
||||
describe('41. dataTypeBlob.js', function() {
|
||||
|
||||
var connection = null;
|
||||
var tableName = "nodb_myblobs";
|
||||
let connection = null;
|
||||
let tableName = "nodb_myblobs";
|
||||
|
||||
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.release(function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
after('release connection', async function() {
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
describe('41.1 testing BLOB data type', function() {
|
||||
before('create table', function(done) {
|
||||
assist.createTable(connection, tableName, done);
|
||||
before('create table', async function() {
|
||||
await connection.execute(assist.sqlCreateTable(tableName));
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP table " + tableName + " PURGE",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute("DROP table " + tableName + " PURGE");
|
||||
});
|
||||
|
||||
it('41.1.1 stores BLOB value correctly', function(done) {
|
||||
connection.should.be.ok();
|
||||
async.series([
|
||||
function blobinsert1(callback) {
|
||||
it('41.1.1 stores BLOB value correctly', async function() {
|
||||
|
||||
connection.execute(
|
||||
"INSERT INTO nodb_myblobs (num, content) VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv",
|
||||
{ n: 2, lobbv: {type: oracledb.BLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }, // a transaction needs to span the INSERT and pipe()
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
(result.outBinds.lobbv.length).should.be.exactly(1);
|
||||
let result = await connection.execute(
|
||||
`INSERT INTO nodb_myblobs (num, content) ` +
|
||||
`VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv`,
|
||||
{ n: 2, lobbv: {type: oracledb.BLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }); // a transaction needs to span the INSERT and pipe()
|
||||
|
||||
var inStream = fs.createReadStream(inFileName);
|
||||
inStream.on('error', function(err) {
|
||||
should.not.exist(err, "inStream.on 'end' event");
|
||||
});
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
assert.strictEqual(result.outBinds.lobbv.length, 1);
|
||||
|
||||
var lob = result.outBinds.lobbv[0];
|
||||
let inStream = await fs.createReadStream(inFileName);
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
let lob = result.outBinds.lobbv[0];
|
||||
await new Promise((resolve, reject) => {
|
||||
inStream.on('error', reject);
|
||||
lob.on('error', reject);
|
||||
lob.on('finish', resolve);
|
||||
inStream.pipe(lob);
|
||||
});
|
||||
await connection.commit();
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myblobs WHERE num = :n",
|
||||
{ n: 2 });
|
||||
|
||||
inStream.pipe(lob); // pipes the data to the BLOB
|
||||
lob = result.rows[0][0];
|
||||
|
||||
lob.on('finish', function() {
|
||||
connection.commit(function(err) {
|
||||
should.not.exist(err);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
},
|
||||
function blobstream1(callback) {
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myblobs WHERE num = :n",
|
||||
{ n: 2 },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
|
||||
var lob = result.rows[0][0];
|
||||
should.exist(lob);
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
|
||||
var outStream = fs.createWriteStream(outFileName);
|
||||
|
||||
outStream.on('error', function(err) {
|
||||
should.not.exist(err, "outStream.on 'error' event");
|
||||
});
|
||||
|
||||
lob.pipe(outStream);
|
||||
|
||||
outStream.on('finish', function() {
|
||||
fs.readFile(inFileName, function(err, originalData) {
|
||||
should.not.exist(err);
|
||||
|
||||
fs.readFile(outFileName, function(err, generatedData) {
|
||||
should.not.exist(err);
|
||||
originalData.should.eql(generatedData);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
}); // finish event
|
||||
}
|
||||
);
|
||||
},
|
||||
function blobstream2(callback) {
|
||||
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myblobs WHERE num = :n",
|
||||
{ n: 2 },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
|
||||
var blob = Buffer.alloc(0);
|
||||
var blobLength = 0;
|
||||
var lob = result.rows[0][0];
|
||||
|
||||
should.exist(lob);
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
|
||||
lob.on('data', function(chunk) {
|
||||
blobLength = blobLength + chunk.length;
|
||||
blob = Buffer.concat([blob, chunk], blobLength);
|
||||
});
|
||||
|
||||
lob.on('end', function() {
|
||||
fs.readFile(inFileName, function(err, data) {
|
||||
should.not.exist(err);
|
||||
data.length.should.be.exactly(blob.length);
|
||||
data.should.eql(blob);
|
||||
callback();
|
||||
});
|
||||
}); // close event
|
||||
|
||||
}
|
||||
);
|
||||
},
|
||||
function deleteOutFile(callback) {
|
||||
fs.unlink(outFileName, function(err) {
|
||||
should.not.exist(err);
|
||||
callback();
|
||||
await new Promise((resolve, reject) => {
|
||||
lob.on('error', reject);
|
||||
let outStream = fs.createWriteStream(outFileName);
|
||||
outStream.on('error', reject);
|
||||
lob.pipe(outStream);
|
||||
outStream.on('finish', async function() {
|
||||
await fs.readFile(inFileName, function(err, originalData) {
|
||||
assert.ifError(err);
|
||||
fs.readFile(outFileName, function(err, generatedData) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(originalData, generatedData);
|
||||
});
|
||||
});
|
||||
}
|
||||
], done);
|
||||
resolve();
|
||||
}); // finish event
|
||||
});
|
||||
await connection.commit();
|
||||
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myblobs WHERE num = :n",
|
||||
{ n: 2 });
|
||||
let blob = Buffer.alloc(0);
|
||||
let blobLength = 0;
|
||||
lob = result.rows[0][0];
|
||||
await new Promise((resolve, reject) => {
|
||||
lob.on("error", reject);
|
||||
|
||||
lob.on('data', async function(chunk) {
|
||||
blobLength = blobLength + chunk.length;
|
||||
blob = await lob.getData();
|
||||
});
|
||||
|
||||
lob.on('end', async function() {
|
||||
await fs.readFile(inFileName, function(err, data) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(data.length, blob.length);
|
||||
assert.deepEqual(data, blob);
|
||||
resolve();
|
||||
});
|
||||
}); // close event
|
||||
});
|
||||
await fs.unlinkSync(outFileName);
|
||||
}); // 41.1.1
|
||||
|
||||
it('41.1.2 BLOB getData()', function(done) {
|
||||
connection.should.be.ok();
|
||||
async.series([
|
||||
function blobinsert1(callback) {
|
||||
it('41.1.2 BLOB getData()', async function() {
|
||||
|
||||
connection.execute(
|
||||
"INSERT INTO nodb_myblobs (num, content) VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv",
|
||||
{ n: 3, lobbv: {type: oracledb.BLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }, // a transaction needs to span the INSERT and pipe()
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
(result.outBinds.lobbv.length).should.be.exactly(1);
|
||||
let result = await connection.execute(
|
||||
`INSERT INTO nodb_myblobs (num, content) ` +
|
||||
`VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv`,
|
||||
{ n: 3, lobbv: {type: oracledb.BLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }); // a transaction needs to span the INSERT and pipe()
|
||||
|
||||
var inStream = fs.createReadStream(inFileName);
|
||||
inStream.on('error', function(err) {
|
||||
should.not.exist(err, "inStream.on 'end' event");
|
||||
});
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
assert.strictEqual(result.outBinds.lobbv.length, 1);
|
||||
|
||||
var lob = result.outBinds.lobbv[0];
|
||||
let inStream = fs.createReadStream(inFileName);
|
||||
inStream.on('error', function(err) {
|
||||
assert.ifError(err, "inStream.on 'end' event");
|
||||
});
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
let lob = result.outBinds.lobbv[0];
|
||||
await new Promise((resolve, reject) => {
|
||||
lob.on("error", reject);
|
||||
|
||||
inStream.pipe(lob); // pipes the data to the BLOB
|
||||
inStream.pipe(lob); // pipes the data to the BLOB
|
||||
|
||||
lob.on('finish', function() {
|
||||
connection.commit(function(err) {
|
||||
should.not.exist(err);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
lob.on('finish', async function() {
|
||||
await connection.commit();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myblobs WHERE num = :n",
|
||||
{ n: 3 });
|
||||
|
||||
}
|
||||
);
|
||||
},
|
||||
function blobstream2(callback) {
|
||||
lob = result.rows[0][0];
|
||||
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myblobs WHERE num = :n",
|
||||
{ n: 3 },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
|
||||
var lob = result.rows[0][0];
|
||||
should.exist(lob);
|
||||
|
||||
fs.readFile(inFileName, function(err, data) {
|
||||
should.not.exist(err);
|
||||
lob.getData(function(err, blob) {
|
||||
data.length.should.be.exactly(blob.length);
|
||||
data.should.eql(blob);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
], done);
|
||||
await fs.readFile(inFileName, function(err, data) {
|
||||
assert.ifError(err);
|
||||
lob.getData(function(err, blob) {
|
||||
assert.strictEqual(data.length, blob.length);
|
||||
assert.strictEqual(data, blob);
|
||||
});
|
||||
});
|
||||
}); // 41.1.2
|
||||
|
||||
}); //41.1
|
||||
|
||||
describe('41.2 stores null value correctly', function() {
|
||||
it('41.2.1 testing Null, Empty string and Undefined', function(done) {
|
||||
assist.verifyNullValues(connection, tableName, done);
|
||||
it('41.2.1 testing Null, Empty string and Undefined', async function() {
|
||||
await assist.verifyNullValues(connection, tableName);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
|
||||
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
|
@ -37,267 +37,137 @@
|
|||
*****************************************************************************/
|
||||
'use strict';
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var should = require('should');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
var assist = require('./dataTypeAssist.js');
|
||||
const oracledb = require('oracledb');
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const dbConfig = require('./dbconfig.js');
|
||||
const assist = require('./dataTypeAssist.js');
|
||||
|
||||
var inFileName = 'test/clobexample.txt'; // the file with text to be inserted into the database
|
||||
var outFileName = 'test/clobstreamout.txt';
|
||||
let inFileName = 'test/clobexample.txt'; // the file with text to be inserted into the database
|
||||
let outFileName = 'test/clobstreamout.txt'; // output file with the stream out data
|
||||
|
||||
describe('40. dataTypeClob.js', function() {
|
||||
|
||||
var connection = null;
|
||||
var tableName = "nodb_myclobs";
|
||||
let connection = null;
|
||||
let tableName = "nodb_myclobs";
|
||||
|
||||
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.release(function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
after('release connection', async function() {
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
describe('40.1 testing CLOB data type', function() {
|
||||
before('create table', function(done) {
|
||||
assist.createTable(connection, tableName, done);
|
||||
before('create table', async function() {
|
||||
await connection.execute(assist.sqlCreateTable(tableName));
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP table " + tableName + " PURGE",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute("DROP table " + tableName + " PURGE");
|
||||
});
|
||||
|
||||
it('40.1.1 stores CLOB value correctly', function(done) {
|
||||
connection.should.be.ok();
|
||||
async.series([
|
||||
function clobinsert1(callback) {
|
||||
it('40.1.1 stores CLOB value correctly', async function() {
|
||||
let result = await connection.execute(
|
||||
'INSERT INTO nodb_myclobs (num, content) ' +
|
||||
'VALUES (:n, EMPTY_CLOB()) RETURNING content INTO :lobbv',
|
||||
{ n: 1, lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }); // a transaction needs to span the INSERT and pipe()
|
||||
|
||||
connection.execute(
|
||||
"INSERT INTO nodb_myclobs (num, content) VALUES (:n, EMPTY_CLOB()) RETURNING content INTO :lobbv",
|
||||
{ n: 1, lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }, // a transaction needs to span the INSERT and pipe()
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
(result.outBinds.lobbv.length).should.be.exactly(1);
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
assert.strictEqual(result.outBinds.lobbv.length, 1);
|
||||
|
||||
var inStream = fs.createReadStream(inFileName);
|
||||
var lob = result.outBinds.lobbv[0];
|
||||
let inStream = await fs.createReadStream(inFileName);
|
||||
let lob = result.outBinds.lobbv[0];
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
await new Promise((resolve, reject) => {
|
||||
inStream.on('error', reject);
|
||||
lob.on('error', reject);
|
||||
lob.on('finish', resolve);
|
||||
inStream.pipe(lob);
|
||||
});
|
||||
await connection.commit();
|
||||
|
||||
inStream.on('error', function(err) {
|
||||
should.not.exist(err, "inStream.on 'error' event");
|
||||
});
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 1 });
|
||||
|
||||
lob.on('finish', function() {
|
||||
// now commit updates
|
||||
connection.commit(function(err) {
|
||||
should.not.exist(err);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
lob = result.rows[0][0];
|
||||
lob.setEncoding('utf8');
|
||||
await new Promise((resolve, reject) => {
|
||||
lob.on("error", reject);
|
||||
const outStream = fs.createWriteStream(outFileName);
|
||||
outStream.on('error', reject);
|
||||
outStream.on('finish', resolve);
|
||||
lob.pipe(outStream);
|
||||
});
|
||||
const originalData = fs.readFileSync(inFileName, { encoding: 'utf8' });
|
||||
const generatedData = fs.readFileSync(outFileName, { encoding: 'utf8' });
|
||||
assert.strictEqual(originalData, generatedData);
|
||||
|
||||
inStream.pipe(lob); // copies the text to the CLOB
|
||||
}
|
||||
);
|
||||
},
|
||||
function clobstream1(callback) {
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 1 },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 1 });
|
||||
|
||||
var lob = result.rows[0][0];
|
||||
should.exist(lob);
|
||||
lob.setEncoding('utf8');
|
||||
lob = result.rows[0][0];
|
||||
let clob = await lob.getData();
|
||||
const data = fs.readFileSync(inFileName, { encoding: 'utf8' });
|
||||
assert.strictEqual(data, clob);
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 1 },
|
||||
{ outFormat: oracledb.OUT_FORMAT_OBJECT });
|
||||
|
||||
var outStream = fs.createWriteStream(outFileName);
|
||||
outStream.on('error', function(err) {
|
||||
should.not.exist(err, "outStream.on 'error' event");
|
||||
});
|
||||
|
||||
lob.pipe(outStream);
|
||||
|
||||
outStream.on('finish', function() {
|
||||
|
||||
fs.readFile(inFileName, { encoding: 'utf8' }, function(err, originalData) {
|
||||
should.not.exist(err);
|
||||
|
||||
fs.readFile(outFileName, { encoding: 'utf8' }, function(err, generatedData) {
|
||||
should.not.exist(err);
|
||||
originalData.should.equal(generatedData);
|
||||
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
},
|
||||
function clobstream2(callback) {
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 1 },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
|
||||
var clob = '';
|
||||
var lob = result.rows[0][0];
|
||||
should.exist(lob);
|
||||
lob.setEncoding('utf8'); // set the encoding so we get a 'string' not a 'buffer'
|
||||
|
||||
lob.on('data', function(chunk) {
|
||||
clob += chunk;
|
||||
});
|
||||
|
||||
lob.on('end', function() {
|
||||
fs.readFile(inFileName, { encoding: 'utf8' }, function(err, data) {
|
||||
should.not.exist(err);
|
||||
data.length.should.be.exactly(clob.length);
|
||||
data.should.equal(clob);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
function objectOutFormat(callback) {
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 1 },
|
||||
{ outFormat: oracledb.OUT_FORMAT_OBJECT },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
|
||||
var clob = '';
|
||||
var row = result.rows[0];
|
||||
var lob = row['CONTENT'];
|
||||
|
||||
lob.setEncoding('utf8');
|
||||
|
||||
lob.on('data', function(chunk) {
|
||||
clob = clob + chunk;
|
||||
});
|
||||
|
||||
lob.on('end', function() {
|
||||
callback();
|
||||
});
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
function deleteOutFile(callback) {
|
||||
fs.unlink(outFileName, function(err) {
|
||||
should.not.exist(err);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
], done); // async
|
||||
let row = result.rows[0];
|
||||
lob = row['CONTENT'];
|
||||
clob = await lob.getData();
|
||||
assert.strictEqual(data, clob);
|
||||
fs.unlinkSync(outFileName);
|
||||
|
||||
}); // 40.1.1
|
||||
|
||||
|
||||
it('40.1.2 CLOB getData()', function(done) {
|
||||
connection.should.be.ok();
|
||||
async.series([
|
||||
function clobinsert1(callback) {
|
||||
it('40.1.2 CLOB getData()', async function() {
|
||||
|
||||
connection.execute(
|
||||
"INSERT INTO nodb_myclobs (num, content) VALUES (:n, EMPTY_CLOB()) RETURNING content INTO :lobbv",
|
||||
{ n: 2, lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }, // a transaction needs to span the INSERT and pipe()
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
(result.outBinds.lobbv.length).should.be.exactly(1);
|
||||
let result = await connection.execute(
|
||||
`INSERT INTO nodb_myclobs (num, content) ` +
|
||||
`VALUES (:n, EMPTY_CLOB()) RETURNING content INTO :lobbv`,
|
||||
{ n: 2, lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT} },
|
||||
{ autoCommit: false }); // a transaction needs to span the INSERT and pipe()
|
||||
|
||||
var inStream = fs.createReadStream(inFileName);
|
||||
var lob = result.outBinds.lobbv[0];
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
assert.strictEqual(result.outBinds.lobbv.length, 1);
|
||||
|
||||
lob.on('error', function(err) {
|
||||
should.not.exist(err, "lob.on 'error' event");
|
||||
});
|
||||
let inStream = await fs.createReadStream(inFileName);
|
||||
let lob = result.outBinds.lobbv[0];
|
||||
|
||||
inStream.on('error', function(err) {
|
||||
should.not.exist(err, "inStream.on 'error' event");
|
||||
});
|
||||
await new Promise((resolve, reject) => {
|
||||
inStream.on('error', reject);
|
||||
lob.on('error', reject);
|
||||
lob.on('finish', resolve);
|
||||
inStream.pipe(lob);
|
||||
});
|
||||
await connection.commit();
|
||||
|
||||
lob.on('finish', function() {
|
||||
// now commit updates
|
||||
connection.commit(function(err) {
|
||||
should.not.exist(err);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
result = await connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 2 });
|
||||
|
||||
inStream.pipe(lob); // copies the text to the CLOB
|
||||
}
|
||||
);
|
||||
},
|
||||
function clobgetval(callback) {
|
||||
connection.execute(
|
||||
"SELECT content FROM nodb_myclobs WHERE num = :n",
|
||||
{ n: 2 },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
lob = result.rows[0][0];
|
||||
|
||||
var lob = result.rows[0][0];
|
||||
should.exist(lob);
|
||||
|
||||
fs.readFile(inFileName, { encoding: 'utf8' }, function(err, data) {
|
||||
should.not.exist(err);
|
||||
lob.getData(function(err, clob) {
|
||||
should.not.exist(err);
|
||||
data.length.should.be.exactly(clob.length);
|
||||
data.should.equal(clob);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
], done); // async
|
||||
const data = fs.readFileSync(inFileName, { encoding: 'utf8' });
|
||||
const clob = await lob.getData();
|
||||
assert.strictEqual(data, clob);
|
||||
|
||||
}); // 40.1.2
|
||||
|
||||
}); // 40.1
|
||||
|
||||
describe('40.2 stores null value correctly', function() {
|
||||
it('40.2.1 testing Null, Empty string and Undefined', function(done) {
|
||||
assist.verifyNullValues(connection, tableName, done);
|
||||
it('40.2.1 testing Null, Empty string and Undefined', async function() {
|
||||
await assist.verifyNullValues(connection, tableName);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates. */
|
||||
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
|
@ -31,141 +31,117 @@
|
|||
*****************************************************************************/
|
||||
'use strict';
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var should = require('should');
|
||||
var async = require('async');
|
||||
var assist = require('./dataTypeAssist.js');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
var random = require('./random.js');
|
||||
const oracledb = require('oracledb');
|
||||
const assert = require('assert');
|
||||
const assist = require('./dataTypeAssist.js');
|
||||
const dbConfig = require('./dbconfig.js');
|
||||
const random = require('./random.js');
|
||||
|
||||
describe('42. dataTypeRaw.js', function() {
|
||||
|
||||
var connection = null;
|
||||
var tableName = "nodb_raw";
|
||||
var insertID = 1;
|
||||
let connection = null;
|
||||
let tableName = "nodb_raw";
|
||||
let insertID = 1;
|
||||
|
||||
var bufLen = [10, 100, 1000, 2000]; // buffer length
|
||||
var bufs = [];
|
||||
for (var i = 0; i < bufLen.length; i++)
|
||||
let bufLen = [10, 100, 1000, 2000]; // buffer length
|
||||
let bufs = [];
|
||||
for (let i = 0; i < bufLen.length; i++)
|
||||
bufs[i] = assist.createBuffer(bufLen[i]);
|
||||
|
||||
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.release(function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
after('close connection', async function() {
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
describe('42.1 testing RAW data in various lengths', function() {
|
||||
|
||||
before('create table, insert data', function(done) {
|
||||
assist.setUp(connection, tableName, bufs, done);
|
||||
before('create table, insert data', async function() {
|
||||
await new Promise((resolve) => {
|
||||
assist.setUp(connection, tableName, bufs, resolve);
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP table " + tableName + " PURGE",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute("DROP table " + tableName + " PURGE");
|
||||
});
|
||||
|
||||
it('42.1.1 SELECT query', function(done) {
|
||||
assist.dataTypeSupport(connection, tableName, bufs, done);
|
||||
it('42.1.1 SELECT query', async function() {
|
||||
await new Promise((resolve) => {
|
||||
assist.dataTypeSupport(connection, tableName, bufs, resolve);
|
||||
});
|
||||
});
|
||||
|
||||
it('42.1.2 resultSet stores RAW data correctly', function(done) {
|
||||
assist.verifyResultSet(connection, tableName, bufs, done);
|
||||
it('42.1.2 resultSet stores RAW data correctly', async function() {
|
||||
await new Promise((resolve) => {
|
||||
assist.verifyResultSet(connection, tableName, bufs, resolve);
|
||||
});
|
||||
});
|
||||
|
||||
it('42.1.3 works well with REF Cursor', function(done) {
|
||||
assist.verifyRefCursor(connection, tableName, bufs, done);
|
||||
it('42.1.3 works well with REF Cursor', async function() {
|
||||
await new Promise((resolve) => {
|
||||
assist.verifyRefCursor(connection, tableName, bufs, resolve);
|
||||
});
|
||||
});
|
||||
|
||||
it('42.1.4 result set getRow() function works well with RAW', function(done) {
|
||||
it('42.1.4 result set getRow() function works well with RAW', async function() {
|
||||
|
||||
var sql1 = "select dummy, HEXTORAW('0123456789ABCDEF0123456789ABCDEF') from dual";
|
||||
connection.execute(
|
||||
let sql1 = "select dummy, HEXTORAW('0123456789ABCDEF0123456789ABCDEF') from dual";
|
||||
let result = await connection.execute(
|
||||
sql1,
|
||||
[],
|
||||
{ resultSet: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
fetchOneRowFromRS(result.resultSet, done);
|
||||
}
|
||||
);
|
||||
{ resultSet: true });
|
||||
|
||||
function fetchOneRowFromRS(rs, cb) {
|
||||
rs.getRow(function(err, row) {
|
||||
should.not.exist(err);
|
||||
if (row) {
|
||||
fetchOneRowFromRS(rs, cb);
|
||||
} else {
|
||||
rs.close(function(err) {
|
||||
should.not.exist(err);
|
||||
cb();
|
||||
});
|
||||
}
|
||||
});
|
||||
await fetchOneRowFromRS(result.resultSet);
|
||||
|
||||
async function fetchOneRowFromRS(rs) {
|
||||
let row = await rs.getRow();
|
||||
|
||||
if (row) {
|
||||
await fetchOneRowFromRS(rs);
|
||||
} else {
|
||||
await rs.close();
|
||||
}
|
||||
}
|
||||
}); // 42.1.4
|
||||
|
||||
it('42.1.5 a negative case which hits NJS-011 error', function(done) {
|
||||
connection.execute(
|
||||
"INSERT INTO " + tableName + " (content ) VALUES (:c)",
|
||||
{ c : { val: 1234, type: oracledb.BUFFER, dir:oracledb.BIND_IN } },
|
||||
function(err, result) {
|
||||
should.exist(err);
|
||||
// NJS-011: encountered bind value and type mismatch
|
||||
(err.message).should.startWith('NJS-011:');
|
||||
should.not.exist(result);
|
||||
done();
|
||||
}
|
||||
it('42.1.5 a negative case which hits NJS-011 error', async function() {
|
||||
await assert.rejects(
|
||||
async () => await connection.execute(
|
||||
"INSERT INTO " + tableName + " (content ) VALUES (:c)",
|
||||
{ c : { val: 1234, type: oracledb.BUFFER, dir:oracledb.BIND_IN } }),
|
||||
// NJS-011: encountered bind value and type mismatch
|
||||
/NJS-011:/
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('42.2 stores null value correctly', function() {
|
||||
it('42.2.1 testing Null, Empty string and Undefined', function(done) {
|
||||
assist.verifyNullValues(connection, tableName, done);
|
||||
it('42.2.1 testing Null, Empty string and Undefined', async function() {
|
||||
await new Promise((resolve) => {
|
||||
assist.verifyNullValues(connection, tableName, resolve);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('42.3 DML Returning', function() {
|
||||
|
||||
before('create table', function(done) {
|
||||
assist.createTable(connection, tableName, done);
|
||||
before('create table', async function() {
|
||||
await connection.execute(assist.sqlCreateTable(tableName));
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP table " + tableName + " PURGE",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute("DROP table " + tableName + " PURGE");
|
||||
});
|
||||
|
||||
it('42.3.1 INSERT statement with Object binding', function(done) {
|
||||
var seq = 1;
|
||||
var size = 10;
|
||||
var bindValue = assist.createBuffer(size);
|
||||
it('42.3.1 INSERT statement with Object binding', async function() {
|
||||
let seq = 1;
|
||||
let size = 10;
|
||||
let bindValue = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
|
||||
{
|
||||
n : seq,
|
||||
|
@ -173,22 +149,18 @@ describe('42. dataTypeRaw.js', function() {
|
|||
rid : { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
|
||||
rc : { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 2000 }
|
||||
},
|
||||
{ autoCommit: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.strictEqual(result.outBinds.rid[0], seq);
|
||||
should.deepEqual(result.outBinds.rc[0], bindValue);
|
||||
done();
|
||||
}
|
||||
);
|
||||
{ autoCommit: true });
|
||||
|
||||
assert.strictEqual(result.outBinds.rid[0], seq);
|
||||
assert.deepEqual(result.outBinds.rc[0], bindValue);
|
||||
}); // 42.3.1
|
||||
|
||||
it('42.3.2 INSERT statement with ARRAY binding', function(done) {
|
||||
var seq = 2;
|
||||
var size = 10;
|
||||
var bindValue = assist.createBuffer(size);
|
||||
it('42.3.2 INSERT statement with ARRAY binding', async function() {
|
||||
let seq = 2;
|
||||
let size = 10;
|
||||
let bindValue = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
|
||||
[
|
||||
seq,
|
||||
|
@ -196,22 +168,17 @@ describe('42. dataTypeRaw.js', function() {
|
|||
{ type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
|
||||
{ type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 2000 }
|
||||
],
|
||||
{ autoCommit: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.strictEqual(result.outBinds[0][0], seq);
|
||||
should.deepEqual(result.outBinds[1][0], bindValue);
|
||||
done();
|
||||
}
|
||||
);
|
||||
{ autoCommit: true });
|
||||
assert.strictEqual(result.outBinds[0][0], seq);
|
||||
assert.deepEqual(result.outBinds[1][0], bindValue);
|
||||
}); // 42.3.2
|
||||
|
||||
it('42.3.3 INSERT statement with exact maxSize restriction', function(done) {
|
||||
var seq = 3;
|
||||
var size = 100;
|
||||
var bindValue = assist.createBuffer(size);
|
||||
it('42.3.3 INSERT statement with exact maxSize restriction', async function() {
|
||||
let seq = 3;
|
||||
let size = 100;
|
||||
let bindValue = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"INSERT INTO " + tableName + " VALUES (:n, :c) RETURNING num, content INTO :rid, :rc",
|
||||
{
|
||||
n : seq,
|
||||
|
@ -219,22 +186,17 @@ describe('42. dataTypeRaw.js', function() {
|
|||
rid : { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
|
||||
rc : { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: size}
|
||||
},
|
||||
{ autoCommit: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.strictEqual(result.outBinds.rid[0], seq);
|
||||
should.deepEqual(result.outBinds.rc[0], bindValue);
|
||||
done();
|
||||
}
|
||||
);
|
||||
{ autoCommit: true });
|
||||
assert.strictEqual(result.outBinds.rid[0], seq);
|
||||
assert.deepEqual(result.outBinds.rc[0], bindValue);
|
||||
});
|
||||
|
||||
it('42.3.4 UPDATE statement', function(done) {
|
||||
var seq = 2;
|
||||
var size = 10;
|
||||
var bindValue = assist.createBuffer(size);
|
||||
it('42.3.4 UPDATE statement', async function() {
|
||||
let seq = 2;
|
||||
let size = 10;
|
||||
let bindValue = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"UPDATE " + tableName + " SET content = :c WHERE num = :n RETURNING num, content INTO :rid, :rc",
|
||||
{
|
||||
n : seq,
|
||||
|
@ -242,378 +204,276 @@ describe('42. dataTypeRaw.js', function() {
|
|||
rid : { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
|
||||
rc : { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 2000 }
|
||||
},
|
||||
{ autoCommit: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.strictEqual(result.outBinds.rid[0], seq);
|
||||
should.deepEqual(result.outBinds.rc[0], bindValue);
|
||||
done();
|
||||
}
|
||||
);
|
||||
{ autoCommit: true });
|
||||
assert.strictEqual(result.outBinds.rid[0], seq);
|
||||
assert.deepEqual(result.outBinds.rc[0], bindValue);
|
||||
}); // 42.3.4
|
||||
|
||||
it('42.3.5 DELETE statement with single row matching', function(done) {
|
||||
var seq = 1;
|
||||
it('42.3.5 DELETE statement with single row matching', async function() {
|
||||
let seq = 1;
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"DELETE FROM " + tableName + " WHERE num = :1 RETURNING num, content INTO :2, :3",
|
||||
[
|
||||
seq,
|
||||
{ type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
|
||||
{ type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 2000 }
|
||||
],
|
||||
{ autoCommit: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.strictEqual(result.outBinds[0][0], seq);
|
||||
done();
|
||||
}
|
||||
);
|
||||
{ autoCommit: true });
|
||||
assert.strictEqual(result.outBinds[0][0], seq);
|
||||
});
|
||||
|
||||
it('42.3.6 DELETE statement with multiple rows matching', function(done) {
|
||||
var seq = 1;
|
||||
it('42.3.6 DELETE statement with multiple rows matching', async function() {
|
||||
let seq = 1;
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"DELETE FROM " + tableName + " WHERE num > :n RETURNING num, content INTO :rid, :rc",
|
||||
{
|
||||
n : seq,
|
||||
rid : { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
|
||||
rc : { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 2000 }
|
||||
},
|
||||
{ autoCommit: true },
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.deepEqual(result.outBinds.rid, [2, 3]);
|
||||
done();
|
||||
}
|
||||
);
|
||||
{ autoCommit: true });
|
||||
assert.deepEqual(result.outBinds.rid, [2, 3]);
|
||||
});
|
||||
|
||||
}); // 42.3
|
||||
|
||||
describe('42.4 in PL/SQL, the maximum size is 32767', function() {
|
||||
|
||||
var proc =
|
||||
let proc =
|
||||
"CREATE OR REPLACE PROCEDURE nodb_testraw (p_in IN RAW, p_out OUT RAW) " +
|
||||
"AS " +
|
||||
"BEGIN " +
|
||||
" p_out := p_in; " +
|
||||
"END; ";
|
||||
|
||||
before('create procedure', function(done) {
|
||||
connection.execute(
|
||||
proc,
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
before('create procedure', async function() {
|
||||
await connection.execute(proc);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP PROCEDURE nodb_testraw",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute("DROP PROCEDURE nodb_testraw");
|
||||
});
|
||||
|
||||
it('42.4.1 works well when the length of data is less than maxSize', function(done) {
|
||||
var size = 5;
|
||||
var buf = assist.createBuffer(size);
|
||||
it('42.4.1 works well when the length of data is less than maxSize', async function() {
|
||||
let size = 5;
|
||||
let buf = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"BEGIN nodb_testraw(:i, :o); END;",
|
||||
{
|
||||
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
|
||||
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 32800}
|
||||
},
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
});
|
||||
|
||||
(Buffer.isBuffer(result.outBinds.o)).should.equal(true, "Error: the bind out data is not a Buffer");
|
||||
(result.outBinds.o.length).should.be.exactly(size);
|
||||
done();
|
||||
}
|
||||
);
|
||||
assert.strictEqual(Buffer.isBuffer(result.outBinds.o), true);
|
||||
assert.strictEqual(result.outBinds.o.length, size);
|
||||
});
|
||||
|
||||
it('42.4.2 works well when the length of data is exactly 32767', function(done) {
|
||||
var size = 32767;
|
||||
var buf = assist.createBuffer(size);
|
||||
it('42.4.2 works well when the length of data is exactly 32767', async function() {
|
||||
let size = 32767;
|
||||
let buf = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
"BEGIN nodb_testraw(:i, :o); END;",
|
||||
{
|
||||
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
|
||||
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 32767}
|
||||
},
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
});
|
||||
|
||||
(Buffer.isBuffer(result.outBinds.o)).should.equal(true, "Error: the bind out data is not a Buffer");
|
||||
(result.outBinds.o.length).should.be.exactly(size);
|
||||
done();
|
||||
}
|
||||
assert.deepEqual(Buffer.isBuffer(result.outBinds.o), true);
|
||||
assert.strictEqual(result.outBinds.o.length, size);
|
||||
});
|
||||
|
||||
it('42.4.3 throws error when the length of data is greater than maxSize', async function() {
|
||||
let size = 32700;
|
||||
let buf = assist.createBuffer(size);
|
||||
|
||||
await assert.rejects(
|
||||
async () => await connection.execute(
|
||||
"BEGIN nodb_testraw(:i, :o); END;",
|
||||
{
|
||||
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
|
||||
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: (size - 100) }
|
||||
}),
|
||||
// ORA-06502: PL/SQL: numeric or value error\nORA-06512: at line 1
|
||||
/ORA-06502:/
|
||||
);
|
||||
});
|
||||
|
||||
it('42.4.3 throws error when the length of data is greater than maxSize', function(done) {
|
||||
var size = 32700;
|
||||
var buf = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
"BEGIN nodb_testraw(:i, :o); END;",
|
||||
{
|
||||
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
|
||||
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: (size - 100) }
|
||||
},
|
||||
function(err) {
|
||||
should.exist(err);
|
||||
// ORA-06502: PL/SQL: numeric or value error\nORA-06512: at line 1
|
||||
(err.message).should.startWith('ORA-06502:');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('42.4.4 throws error when both data and maxSize are greater than 32767', function(done) {
|
||||
var size = 32800;
|
||||
var buf = assist.createBuffer(size);
|
||||
|
||||
connection.execute(
|
||||
"BEGIN nodb_testraw(:i, :o); END;",
|
||||
{
|
||||
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
|
||||
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 40000}
|
||||
},
|
||||
function(err) {
|
||||
should.exist(err);
|
||||
// ORA-06502: PL/SQL: numeric or value error\nORA-06512: at line 1
|
||||
(err.message).should.startWith('ORA-06502:');
|
||||
done();
|
||||
}
|
||||
it('42.4.4 throws error when both data and maxSize are greater than 32767', async function() {
|
||||
let size = 32800;
|
||||
let buf = assist.createBuffer(size);
|
||||
await assert.rejects(
|
||||
async () => await connection.execute(
|
||||
"BEGIN nodb_testraw(:i, :o); END;",
|
||||
{
|
||||
i: { type: oracledb.BUFFER, dir: oracledb.BIND_IN, val: buf },
|
||||
o: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: 40000}
|
||||
}),
|
||||
// ORA-06502: PL/SQL: numeric or value error\nORA-06512: at line 1
|
||||
/ORA-06502:/
|
||||
);
|
||||
});
|
||||
}); // 42.4
|
||||
|
||||
describe('42.5 INSERT and SELECT', function() {
|
||||
before(function(done) {
|
||||
assist.createTable(connection, tableName, done);
|
||||
before(async function() {
|
||||
await connection.execute(assist.sqlCreateTable(tableName));
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP table " + tableName + " PURGE",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute(
|
||||
"DROP table " + tableName + " PURGE");
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function() {
|
||||
insertID++;
|
||||
done();
|
||||
});
|
||||
|
||||
it('42.5.1 works with data size 100', function(done) {
|
||||
var insertedStr = random.getRandomLengthString(100);
|
||||
var insertedBuf = Buffer.from(insertedStr);
|
||||
test1(insertedBuf, done);
|
||||
it('42.5.1 works with data size 100', async function() {
|
||||
let insertedStr = random.getRandomLengthString(100);
|
||||
let insertedBuf = Buffer.from(insertedStr);
|
||||
await test1(insertedBuf);
|
||||
});
|
||||
|
||||
it('42.5.2 works with data size 2000', function(done) {
|
||||
var insertedStr = random.getRandomLengthString(2000);
|
||||
var insertedBuf = Buffer.from(insertedStr);
|
||||
test1(insertedBuf, done);
|
||||
it('42.5.2 works with data size 2000', async function() {
|
||||
let insertedStr = random.getRandomLengthString(2000);
|
||||
let insertedBuf = Buffer.from(insertedStr);
|
||||
await test1(insertedBuf);
|
||||
});
|
||||
|
||||
it('42.5.3 works with default type/dir', function(done) {
|
||||
var insertedStr = random.getRandomLengthString(2000);
|
||||
var insertedBuf = Buffer.from(insertedStr);
|
||||
test1_default(insertedBuf, done);
|
||||
it('42.5.3 works with default type/dir', async function() {
|
||||
let insertedStr = random.getRandomLengthString(2000);
|
||||
let insertedBuf = Buffer.from(insertedStr);
|
||||
await test1_default(insertedBuf);
|
||||
});
|
||||
|
||||
}); // 42.5
|
||||
|
||||
describe('42.6 UPDATE', function() {
|
||||
before(function(done) {
|
||||
assist.createTable(connection, tableName, done);
|
||||
before(async function() {
|
||||
await connection.execute(assist.sqlCreateTable(tableName));
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
connection.execute(
|
||||
"DROP table " + tableName + " PURGE",
|
||||
function(err) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
}
|
||||
);
|
||||
after(async function() {
|
||||
await connection.execute("DROP table " + tableName + " PURGE");
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function() {
|
||||
insertID++;
|
||||
done();
|
||||
});
|
||||
|
||||
it('42.6.1 works with data size 100', function(done) {
|
||||
var insertedStr = random.getRandomLengthString(20);
|
||||
var updateStr = random.getRandomLengthString(100);
|
||||
var insertedBuf = Buffer.from(insertedStr);
|
||||
var updateBuf = Buffer.from(updateStr);
|
||||
test2(insertedBuf, updateBuf, done);
|
||||
it('42.6.1 works with data size 100', async function() {
|
||||
let insertedStr = random.getRandomLengthString(20);
|
||||
let updateStr = random.getRandomLengthString(100);
|
||||
let insertedBuf = Buffer.from(insertedStr);
|
||||
let updateBuf = Buffer.from(updateStr);
|
||||
await test2(insertedBuf, updateBuf);
|
||||
});
|
||||
|
||||
it('42.6.2 works with data size 2000', function(done) {
|
||||
var insertedStr = random.getRandomLengthString(30);
|
||||
var updateStr = random.getRandomLengthString(2000);
|
||||
var insertedBuf = Buffer.from(insertedStr);
|
||||
var updateBuf = Buffer.from(updateStr);
|
||||
test2(insertedBuf, updateBuf, done);
|
||||
it('42.6.2 works with data size 2000', async function() {
|
||||
let insertedStr = random.getRandomLengthString(30);
|
||||
let updateStr = random.getRandomLengthString(2000);
|
||||
let insertedBuf = Buffer.from(insertedStr);
|
||||
let updateBuf = Buffer.from(updateStr);
|
||||
await test2(insertedBuf, updateBuf);
|
||||
});
|
||||
|
||||
it('42.6.3 works with default type/dir', function(done) {
|
||||
var insertedStr = random.getRandomLengthString(30);
|
||||
var updateStr = random.getRandomLengthString(2000);
|
||||
var insertedBuf = Buffer.from(insertedStr);
|
||||
var updateBuf = Buffer.from(updateStr);
|
||||
test2_default(insertedBuf, updateBuf, done);
|
||||
it('42.6.3 works with default type/dir', async function() {
|
||||
let insertedStr = random.getRandomLengthString(30);
|
||||
let updateStr = random.getRandomLengthString(2000);
|
||||
let insertedBuf = Buffer.from(insertedStr);
|
||||
let updateBuf = Buffer.from(updateStr);
|
||||
await test2_default(insertedBuf, updateBuf);
|
||||
});
|
||||
|
||||
}); // 42.6
|
||||
|
||||
var test1 = function(content, callback) {
|
||||
async.series([
|
||||
function(cb) {
|
||||
insert(content, cb);
|
||||
},
|
||||
function(cb) {
|
||||
fetch(content, cb);
|
||||
}
|
||||
], callback);
|
||||
let test1 = async function(content) {
|
||||
|
||||
await insert(content);
|
||||
|
||||
await fetch(content);
|
||||
};
|
||||
|
||||
var test1_default = function(content, callback) {
|
||||
async.series([
|
||||
function(cb) {
|
||||
insert_default(content, cb);
|
||||
},
|
||||
function(cb) {
|
||||
fetch(content, cb);
|
||||
}
|
||||
], callback);
|
||||
let test1_default = async function(content) {
|
||||
|
||||
await insert_default(content);
|
||||
|
||||
await fetch(content);
|
||||
};
|
||||
|
||||
var test2 = function(insertedStr, updateStr, callback) {
|
||||
async.series([
|
||||
function(cb) {
|
||||
insert(insertedStr, cb);
|
||||
},
|
||||
function(cb) {
|
||||
update(updateStr, cb);
|
||||
},
|
||||
function(cb) {
|
||||
fetch(updateStr, cb);
|
||||
}
|
||||
], callback);
|
||||
let test2 = async function(insertedStr, updateStr) {
|
||||
|
||||
await insert(insertedStr);
|
||||
|
||||
await update(updateStr);
|
||||
|
||||
await fetch(updateStr);
|
||||
};
|
||||
|
||||
var test2_default = function(insertedStr, updateStr, callback) {
|
||||
async.series([
|
||||
function(cb) {
|
||||
insert(insertedStr, cb);
|
||||
},
|
||||
function(cb) {
|
||||
update_default(updateStr, cb);
|
||||
},
|
||||
function(cb) {
|
||||
fetch(updateStr, cb);
|
||||
}
|
||||
], callback);
|
||||
let test2_default = async function(insertedStr, updateStr) {
|
||||
|
||||
await insert(insertedStr);
|
||||
|
||||
await update_default(updateStr);
|
||||
|
||||
await fetch(updateStr);
|
||||
};
|
||||
|
||||
var insert = function(content, callback) {
|
||||
var sql = "insert into " + tableName + " (num, content) values (:i, :c)";
|
||||
var bindVar = {
|
||||
let insert = async function(content) {
|
||||
let sql = "insert into " + tableName + " (num, content) values (:i, :c)";
|
||||
let bindVar = {
|
||||
i: { val: insertID, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
|
||||
c: { val: content, dir: oracledb.BIND_IN, type: oracledb.BUFFER }
|
||||
};
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
sql,
|
||||
bindVar,
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
callback();
|
||||
}
|
||||
);
|
||||
bindVar);
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
};
|
||||
|
||||
var insert_default = function(content, callback) {
|
||||
var sql = "insert into " + tableName + " (num, content) values (:i, :c)";
|
||||
var bindVar = {
|
||||
let insert_default = async function(content) {
|
||||
let sql = "insert into " + tableName + " (num, content) values (:i, :c)";
|
||||
let bindVar = {
|
||||
i: insertID,
|
||||
c: content
|
||||
};
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
sql,
|
||||
bindVar,
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
callback();
|
||||
}
|
||||
);
|
||||
bindVar);
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
};
|
||||
|
||||
var update = function(content, callback) {
|
||||
var sql = "update " + tableName + " set content = :c where num = :i";
|
||||
var bindVar = {
|
||||
let update = async function(content) {
|
||||
let sql = "update " + tableName + " set content = :c where num = :i";
|
||||
let bindVar = {
|
||||
i: { val: insertID, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
|
||||
c: { val: content, dir: oracledb.BIND_IN, type: oracledb.BUFFER }
|
||||
};
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
sql,
|
||||
bindVar,
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
callback();
|
||||
}
|
||||
);
|
||||
bindVar);
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
};
|
||||
|
||||
var update_default = function(content, callback) {
|
||||
var sql = "update " + tableName + " set content = :c where num = :i";
|
||||
var bindVar = {
|
||||
let update_default = async function(content) {
|
||||
let sql = "update " + tableName + " set content = :c where num = :i";
|
||||
let bindVar = {
|
||||
i: insertID,
|
||||
c: content
|
||||
};
|
||||
connection.execute(
|
||||
let result = await connection.execute(
|
||||
sql,
|
||||
bindVar,
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
(result.rowsAffected).should.be.exactly(1);
|
||||
callback();
|
||||
}
|
||||
);
|
||||
bindVar);
|
||||
assert.strictEqual(result.rowsAffected, 1);
|
||||
};
|
||||
|
||||
var fetch = function(expected, callback) {
|
||||
var sql = "select content from " + tableName + " where num = " + insertID;
|
||||
connection.execute(
|
||||
sql,
|
||||
function(err, result) {
|
||||
should.not.exist(err);
|
||||
assist.compare2Buffers(result.rows[0][0], expected);
|
||||
callback();
|
||||
}
|
||||
);
|
||||
let fetch = async function(expected) {
|
||||
let sql = "select content from " + tableName + " where num = " + insertID;
|
||||
let result = await connection.execute(sql);
|
||||
assist.compare2Buffers(result.rows[0][0], expected);
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -5240,3 +5240,19 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
|
|||
267.9 recipient list with enqMany
|
||||
267.10 recipient list with enqMany non-existent in dequeue
|
||||
267.11 recipient list with enqMany invalid datatype in dequeue
|
||||
268. procAndFuncs.js
|
||||
268.1 calling stored procedures
|
||||
268.1.1 executing a stored procedure
|
||||
268.1.2 executing a stored procedure with all args keyword args
|
||||
268.1.3 executing a stored procedure with last arg as keyword arg
|
||||
268.2 calling stored procedures no args
|
||||
268.2.1 executing a stored procedure with last arg as keyword arg
|
||||
268.3 calling functions
|
||||
268.3.1 executing a stored function
|
||||
268.3.2 executing a stored function with extra args
|
||||
268.3.3 executing a stored function with wrong function name
|
||||
268.3.4 executing a stored function with wrong args
|
||||
268.3.5 executing a stored function with no args
|
||||
268.3.6 executing a stored function with only one args
|
||||
268.4 calling functions without any arguments
|
||||
268.4.1 executing a stored function without any argument
|
||||
|
|
|
@ -250,3 +250,4 @@ spec:
|
|||
- test/asyncStack.js
|
||||
- test/methodName.js
|
||||
- test/aq4.js
|
||||
- test/procAndFuncs.js
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This software is dual-licensed to you under the Universal Permissive License
|
||||
* (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
|
||||
* 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose
|
||||
* either license.
|
||||
*
|
||||
* If you elect to accept the software under the Apache License, Version 2.0,
|
||||
* the following applies:
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* 268. procAndFuncs.js
|
||||
*
|
||||
* DESCRIPTION:
|
||||
* Tests for stored procedures and functions
|
||||
*
|
||||
*****************************************************************************/
|
||||
'use strict';
|
||||
|
||||
const oracledb = require('oracledb');
|
||||
const assert = require('assert');
|
||||
const dbConfig = require('./dbconfig.js');
|
||||
|
||||
describe('268. tests for calling stored procedures and functions', function() {
|
||||
describe('268.1 calling stored procedures', function() {
|
||||
let connection = null;
|
||||
|
||||
const script = `CREATE OR REPLACE PROCEDURE proc_Test (a_InValue IN VARCHAR2, a_InOutValue IN OUT NUMBER, a_OutValue OUT NUMBER) AS \n` +
|
||||
`BEGIN \n` +
|
||||
`a_InOutValue := a_InOutValue * length(a_InValue); \n` +
|
||||
`a_OutValue := length(a_InValue); \n` +
|
||||
`END;`;
|
||||
|
||||
before(async function() {
|
||||
connection = await oracledb.getConnection(dbConfig);
|
||||
await connection.execute(script);
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
await connection.execute(`DROP PROCEDURE proc_Test`);
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
it('268.1.1 executing a stored procedure', async function() {
|
||||
let outValue = { type: oracledb.NUMBER, dir: oracledb.BIND_OUT };
|
||||
let result = await connection.execute(
|
||||
`BEGIN proc_Test(:a_InValue, :a_InOutValue, :a_OutValue); END;`,
|
||||
{
|
||||
a_InValue: "hi",
|
||||
a_InOutValue: 5,
|
||||
a_OutValue: outValue
|
||||
},
|
||||
{ outFormat: oracledb.OBJECT }
|
||||
);
|
||||
assert.deepEqual(result.outBinds, { a_OutValue: 2 });
|
||||
});
|
||||
|
||||
it('268.1.2 executing a stored procedure with all args keyword args', async function() {
|
||||
let inout_value = {
|
||||
dir: oracledb.BIND_INOUT,
|
||||
type: oracledb.NUMBER,
|
||||
val: 5
|
||||
};
|
||||
let out_value = {
|
||||
dir: oracledb.BIND_OUT,
|
||||
type: oracledb.NUMBER
|
||||
};
|
||||
let results = await connection.execute(
|
||||
`BEGIN proc_Test(:a_InValue, :a_InOutValue, :a_OutValue); END;`,
|
||||
{
|
||||
a_InValue: 'hi',
|
||||
a_InOutValue: inout_value,
|
||||
a_OutValue: out_value
|
||||
}
|
||||
);
|
||||
assert(results.outBinds.a_InOutValue, 10);
|
||||
assert(results.outBinds.a_OutValue, 2.0);
|
||||
});
|
||||
|
||||
it('268.1.3 executing a stored procedure with last arg as keyword arg', async function() {
|
||||
|
||||
let outValue = { type: oracledb.NUMBER, dir: oracledb.BIND_OUT };
|
||||
let result = await connection.execute(`BEGIN proc_Test(:a_InValue, :a_InOutValue, :a_OutValue); END;`,
|
||||
{ a_InValue: "hi", a_InOutValue: 5, a_OutValue: outValue });
|
||||
|
||||
assert.strictEqual(result.outBinds.a_OutValue, 2.0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('268.2 calling stored procedures no args', function() {
|
||||
let connection = null;
|
||||
|
||||
const script = `CREATE OR REPLACE PROCEDURE proc_TestNoArgs AS \n` +
|
||||
`BEGIN \n` +
|
||||
`null; \n` +
|
||||
`END;`;
|
||||
|
||||
before(async function() {
|
||||
connection = await oracledb.getConnection(dbConfig);
|
||||
await connection.execute(script);
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
await connection.execute(`DROP PROCEDURE proc_TestNoArgs`);
|
||||
await connection.close();
|
||||
});
|
||||
it('268.2.1 executing a stored procedure with last arg as keyword arg', async function() {
|
||||
const result = await connection.execute(
|
||||
`BEGIN proc_TestNoArgs; END;`,
|
||||
[],
|
||||
{ outFormat: oracledb.OBJECT }
|
||||
);
|
||||
assert.deepEqual(result, {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('268.3 calling functions', function() {
|
||||
let connection = null;
|
||||
const script = `CREATE OR REPLACE FUNCTION function_Test(a_String VARCHAR2, a_ExtraAmount NUMBER) return number AS \n` +
|
||||
`BEGIN \n` +
|
||||
`return length(a_String) + a_ExtraAmount; \n` +
|
||||
`END;`;
|
||||
|
||||
before(async function() {
|
||||
connection = await oracledb.getConnection(dbConfig);
|
||||
await connection.execute(script);
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
await connection.execute(`DROP FUNCTION function_Test`);
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
it('268.3.1 executing a stored function', async function() {
|
||||
|
||||
let result = await connection.execute(`SELECT function_Test('hi', 5) as result FROM DUAL`, [], { outFormat: oracledb.OBJECT });
|
||||
assert.deepEqual(result.rows[0], {"RESULT":7});
|
||||
});
|
||||
|
||||
it('268.3.2 executing a stored function with extra args', async function() {
|
||||
await assert.rejects(
|
||||
async () => {
|
||||
await connection.execute(`SELECT function_Test('hi', 5, 7) as result FROM DUAL`, [], { outFormat: oracledb.OBJECT }),
|
||||
/ORA-06553:/; //Error: ORA-06553: PLS-306: wrong number or types of arguments in call to 'FUNCTION_TEST'
|
||||
});
|
||||
});
|
||||
|
||||
it('268.3.3 executing a stored function with wrong function name', async function() {
|
||||
await assert.rejects(
|
||||
async () => {
|
||||
await connection.execute(`SELECT fun_Test('hi', 5) as result FROM DUAL`, [], { outFormat: oracledb.OBJECT }),
|
||||
/ORA-12545:/; //ORA-12545: Connect failed because target host or object does not exist
|
||||
});
|
||||
});
|
||||
|
||||
it('268.3.4 executing a stored function with wrong args', async function() {
|
||||
await assert.rejects(
|
||||
async () => {
|
||||
await connection.execute(`SELECT function_Test(5, 'Hi') as result FROM DUAL`, [], { outFormat: oracledb.OBJECT }),
|
||||
/ORA-12545:/; //ORA-12545: Connect failed because target host or object does not exist
|
||||
});
|
||||
});
|
||||
|
||||
it('268.3.5 executing a stored function with no args', async function() {
|
||||
await assert.rejects(
|
||||
async () => {
|
||||
await connection.execute(`SELECT function_Test as result FROM DUAL`, [], { outFormat: oracledb.OBJECT }),
|
||||
/ORA-12545:/; //ORA-12545: Connect failed because target host or object does not exist
|
||||
});
|
||||
});
|
||||
|
||||
it('268.3.6 executing a stored function with only one args', async function() {
|
||||
await assert.rejects(
|
||||
async () => {
|
||||
await connection.execute(`SELECT function_Test('Hi') as result FROM DUAL`, [], { outFormat: oracledb.OBJECT }),
|
||||
/ORA-12545:/; //ORA-12545: Connect failed because target host or object does not exist
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('268.4 calling functions without any arguments', function() {
|
||||
let connection = null;
|
||||
const script = `CREATE OR REPLACE FUNCTION function_TestNoArgs return number AS \n` +
|
||||
`BEGIN \n` +
|
||||
`return 123; \n` +
|
||||
`END;`;
|
||||
|
||||
before(async function() {
|
||||
connection = await oracledb.getConnection(dbConfig);
|
||||
await connection.execute(script);
|
||||
});
|
||||
|
||||
after(async function() {
|
||||
await connection.execute(`DROP FUNCTION function_TestNoArgs`);
|
||||
await connection.close();
|
||||
});
|
||||
|
||||
it('268.4.1 executing a stored function without any arguments', async function() {
|
||||
|
||||
let result = await connection.execute(`SELECT function_TestNoArgs() as result FROM DUAL`, [], { outFormat: oracledb.OBJECT });
|
||||
assert.deepEqual(result.rows[0], {"RESULT": 123});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue