Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('70.8.3 val: null', function(done) {
var emptybuf;
if ( nodever6 )
emptybuf = new Buffer.alloc ( 0 ) ;
else
emptybuf = new Buffer ( 0 );
var bindVar = {
p_inout : {
dir: oracledb.BIND_INOUT,
type: oracledb.BUFFER,
val: emptybuf,
maxSize: 32767
}
};
connection.execute(
sqlrun,
bindVar,
function(err, result) {
should.not.exist(err);
// console.log(result);
should.strictEqual(result.outBinds.p_inout, null);
done();
}
);
}); // 70.8.3
it('86.2.4 Buffer supported in fetchAsString', function(done) {
should.doesNotThrow(
function() {
oracledb.fetchAsString = [ oracledb.BUFFER ];
}
);
should.strictEqual(oracledb.fetchAsString.length, 1);
should.strictEqual(oracledb.fetchAsString[0], oracledb.BUFFER);
done();
}); // 86.2.4
it('82.1.15 bind value and type mismatch', function(done) {
var id = insertID++;
var content = 100;
connection.execute(
"INSERT INTO nodb_dml_blob_1 VALUES (:ID, :C)",
{
ID : { val : id },
C : { val : content, dir : oracledb.BIND_IN, type : oracledb.BUFFER }
},
function(err) {
should.exist(err);
// NJS-011: encountered bind value and type mismatch in parameter 2
(err.message).should.startWith('NJS-011:');
done();
}
);
}); // 82.1.15
it('77.2.6 works with null and bind in maxSize set to (64K - 1)', function(done) {
var sequence = insertID++;
var bindVar = {
i: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
b: { val: null, type: oracledb.BUFFER, dir: oracledb.BIND_IN, maxSize: 65535 }
};
var option = { autoCommit: true };
async.series([
function(cb) {
plsqlBindIn(sqlRun, bindVar, option, cb);
},
function(cb) {
var sql = "select blob_1 from nodb_tab_blob_in where id = " + sequence;
verifyBlobValueWithBuffer(sql, null, null, cb);
}
], done);
}); // 77.2.6
console.log('Inserting Data');
const data = { "userId": 2, "userName": "Bob", "location": "USA" };
const s = JSON.stringify(data);
const b = Buffer.from(s, 'utf8');
await connection.execute(
`INSERT INTO no_purchaseorder_b (po_document) VALUES (:lobbv)`,
{ lobbv: b }
);
console.log('Selecting JSON stored in a BLOB column:');
result = await connection.execute(
`SELECT po_document
FROM no_purchaseorder_b
WHERE JSON_EXISTS (po_document, '$.location')`,
[],
{ fetchInfo: { "PO_DOCUMENT": { type: oracledb.BUFFER } } } // Fetch as a Buffer instead of a Stream
);
if (result.rows.length === 0)
throw new Error('No results');
console.log(result.rows[0][0].toString('utf8'));
console.log('Selecting a JSON value using "dotted" notation:');
if (connection.oracleServerVersion < 1202000000) {
throw new Error('This example only works with Oracle Database 12.2 or greater');
}
result = await connection.execute(
`SELECT pob.po_document.location
FROM no_purchaseorder_b pob`
);
if (result.rows.length === 0)
throw new Error('No results');
console.log(result.rows[0][0]);
it('96.1.13 oracledb.BUFFER <--> DB: NUMBER', function(done) {
index++;
var table_name = tableNamePre + index;
var proc_name = procPre + index;
var content = assist.createBuffer(100);
var bindType = oracledb.BUFFER;
var dbColType = "NUMBER";
var nullBind = false;
doTest(table_name, proc_name, bindType, dbColType, content, index, nullBind, done);
});
it("188.2 Fetch RAW as string by defining fetchAsString", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='string'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawContentString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
function(cb) {
connection.execute(
sqlRun,
{
i1: { val: sequence, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
i2: { val: null, type: oracledb.NUMBER, dir: oracledb.BIND_IN },
c: { val: content, type: oracledb.BUFFER, dir: oracledb.BIND_IN },
output: { type: oracledb.BUFFER, dir: oracledb.BIND_OUT, maxSize: len }
},
function(err, result) {
should.not.exist(err);
var resultVal = result.outBinds.output;
var compareBuffer = assist.compare2Buffers(resultVal, content);
should.strictEqual(compareBuffer, true);
cb();
}
);
}
], done);
if(content == "EMPTY_BLOB") {
connection.execute(
"INSERT INTO nodb_blob1 VALUES (:ID, EMPTY_BLOB())",
[ id ],
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 1);
callback();
}
);
} else {
connection.execute(
"INSERT INTO nodb_blob1 VALUES (:ID, :B)",
{
ID : { val : id },
B : { val : content, dir : oracledb.BIND_IN, type : oracledb.BUFFER }
},
function(err, result) {
should.not.exist(err);
should.strictEqual(result.rowsAffected, 1);
callback();
}
);
}
};
function() {
oracledb.fetchAsString = [ oracledb.BUFFER ];
}
);