How to use the oracledb.BLOB function in oracledb

To help you get started, we’ve selected a few oracledb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oracle / node-oracledb / test / blobDMLBindAsBuffer.js View on Github external
it('82.1.19 Negative: RETURNING INTO with autocommit on', function(done) {
      var id = insertID++;
      var sql = "INSERT INTO nodb_dml_blob_1 (id, blob) VALUES (:i, EMPTY_BLOB()) RETURNING blob INTO :lobbv";
      var inFileName = './test/tree.jpg';

      connection.execute(
        sql,
        {
          i: id,
          lobbv: { type: oracledb.BLOB, dir: oracledb.BIND_OUT }
        },
        { autoCommit: true },
        function(err, result) {
          should.not.exist(err);
          var inStream = fs.createReadStream(inFileName);
          var lob = result.outBinds.lobbv[0];

          lob.on('error', function(err) {
            should.exist(err);
            // ORA-22990: LOB locators cannot span transactions
            // ORA-22920: row containing the LOB value is not locked
            var isExpectedError;
            if ( (err.message).startsWith('ORA-22990') || (err.message).startsWith('ORA-22920') ) {
              isExpectedError = true;
            } else {
              isExpectedError = false;
github oracle / node-oracledb / test / lobResultSet.js View on Github external
function streamIntoBlob(id, cb) {
      connection.execute(
        "INSERT INTO " + tableName + " VALUES (:n, EMPTY_BLOB()) RETURNING content INTO :lobbv",
        { n: id, lobbv: { type: oracledb.BLOB, dir: oracledb.BIND_OUT } },
        function(err, result) {
          should.not.exist(err);
          var lob = result.outBinds.lobbv[0];
          var inStream = fs.createReadStream(jpgFileName);

          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);
github oracle / node-oracledb / test / fetchBlobAsBuffer3.js View on Github external
beforeEach('set oracledb.fetchAsBuffer', function(done) {
      oracledb.fetchAsBuffer = [ oracledb.BLOB ];
      done();
    }); // beforeEach
github oracle / node-oracledb / examples / blobinsert1.js View on Github external
function(err, connection)
  {
    if (err) { console.error(err.message); return; }

    connection.execute(
      "INSERT INTO mylobs (id, b) VALUES (:id, EMPTY_BLOB()) RETURNING b INTO :lobbv",
      { id: 2, lobbv: {type: oracledb.BLOB, dir: oracledb.BIND_OUT} },
      { autoCommit: false },  // a transaction needs to span the INSERT and pipe()
      function(err, result)
      {
        if (err) { console.error(err.message); return; }
        if (result.rowsAffected != 1 || result.outBinds.lobbv.length != 1) {
          console.error('Error getting a LOB locator');
          return;
        }

        var lob = result.outBinds.lobbv[0];
        lob.on(
          'error',
          function(err)
          {
            console.log("lob.on 'error' event");
            console.error(err);
github knex / knex / lib / dialects / oracledb / index.js View on Github external
const lobProcessing = function(stream) {
  const oracledb = require('oracledb');

  /**
   * @type 'string' | 'buffer'
   */
  let type;

  if (stream.type) {
    // v1.2-v4
    if (stream.type === oracledb.BLOB) {
      type = 'buffer';
    } else if (stream.type === oracledb.CLOB) {
      type = 'string';
    }
  } else if (stream.iLob) {
    // v1
    if (stream.iLob.type === oracledb.CLOB) {
      type = 'string';
    } else if (stream.iLob.type === oracledb.BLOB) {
      type = 'buffer';
    }
  } else {
    throw new Error('Unrecognized oracledb lob stream type');
  }
  if (type === 'string') {
    stream.setEncoding('utf-8');
github oracle / node-oracledb / test / constants.js View on Github external
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);

  });
github oracle / node-oracledb / test / blobDMLReturningMultipleRowsAsStream.js View on Github external
var updateReturning_stream = function(callback) {
    var sql_update = "UPDATE " + tableName + " set num = num+10 RETURNING num, blob into :num, :lobou";
    connection.execute(
      sql_update,
      {
        num: { type: oracledb.NUMBER, dir: oracledb.BIND_OUT },
        lobou: { type: oracledb.BLOB, 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
        );
      }
    );
  };
github oracle / node-oracledb / test / lobBind2.js View on Github external
lob.on('finish', function() {

            connection.execute(
              "begin nodb_proc_blob_inout1(:id, :oid, :io); end;",
              {
                id: seq,
                oid: outLobId,
                io: { type: oracledb.BLOB, dir: oracledb.BIND_INOUT, val: lob }
              },
              { autoCommit: true },
              function(err, result) {
                should.not.exist(err);
                var lobout = result.outBinds.io;

                lobout.on('close', function(err) {
                  should.not.exist(err);

                  return callback();
                });

                lobout.on('error', function(err) {
                  should.not.exist(err, "lob.on 'error' event.");
                });
github oracle / node-oracledb / test / lobBind1.js View on Github external
function(err, result) {
              should.not.exist(err);
              (result.rows.length).should.not.eql(0);

              var lob = result.rows[0][0];

              connection.execute(
                sql2,
                [
                  seq,
                  { val: lob, type: oracledb.BLOB, dir: oracledb.BIND_IN }
                ],
                { autoCommit: true },
                function(err) {
                  should.not.exist(err);
                  lob.close(cb);
                }
              );
            }
          );
github oracle / node-oracledb / test / blobStream.js View on Github external
function(cb) {
        var bindVar = { i: insertID, c: { val: lob, type: oracledb.BLOB, dir: oracledb.BIND_IN } };
        connection.execute(
          insetSql,
          bindVar,
          { autoCommit: true },
          function(err) {
            should.not.exist(err);
            lob.close(cb);
          }
        );
      },
      function(cb) {