node-firebird icon indicating copy to clipboard operation
node-firebird copied to clipboard

Field string return type buffer!

Open marcelogracia opened this issue 3 years ago • 3 comments

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?

marcelogracia avatar Jan 14 '22 16:01 marcelogracia

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')
          }

adminOtherside avatar Feb 08 '22 10:02 adminOtherside

@mbotherside this worked for me. Thanks

dtremp007 avatar May 04 '22 19:05 dtremp007

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()
}

AlbertoAlfredo avatar Jul 06 '22 19:07 AlbertoAlfredo

Hi @marcelogracia try to update the library please, this should be solved.

jesusvilla avatar Nov 08 '22 01:11 jesusvilla