在我的节点模块中,我需要更新多个行(数字不固定),以便完成我创建的循环,该循环将值分配给一个数组并生成下一个" UPDATE SET。 ..;"串。所以最后它看起来像这样:
UPDATE rules_cancellation SET period = ?, amount = ?, type = ? WHERE ID
= ?; UPDATE rules_cancellation SET period = ?, amount = ?, type = ? WHERE ID = ?;
并且数组:
[ 111, 111, '%', 27, 222, 222, '£', 28 ]
但是我收到了这个错误:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check
the manual that corresponds to your MariaDB server version for the
right syntax to use near '111, '%', 27, 222, 222, '£', 28, amount = ?,
type = ? WHERE ID = ?; UPDATE rule' at line 1
我的代码:
var queryUpdate = '';
var dataUpdate = [];
for(var i in cancellation.rule)
{
queryUpdate += "UPDATE rules_cancellation SET period = ?, amount = ?, type = ? WHERE ID = ?; ";
dataUpdate.push(cancellation.rule[i].daysBefore);
dataUpdate.push(cancellation.rule[i].fee);
dataUpdate.push(cancellation.rule[i].type);
dataUpdate.push(cancellation.rule[i].id);
}
connection.query(queryUpdate, dataUpdate, function(err,results){
if(err){return console.log(err)}
console.log('ok!')
});
这是我的节点语法或查询中的错误吗?我该如何解决这个问题?提前感谢您的帮助!