2

I'm trying data extraction in Node.js with Firebird.

First code:

var sql1 = 'select id,id_asset_element,duration,start_datetime,show_name from MAIN_EVENT where start_datetime > DATEDIFF(millisecond, TIMESTAMP\'0001-01-01 00:00\', CURRENT_TIMESTAMP) and id_playlist=1 order by 1 asc;'

app.get('/', function(req, res) {
firebird.attach(options, function(err, db) {

    if (err)
        throw err;  

    // db = DATABASE
    db.query(sql1, function(err, result) {
        // IMPORTANT: close the connection
        console.log(result())
        db.detach();
        res.render('pages/index', {
            result : result
          });

        if(err)
            console.log(err)
        });


    });
   })

And first log:

  {
    ID: 744636,
    ID_ASSET_ELEMENT: 86869,
    DURATION: 27000,
    START_DATETIME: 63760068424160,
    SHOW_NAME: 'CHID, CLIP'
  },
  {
    ID: 744637,
    ID_ASSET_ELEMENT: 81723,
    DURATION: 96120,
    START_DATETIME: 63760068451160,
    SHOW_NAME: 'CHID, CLIP'
  },

This result is good.

Second Code:

var sql2 = 'select IMPORT_FIELDS from MAIN_EVENT where start_datetime > DATEDIFF(millisecond, TIMESTAMP\'0001-01-01 00:00\', CURRENT_TIMESTAMP) and id_playlist=1 order by 1 asc;'

    app.get('/test/', function(req, res) {



        firebird.attach(options, function(err, db) {
    
            if (err)
                throw err;
        
            // db = DATABASE
            db.query(sql2, function(err, result) {
                // IMPORTANT: close the connection
                console.log(result)
                db.detach();    
                res.render('pages/test', {
                    result : result
                  });
    
                if(err)
                    console.log(err)
                });
    
    
            });
            
    })
    

And second log:

  { IMPORT_FIELDS: [Function (anonymous)] },
  { IMPORT_FIELDS: [Function (anonymous)] },
  { IMPORT_FIELDS: [Function (anonymous)] },
  { IMPORT_FIELDS: [Function (anonymous)] },

If I open, localhost:3000/test result is this:

function(callback) { // callback(err, buffer, name); statement.connection.startTransaction(ISOLATION_READ_UNCOMMITTED, function(err, transaction) { if (err) { callback(err); return; } statement.connection._pending.push('openBlob'); statement.connection.openBlob(id, transaction, function(err, blob) { var e = new Events.EventEmitter(); e.pipe = function(stream) { e.on('data', function(chunk) { stream.write(chunk); }); e.on('end', function() { stream.end(); }); }; if (err) { callback(err, name, e); return; } function read() { statement.connection.getSegment(blob, function(err, ret) { if (err) { transaction.rollback(function() { e.emit('error', err); }); return; } if (ret.buffer) { var blr = new BlrReader(ret.buffer); var data = blr.readSegment(); e.emit('data', data); } if (ret.handle !== 2) { read(); return; } statement.connection.closeBlob(blob); transaction.commit(function(err) { if (err) { e.emit('error', err); } else { e.emit('end'); } e = null; }); }); } callback(err, name, e); read(); }); }); } function(callback) { // callback(err, buffer, name); statement.connection.startTransaction(ISOLATION_READ_UNCOMMITTED, function(err, transaction) { if (err) { callback(err); return; } statement.connection._pending.push('openBlob'); statement.connection.openBlob(id, transaction, function(err, blob) { var e = new Events.EventEmitter(); e.pipe = function(stream) { e.on('data', function(chunk) { stream.write(chunk); }); e.on('end', function() { stream.end(); }); }; if (err) { callback(err, name, e); return; } function read() { statement.connection.getSegment(blob, function(err, ret) { if (err) { transaction.rollback(function() { e.emit('error', err); }); return; } if (ret.buffer) { var blr = new BlrReader(ret.buffer); var data = blr.readSegment(); e.emit('data', data); } if (ret.handle !== 2) { read(); return; } statement.connection.closeBlob(blob); transaction.commit(function(err) { if (err) { e.emit('error', err); } else { e.emit('end'); } e = null; }); }); } callback(err, name, e); read(); }); }); } function(callback) { // callback(err, buffer, name);
      

Problem

How can I extract [Function (anonymous)] from second log.

I'm using, Node.js, Express, Ejs and Firebird.

Update :

npmjs.com/package/node-firebird

Mert
  • 39
  • 4
  • It looks like IMPORT_FIELDS is a BLOB field. Check driver documentation how to work with them. – user13964273 Jun 23 '21 at 11:30
  • @user13964273 yep its blob field. But I didn't find how to work this. I'm trying Reading Blobs (Aasynchronous) with firebird. But I didn't succeed. Thank you for suggesting the right way. I need to work on this a little more until the answers come. – Mert Jun 23 '21 at 11:43
  • Exactly which Firebird Node.js driver are you using? There is more than one. – Mark Rotteveel Jun 23 '21 at 12:32
  • @MarkRotteveel i'm using this https://www.npmjs.com/package/node-firebird – Mert Jun 23 '21 at 12:41
  • Does the documentation for reading blobs help: https://www.npmjs.com/package/node-firebird#reading-blobs-aasynchronous – Mark Rotteveel Jun 23 '21 at 13:06

1 Answers1

1

I found how to display blob data. This code is working for me.

select cast(BLOBDATANAME as varchar(1000) character set utf8)

Firebird-Nodejs

firebird.attach(options, function(err, db) {
    if (err)
        throw err;

    // db = DATABASE
    db.query(sql2, function(err, result) {
        // IMPORTANT: close the connection
        console.log(result)
        db.detach();    

        if(err)
            console.log(err)
    });
});

Result:

{ CAST: '<XML></XML>' }, { CAST: '<XML></XML>' }, { CAST: '<XML></XML>' },
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mert
  • 39
  • 4
  • it would only work if the data fits into `varchar(1000)`, otherwise you would have find ways to download BLOBs content with BLOB-oriented functions – Arioch 'The Jun 24 '21 at 09:14
  • BLOB fields are used not because of blue sky. Even if it works for you casting BLOB to VARCHAR in query is a very bad idea. – user13964273 Jun 24 '21 at 11:22
  • I dıdnt use blob sky. But we bought package program and they used. But i need to new update for web view. I'm using node js for data extraction. And ıts worked for me. Maybe yep, it's bad choosie. Thanks for answer. Regards. – Mert Jun 24 '21 at 12:52
  • Dude, thanks a lot. I had a project stopped here for a few months because I couldn't get out of this problem!!! Thanks for sharing the solution! (Cara, muito obrigado. tava com um projeto parado aqui fazia alguns meses por não conseguir sair deste problema!!! Valeu por compartilhar a solução!) – Rodrigo Silveira Sep 11 '21 at 00:15