node-firebird
node-firebird copied to clipboard
Field string return type buffer!
const datos = () => { return new Promise((resolve, reject) => { Firebird.attach(options, function (err, db) { if (err) { throw err;
}
db.query('SELECT * FROM TIPOCPR', function (err, result) {
if (err) console.log(err)
if (result) {
resolve(result)
db.detach();
}
})
})
})
}
datos() .then( result => console.log(result) )
Results:
{ ID: 28, TIPOCOMPTORABANTE: <Buffer 4e 4f 54 41 20 43 52 45 44 49 54 4f 20 44 45 56 20 4d 45 52>, ACTIVO: 1, TALONARIOID: 0, ADMSTOCK: 1, ACCIONSTOCK: 2, ACCIONCAJA: 0, DESISTEMA: 0, ACCIONCTACTE: 0, COPIAS: 1, REPORTE: null, CODIGO: <Buffer 4e 43 44>, ENTIDAD: <Buffer 43 4c 49> }
All field with string format are in type Buffer, Why is that?
Maybe it's is because charset encoding.. maybe this resolve you problem:
for (const row of result) {
for (const key in row)
if (Buffer.isBuffer(row[key]))
row[key] = row[key].toString('binary')
}
@mbotherside this worked for me. Thanks
Eu estava apanhando disso hoje, resolvi desta forma, sei que faz meses mas espero que se alguém procurar essa forma que fiz ajude
let valor
function setData(data){
valor = data
}
function getData(){
return valor
}
module.exports = function (sql = 'SELECT * FROM CLIENTES'){
firebird.attach(options, function(err, db) {
if (err){
throw err;
}
db.query(sql, function(err, result) {
let resultado = []
for (const row of result) {
for (const key in row){
if (Buffer.isBuffer(row[key]))
row[key] = row[key].toString('binary')
resultado.push(row)
}
}
setData(result)
// IMPORTANT: close the connection
db.detach();
});
});
return getData()
}
Hi @marcelogracia try to update the library please, this should be solved.