Transactions Start journaling the physical file before running the test.
STRJRNPF FILE(MYLIB/MEMBER MYLIB/MEMBER2) JRN(MYLIB/JRN) IMAGES(*BOTH)
SQLtransactions.js
//Example of being committed
app.get("/tranCommit", function (req, res, next) {
pool.transaction(function (tran) {
var Id = 110;
return tran.update("insert into member (ID,LNAME,FNAME,PROF,TOKUTEN) VALUES(?,?,?,?,?)",
[Id, "Tokugawa","Ietsuna",'4th generation', 4]).then(function () {
return tran.update("insert into member2 (ID,LNAME,FNAME,PROF,TENSU) VALUES(?,?,?,?,?)",
[Id, "Tokugawa","Ietsuna",'4th generation', 4]);
});
});
res.send('end');
});
//An example of being rolled back. member2.Set characters in TENSU
app.get("/tranRollback", function (req, res, next) {
pool.transaction(function (tran) {
var Id = 111;
return tran.update("insert into member (ID,LNAME,FNAME,PROF,TOKUTEN) VALUES(?,?,?,?,?)",
[Id, "Tokugawa","Tsunayoshi",'5th generation', 5]).then(function () {
return tran.update("insert into member2 (ID,LNAME,FNAME,PROF,TENSU) VALUES(?,?,?,?,?)",
[Id, "Tokugawa","Tsunayoshi",'5th generation', 'a']);
});
});
res.send('end');
});
Running / tranCommit will correctly add records to each physical file. When I ran / tranRollback, an error occurred in the insert statement for member2 and no records were added to member.
Recommended Posts