Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('3.11.1 REF CURSOR', function(done) {
connection.should.be.ok();
var numRows = 100; // number of rows to return from each call to getRows()
connection.execute(
"BEGIN get_emp_rs11(:sal, :cursor); END;",
{
sal: 12000,
cursor: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
result.outBinds.cursor.metaData[0].name.should.eql('NAME');
result.outBinds.cursor.metaData[1].name.should.eql('SALARY');
result.outBinds.cursor.metaData[2].name.should.eql('HIRE_DATE');
fetchRowsFromRS(result.outBinds.cursor);
}
);
function fetchRowsFromRS(resultSet) {
resultSet.getRows(
numRows,
function(err, rows) {
should.not.exist(err);
if(rows.length > 0) {
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"
);
}
cb();
}
);
FROM no_banana_farmer
WHERE id < p_id;
END;`
);
//
// Get a REF CURSOR result set
//
const result = await connection.execute(
`BEGIN
no_get_rs(:id, :cursor);
END;`,
{
id: 3,
cursor: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
});
console.log("Cursor metadata:");
console.log(result.outBinds.cursor.metaData);
//
// Fetch rows from the REF CURSOR.
//
//
// If getRows(numRows) returns:
// Zero rows => there were no rows, or are no more rows to return
// Fewer than numRows rows => this was the last set of rows to get
// Exactly numRows rows => there may be more rows to fetch
const resultSet = result.outBinds.cursor;
let rows;
it('55.4.2 REF Cursor gets closed automatically', function(done) {
testConn.should.be.ok();
testConn.execute(
"BEGIN nodb_rs2_get_emp(:in, :out); END;",
{
in: 200,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, done);
}
);
});
});
it('18.2 Node-oracledb Type Constants', () => {
should.strictEqual(2019, oracledb.BLOB);
should.strictEqual(2006, oracledb.BUFFER);
should.strictEqual(2017, oracledb.CLOB);
should.strictEqual(2021, oracledb.CURSOR);
should.strictEqual(2014, oracledb.DATE);
should.strictEqual(0, oracledb.DEFAULT);
should.strictEqual(2010, oracledb.NUMBER);
should.strictEqual(2001, oracledb.STRING);
});
function(cb) {
connection.execute(
"BEGIN get_emd_rc(:out); END;",
{
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ extendedMetaData: true },
function(err, result) {
should.not.exist(err);
verifyResult(true, result.outBinds.out.metaData);
result.outBinds.out.close(cb);
}
);
},
function(cb) {
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], callback);
}
);
},
function dropProcedure(callback) {
function(callback) {
connection.execute(
"BEGIN get_emp_rs1_proc(:in, :out); END;",
{
in: queryAmount,
out: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ maxRows: 10 },
function(err, result) {
should.not.exist(err);
fetchRowFromRS(result.outBinds.out, callback);
}
);
},
function(callback) {
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.execute(
`BEGIN
OPEN :cursor FOR SELECT department_id, department_name FROM departments;
END;`,
{
cursor: { type: oracledb.CURSOR, dir : oracledb.BIND_OUT }
},
function(err, result) {
var cursor;
var queryStream;
if (err) {
console.error(err.message);
doRelease(connection);
return;
}
cursor = result.outBinds.cursor;
queryStream = cursor.toQueryStream();
queryStream.on('data', function (row) {
console.log(row);
function Orawrap() {
//Query result outFormat option constants
this.ARRAY = oracledb.ARRAY;
this.OBJECT = oracledb.OBJECT;
//Constants for bind parameter type properties
this.STRING = oracledb.STRING;
this.NUMBER = oracledb.NUMBER;
this.DATE = oracledb.DATE;
this.BLOB = oracledb.BLOB;
this.BUFFER = oracledb.BUFFER;
this.CLOB = oracledb.CLOB;
this.CURSOR = oracledb.CURSOR;
this.DEFAULT = oracledb.DEFAULT;
//Constants for bind parameter dir properties
this.BIND_IN = oracledb.BIND_IN;
this.BIND_OUT = oracledb.BIND_OUT;
this.BIND_INOUT = oracledb.BIND_INOUT;
this.poolManager = new PoolManager();
this.connectionManager = new ConnectionManager(this.poolManager);
}