admin管理员组文章数量:1355529
I am querying a mySQL database from the context of Node.js server code. Generally speaking, things are working fine. However, I can't figure out a way to tell whether an UPDATE statement does not update any rows. For instance, if I have code such as:
connection.query("UPDATE table SET columnA = valA WHERE columnB = valB;",
function(err, rows, fields) {
..some code..
}
As far as I can tell, none of the callbacks (err, rows, fields) will provide me with any information informing me that zero rows were affected. This is important information to me. How can I resolve this? Thanks!
I am querying a mySQL database from the context of Node.js server code. Generally speaking, things are working fine. However, I can't figure out a way to tell whether an UPDATE statement does not update any rows. For instance, if I have code such as:
connection.query("UPDATE table SET columnA = valA WHERE columnB = valB;",
function(err, rows, fields) {
..some code..
}
As far as I can tell, none of the callbacks (err, rows, fields) will provide me with any information informing me that zero rows were affected. This is important information to me. How can I resolve this? Thanks!
Share Improve this question edited Dec 11, 2015 at 15:54 Sterling Archer 22.4k19 gold badges85 silver badges121 bronze badges asked Dec 11, 2015 at 15:50 Tim ClotworthyTim Clotworthy 1892 silver badges6 bronze badges1 Answer
Reset to default 8I assume you're using node-mysql. The count of changed rows is in result.changedRows
variable.
Try:
connection.query('UPDATE table SET ...', function (err, result) {
if (err) throw err;
console.log('changed ' + result.changedRows + ' rows');
});
You can also get result.affectedRows
.
Further info is within the docs.
本文标签: javascriptUpdate in MySQL from NodejsHow to tell if zero rows are effectedStack Overflow
版权声明:本文标题:javascript - Update in MySQL from Node.js - How to tell if zero rows are effected? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744028558a2578485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论