Closed Falym closed 5 years ago
I have to process separately my queries like this :
var produits_test = [{id:1,ref:'40'},{id:2,ref:'32'},{id:15,ref:'29'},{id:17,ref:'152'}];
for(var i=0;i<produits_test.length;i++){
var sql = "update t_produits_test set ref='"+produits_test[i].ref+"' where id_produit = "+produits_test[i].id;
connection
.execute(sql)
.then(function(){
})
.catch(error => {
displayWarning(error);
});
}
for(var i=0;i<produits_test.length;i++){
var sql = "insert into log(id, ref) values ("+produits_test[i].id+",'"+produits_test[i].ref+"')";
console.log(sql);//OK
connection
.execute(sql)
.then(function(){
})
.catch(error => {
displayWarning(error);
});
}
But if I want my 2nd query depends on value returned by the first query, this issue isn't the good solution.
Could you help me please ?
Best regards,
const produits = [
{ id: 1, ref: '40' },
{ id: 2, ref: '32' },
{ id: 15, ref: '29' },
{ id: 17, ref: '152' }
];
async function multiple() {
for (let i = 0, length = produits.length; i < length; i++) {
const { ref, id } = produits[i];
const sql = `update t_produits_test set ref="${ref}" where id_produit=${id}`;
await connection
.execute(sql)
.then(console.log)
.catch(error => displayWarning(error));
}
}
multiple();
Hello Nuintun,
How to do to execute multiple queries with nested query.
I've try this code :
I can't execute each item prefectely.
Could you have an idea ? By the way, is there a solution to execute my queries with synchronous mode ?
Thanks.