Monday 12 June 2017

NodeJS mysql update not applied in db, no error shown

I'm currently writting some queries in my app.js, until now, everything was working as expected, but this morning I've attempted to do muliples updates query looping through an array.

When I'm running my app.js there is no error shown, but the table in my db is still the same, no value has been modified...

Here is the code :

var array = [ [
{ col1: 450 },
{ col2: 800 },
{ col3: 1100 },
{ id_row: 3888 } ] ];

async.each(array, function(row, callback)
{

    var sql = "UPDATE my_table SET col1 = ?, col2 = ?, col3 = ? WHERE id_row = ?";

    console.log("before update");
    console.log(row);

    connection.query(sql, row, function (err, results)
    {
        if (err) throw err;

        console.log("done !");
        console.log(row);

        callback();
    });

}, function(err, results)
{
    console.log("fini ?");
});

note :

  • in this short sample, the array has only one row, but could have a lot more rows
  • the initials values of this row that I want to update are for example ( col1: 200, col2: 300, col3 : 600, id_row: 3888 )
  • the 2 console.logs (before and after the query) show the updated value of the array, but the db is not modified.... really I don't understand...

What am I doing wrong ?



via gZ Fab

No comments:

Post a Comment