我目前正在使用mysql和Node.js,并带有 multipleStatements 我可以同时进行多个查询,但是如果查询失败,它不会 break ,我期望
app.post('/api3/stock5', function (req, res) {
var connection = mysql.createConnection({
host : conf.host,
user : conf.user,
password : conf.pass,
database : conf.database,
multipleStatements: true //<- essential for several queries at the same time
});
var sql ="UPDATE (...)"; INSERT INTO (...)";
var query = connection.query(sql);
query.on('error', function(err) {
console.log("error: /api3/stock5 /n");
console.log(sql);
});
query.on('result', function(result) {
});
query.on('end', function(result) {
});
res.send('OK');
});
有什么方法可以确保每个查询都正确执行并且仅在这种情况下才能提交?谢谢