Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var prepareTableWithClob = function(sequence, callback) {
var sql = "INSERT INTO nodb_tab_clob1 (id, content) " +
"VALUES (:i, EMPTY_CLOB()) RETURNING content " +
"INTO :lobbv";
var bindVar = { i: sequence, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } };
connection.execute(
sql,
bindVar,
{ 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);
var inStream = fs.createReadStream(inFileName);
var lob = result.outBinds.lobbv[0];
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event");
});
var prepareTableWithClob = function(sql, id, callback) {
var bindVar = { i: id, lobbv: { type: oracledb.CLOB, dir: oracledb.BIND_OUT } };
connection.execute(
sql,
bindVar,
{ 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);
var inStream = fs.createReadStream(preparedInFileName);
var lob = result.outBinds.lobbv[0];
lob.on('error', function(err) {
should.not.exist(err, "lob.on 'error' event");
});
async function run() {
let connection;
try {
connection = await oracledb.getConnection(dbConfig);
await demoSetup.setupLobs(connection); // create the demo table
// Create an empty Temporary Lob
const tempLob = await connection.createLob(oracledb.CLOB);
// Helper function for loading data to the Temporary Lob
const doStream = new Promise((resolve, reject) => {
let errorHandled = false;
tempLob.on('close', () => {
// console.log("templob.on 'close' event");
});
tempLob.on('error', (err) => {
// console.log("templob.on 'error' event");
if (!errorHandled) {
errorHandled = true;
reject(err);
}
const doStreamHelper = new Promise((resolve, reject) => {
if (lob.type === oracledb.CLOB) {
console.log('Writing a CLOB to ' + outFileName);
lob.setEncoding('utf8'); // set the encoding so we get a 'string' not a 'buffer'
} else {
console.log('Writing a BLOB to ' + outFileName);
}
let errorHandled = false;
lob.on('error', (err) => {
// console.log("lob.on 'error' event");
if (!errorHandled) {
errorHandled = true;
lob.close(() => {
reject(err);
});
}
var dostream = function(lob, cb) {
if (lob.type === oracledb.CLOB) {
console.log('Writing a CLOB to ' + outFileName);
lob.setEncoding('utf8'); // set the encoding so we get a 'string' not a 'buffer'
} else {
console.log('Writing a BLOB to ' + outFileName);
}
var errorHandled = false;
lob.on(
'error',
function(err) {
console.log("lob.on 'error' event");
if (!errorHandled) {
errorHandled = true;
lob.close(function() {
return cb(err);
it('54.1 can access properties of closed LOB without error', function(done) {
conn.createLob(
oracledb.CLOB,
function(err, lob) {
should.not.exist(err);
(lob.chunkSize).should.be.a.Number();
(lob.pieceSize).should.be.a.Number();
should.strictEqual(lob.length, 0);
should.strictEqual(lob.type, oracledb.CLOB);
lob.close(function(err) {
should.not.exist(err);
(lob.chunkSize).should.be.a.Number();
(lob.pieceSize).should.be.a.Number();
should.strictEqual(lob.length, 0);
should.strictEqual(lob.type, oracledb.CLOB);
var updateReturning_stream = function(callback) {
var sql_update = "UPDATE " + tableName + " set num = num+10 RETURNING num, clob into :num, :lobou";
connection.execute(
sql_update,
{
num: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
lobou: { type: oracledb.CLOB, dir: oracledb.BIND_OUT }
},
function(err, result) {
should.not.exist(err);
var numLobs = result.outBinds.lobou.length;
should.strictEqual(numLobs, 10);
async.times(
numLobs,
function(n, next) {
verifyLob( n, result, function(err, result) { next(err, result); } );
},
callback
);
}
);
};
connection.release(function(err) {
should.not.exist(err);
connection.createLob(oracledb.CLOB, function(err, lob) {
should.exist(err);
should.not.exist(lob);
should.strictEqual(
err.message,
"NJS-003: invalid connection"
);
done();
});
});
}
function(err, result) {
should.not.exist(err);
(result.metaData).should.deepEqual(
[ { name: 'NCLB',
fetchType: oracledb.CLOB,
dbType: oracledb.DB_TYPE_NCLOB,
dbTypeName: "NCLOB",
nullable: true } ]
);
done();
}
);