我有一个阵列
[['Tom', 1], ['Jerry', 2], ['Jessica', 3]]
我发现以下语法插入一堆行:
insert into tbl (col2,col1) values ?
所以,我尝试使用语法进行更新
update tbl set col1=?, col3=NOW() where col1=?
但它失败了:
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
可以更新sql使用这种语法进行批处理操作吗?
附:以下节点代码仅供参考
let mysql = require('mysql');
let db = require('../configs/db');
let pool = mysql.createPool(db);
connPool (sql, val, cb) { //function name
pool.getConnection((err, conn) => {
if(err){
console.log('Connection Error:' + err);
}else{
console.log('allConnections:' + pool._allConnections.length);
let q = conn.query(sql, val, (err, rows,fields) => {
if (err) {
console.log('Query:' + sql + ' error:' + err);
}
cb(err, rows, fields);
conn.release();
});
}
});
},
...
let func = require('../sql/func');
let arr = [['Tom', 1], ['Jerry', 2], ['Jessica', 3]];
sql = 'update tbl set col1=?, col3=NOW() where col1=?';
func.connPool(sql, arr , (err,rows,fields) => {
if(err==null){
res.json({code: 200, msg: 'success'});
} else {
res.json({code: 400, msg: 'failed'+err});
}
});