Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('56.5 Fetch DATE, NUMBER column as STRING by-type and override at execute time', function(done) {
oracledb.fetchAsString = [ oracledb.DATE, oracledb.NUMBER ];
connection.execute(
"SELECT 1234567 AS TS_NUM, TO_TIMESTAMP('1999-12-01 11:10:01.00123', 'YYYY-MM-DD HH:MI:SS.FF') AS TS_DATE FROM DUAL",
[],
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchInfo :
{
"TS_DATE" : { type : oracledb.DEFAULT },
"TS_NUM" : { type : oracledb.STRING }
}
},
function(err, result) {
should.not.exist(err);
// console.log(result.rows[0]);
result.rows[0].TS_DATE.should.be.an.Object;
function(cb) {
connection.execute(
"begin nodb_proc_tstz_bindin (:1, :2, :3); end;",
[
sequence,
{ val: bv1, dir: oracledb.BIND_IN, type: oracledb.DATE },
{ val: bv2, dir: oracledb.BIND_IN, type: inType }
],
{ autoCommit: true },
function(err) {
// console.log(err)
should.exist(err);
if (inType == oracledb.CURSOR) {
should.strictEqual(
err.message,
'NJS-007: invalid value for "type" in parameter 1'
);
} else {
should.strictEqual(
err.message,
"NJS-011: encountered bind value and type mismatch"
);
const oracledb = require("oracledb");
const _ = require("lodash/fp");
const { readJsonSync, outputJsonSync } = require("fs-extra");
const dbLoc = require("./nedb");
const { getDefaultsFromSchema, includesCaseInsensitive } = require("./utility");
oracledb.fetchAsString = [oracledb.DATE, oracledb.CLOB, oracledb.NUMBER];
export class DBConfig {
constructor(fileBase) {
// Defaults DB configuration object
this.defaults = getDefaultsFromSchema(
"../../resources/dbconfig-schema.json"
);
this.fileBase = fileBase || "./dbconfig.json";
// DB config JSON Object
this.object = null;
this.load();
}
// Create config file with default values
createFile() {
return outputJsonSync(this.fileBase, this.defaults);
it('56.18 Negative - passing oracledb.DATE type to fetchInfo', function(done) {
connection.execute(
"select sysdate as ts_date from dual",
{ },
{
fetchInfo: { ts_date: { type: oracledb.DATE } }
},
function(err, result) {
should.exist(err);
should.strictEqual(
err.message,
'NJS-021: invalid type for conversion specified'
);
should.not.exist(result);
done();
}
);
});
it('34.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString', function(done) {
oracledb.fetchAsString = [ oracledb.DATE ];
assist.verifyRefCursorWithFetchAsString(connection, tableName, dates, done);
});
it('6.2.6 UPDATE statements, multiple rows, TIMESTAMP data', function(done) {
var sql = "UPDATE " + tableName + " SET content = TO_TIMESTAMP_TZ('1999-12-01 11:00:00.123456 -8:00', 'YYYY-MM-DD HH:MI:SS.FF TZH:TZM') " +
" WHERE num < :n RETURNING num, content INTO :rnum, :rcontent";
var bindVar =
{
n: 100,
rnum: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
rcontent: { type: oracledb.DATE, dir: oracledb.BIND_OUT }
};
var isSingleMatch = false;
runSQL(sql, bindVar, isSingleMatch, done);
});
function(cb) {
var vdate = new Date( Date.UTC( 2016, 7, 5 ) );
connection.execute(
"BEGIN nodb_binddate2(:i, :o); END;",
{
i: { type: oracledb.DATE, dir: oracledb.BIND_IN, val: vdate },
o: { type: oracledb.DATE, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
var vdate = new Date( "2016-08-05T00:00:00.000Z" );
(result.outBinds.o).should.eql(vdate);
cb();
}
);
},
function(cb) {
var getInsertVal = function(element, nullBind) {
var insertValue = [];
if(element.indexOf("CHAR") > -1 || element === "CLOB") {
insertValue[0] = (nullBind===true) ? null : "abcsca";
insertValue[1] = oracledb.STRING;
}
if(element === "BINARY_DOUBLE" || element.indexOf("FLOAT") > -1 || element === "NUMBER") {
insertValue[0] = (nullBind===true) ? null : 1;
insertValue[1] = oracledb.NUMBER;
}
if(element === "TIMESTAMP" || element === "DATE") {
insertValue[0] = (nullBind===true) ? null : new Date(0);
insertValue[1] = oracledb.DATE;
}
if(element === "BLOB" || element.indexOf("RAW") > -1 ) {
insertValue[0] = (nullBind===true) ? null : assist.createBuffer(100);
insertValue[1] = oracledb.BUFFER;
}
return insertValue;
};
function(err, result) {
should.not.exist(err);
(result.metaData).should.deepEqual( [ { name: 'DT', fetchType: oracledb.DATE, dbType: oracledb.DB_TYPE_DATE, dbTypeName: "DATE", nullable: true } ] );
done();
}
);
var getInsertVal = function(element, nullBind) {
var insertValue = [];
if(element.indexOf("CHAR") > -1 || element === "CLOB") {
insertValue[0] = (nullBind===true) ? null : "abcsca";
insertValue[1] = oracledb.STRING;
}
if(element === "BINARY_DOUBLE" || element.indexOf("FLOAT") > -1 || element === "NUMBER") {
insertValue[0] = (nullBind===true) ? null : 1;
insertValue[1] = oracledb.NUMBER;
}
if(element === "TIMESTAMP" || element === "DATE") {
insertValue[0] = (nullBind===true) ? null : new Date(0);
insertValue[1] = oracledb.DATE;
}
if(element === "BLOB" || element.indexOf("RAW") > -1 ) {
insertValue[0] = (nullBind===true) ? null : assist.createBuffer(100);
insertValue[1] = oracledb.BUFFER;
}
return insertValue;
};