-2
請指導我如何使用expressjs在sqlite3中執行事務管理。我以這種方式嘗試過,但沒有成功。使用expressjs在sqlite3中進行事務管理
app.get('/transaction', function(req, res){
db.serialize(function() {
try{
db.run("BEGIN");
db.run("UPDATE emp SET balance = 10000 WHERE eid = 1", function(err, row){
if (err){
throw (e);
}
});
db.run("UPDATE temp SET deptno = 2000 WHERE eid = 2", function(err, row){
//this temp table not exists it should be rollback and server should not
//stop
if (err){
throw (e);
}
});
db.run('commit');
res.end("Transaction succeed");
}//try
catch(e){
//console.log(e);
res.end("Transaction cancelled");
db.run('rollback');
//console.log(e);
}//catch
});
});
您可以添加什麼是你正面臨的錯誤? –
它顯示e沒有找到 –
我解決了另一種方式。感謝您的關注。 –