Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function streamIntoClob(id, cb) {
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);
inStream.pipe(lob);
lob.on('close', function() {
connection.commit( function(err) {
should.not.exist(err);
cb(); // insertion done
});
});
inStream.on('error', function(err) {
should.not.exist(err);
console.log(result.outBinds.outbv);
console.log('\nBinding the record values directly:');
binds = {
inbv: { type: RecTypeClass, val: { NAME: 'Plane', POS: 34 } },
outbv: { type: RecTypeClass, dir: oracledb.BIND_OUT }
};
result = await connection.execute(plsql, binds);
console.log(result.outBinds.outbv);
// Using the name for the type
binds = {
inbv: { type: "RECTEST.RECTYPE", val: { NAME: 'Car', POS: 56 } },
outbv: { type: RecTypeClass, dir: oracledb.BIND_OUT }
};
result = await connection.execute(plsql, binds);
console.log(result.outBinds.outbv);
//
// executeMany()
//
console.log('\nExample with executeMany():');
binds = [
{ inbv: { NAME: 'Train', POS: 78 } },
{ inbv: { NAME: 'Bike', POS: 83 } }
];
async function run() {
let connection;
try {
const connection = await oracledb.getConnection(dbConfig);
await demoSetup.setupLobs(connection); // create the demo table
const result = await connection.execute(
`INSERT INTO no_lobs (id, c) VALUES (:id, EMPTY_CLOB()) RETURNING c INTO :lobbv`,
{
id: 4,
lobbv: {type: oracledb.CLOB, dir: oracledb.BIND_OUT}
},
{ autoCommit: false } // a transaction needs to span the INSERT and pipe()
);
if (result.rowsAffected != 1 || result.outBinds.lobbv.length != 1) {
throw new Error('Error getting a LOB locator');
}
const lob = result.outBinds.lobbv[0];
if (lob === null) {
throw new Error('NULL lob found');
}
const doStream = new Promise((resolve, reject) => {
let errorHandled = false;
it('68.2 inserts multiple CLOBs', function(done) {
var sql = "insert into nodb_multi_clob values(1, " +
" EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB(), EMPTY_CLOB() ) " +
" returning c1, c2, c3, c4, c5 into :lobbv1, :lobbv2, :lobbv3, :lobbv4, :lobbv5";
var bindvars = {
lobbv1: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
lobbv2: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
lobbv3: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
lobbv4: { type: oracledb.CLOB, dir: oracledb.BIND_OUT },
lobbv5: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }
};
var inFileName = './test/clobexample.txt';
lobInsert(sql, bindvars, inFileName, done);
});
function(callback) {
connection.execute(
exec_ref,
[
{ type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
],
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
fetchArraySize: fetchArraySizeVal
},
function(err, result) {
should.not.exist(err);
var rowCount = 0;
fetchRowsFromRS(result.outBinds[0], numRowsVal, rowCount, callback);
}
);
},
function(callback) {
function(cb) {
var bind_in_var = {
i: { val: insertID, dir: oracledb.BIND_IN, type: oracledb.NUMBER },
c: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: maxsize }
};
connection.execute(
proc_bindin_exec,
bind_in_var,
function(err, result) {
should.not.exist(err);
var expected = insertContent;
if(insertContent == "" || insertContent == undefined) {
expected = null;
}
should.strictEqual(result.outBinds.c, expected);
cb();
}
);
}
], callback);
function(cb) {
var bindVar =[ { type: oracledb.NUMBER, dir: oracledb.BIND_OUT, maxSize: 1000 }, sequence, { type: bindType, dir: oracledb.BIND_OUT, maxSize: 1000 } ];
inBind(table_name, proc_name, sequence, dbColType, bindVar, bindType, nullBind, cb);
}
], callback);
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);
var lob = result.outBinds.lobbv[0];
lob.on('error', function(err) {
should.not.exist(err);
return callback(err);
});
var inStream = new stream.Readable();
inStream._read = function noop() {};
inStream.push(rawData);
inStream.push(null);
inStream.on('error', function(err) {