The way to get AffectedRows when non-Async is shown here: https://github.com/mysqljs/mysql/issues/363
My Code below - none of the console.logs after the update display in the console, certain columns are not being updated in the database, and no error or try catch is encountered. If there's an error, why don't I see it, otherwise, why don't I see the AffectedRows?
This is being called from another async function.
async function UpdatePassword(connection, rowID) {
... some code omitted here...
try
{
var [errQuery,results] = await
connection.query(sqlUpdate);
if (errQuery) throw errQuery;
console.log("Back from update");
console.log("AffectedRows=" + results.affectedRows);
} catch (err)
{
console.log("*** Catch Error:")
console.log(err.stack);
}
}
I think I have improved the code, but same issue. Non error, no console.log statements after the connection.query show up.
console.log("SQL Update=" + sqlUpdate);
try
{
var [rows, fields, errQuery] = await connection.query(sqlUpdate);
if (errQuery) throw errQuery;
console.log("Back from update");
console.log("AffectedRows=" + rows.affectedRows);
} catch (err2)
{
console.log("*** Catch Error:")
console.log(err2.stack);
}
console.log ("end function");
Got the answer here: https://github.com/sidorares/node-mysql2/issues/999.
The call from the first async routine to the second one needed an await.
for (let r=0; r < rows.length; ++r) {
await UpdatePassword(connection, rows[r].ID);
}
He recommended a for loop, instead of answer I got earlier here. If using .each or .map, you create another "inner" function, which is not async, and you can't call use the "await" keyword in that kind of logic.