0
I’m having a problem with a loop loop on node js
, this is the query
exports.getValueMsg = function() {
return new Promise((resolve, reject) => {
pconn
.pool
.query("SELECT b.numero_serie, b.grupo_msg, b.index_msg, b.valor_msg FROM bor_msg b where b.id_tipo = '16'",
(err, rows) => {
if (!err) {
while (i<rows.rows.length) {
dadosMsg = rows.rows[i];
i++
return resolve(dadosMsg);
}
} else {
reject(err);
console.log(err);
}
});
});
}
it returns me 5 results that comes from this select above, when I call her in this script
const exec = async() => {
try {
var count = Object.keys(await dbMsg.getValueMsg()).length;
for(i; i<count; i++) {
valueMsg = await dbMsg.getValueMsg();
console.log(valueMsg);
configXml = await fc.dadosXml();
macro = await xmlTemplates.xml_16_begin(valueMsg, configXml);
clientOut.write(macro);
await fc.wait(2200);
clientOut.write(xmlTemplates.xml_16_end(valueMsg, configXml));
await fc.wait(3000);
dbMsg.upStatusMsg(statusMsg, valueMsg);
setTimeout(function() {
if(vDataOutObj.Package.Header._attributes.Id == 116) {
console.log(vDataOutObj.Package.Header._attributes.Id);
dbMsg.upStatusMsg(statusMsg2, valueMsg);
}
}, 3100);
}
} catch (error) {
console.log(error);
}
}
Instead of going through the results and bringing each one...it brings me repeated results and does not bring back all the results it has on query
...
Obs(in my database table not to repeated records) someone can tell me what this could be and how to solve this my question ?
It was basically that, I made some adjustments and now it’s working the right way... Thank you very much Dude
– Zé Reis M. Olliver