我正在尝试使用Firebird在Node.js中提取数据。
第一个代码:
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)
});
});
})
第一个日志:
{
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'
},
这个结果是好的。
第二个代码:
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)
});
});
})
第二个日志:
{ IMPORT_FIELDS: [Function (anonymous)] },
{ IMPORT_FIELDS: [Function (anonymous)] },
{ IMPORT_FIELDS: [Function (anonymous)] },
{ IMPORT_FIELDS: [Function (anonymous)] },
如果我打开,localhost:3000/测试结果是:
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);
问题
如何从第二个日志中提取[函数(匿名(]。
我正在使用,Node.js、Express、Ejs和Firebird。
更新:
npmjs.com/package/node-firebird
我发现了如何显示blob数据。这个代码对我有效。
select cast(BLOBDATANAME as varchar(1000) character set utf8)
火鸟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)
});
});
结果:
{ CAST: '<XML></XML>' }, { CAST: '<XML></XML>' }, { CAST: '<XML></XML>' },