LoginSignup
0
1

More than 5 years have passed since last update.

node-jt400を試してみた(Transactions)

Posted at

Transactions

テストを実施する前に物理ファイルにジャーナル処理を開始します。

STRJRNPF FILE(MYLIB/MEMBER MYLIB/MEMBER2) JRN(MYLIB/JRN) IMAGES(*BOTH)
SQLtransactions.js
//コミットされる例
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, "徳川","家綱",'4代目', 4]).then(function () {
            return tran.update("insert into member2 (ID,LNAME,FNAME,PROF,TENSU) VALUES(?,?,?,?,?)", 
            [Id, "徳川","家綱",'4代目', 4]); 
        });
    });
    res.send('end');
});

//ロールバックされる例。member2.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, "徳川","綱吉",'5代目', 5]).then(function () {
            return tran.update("insert into member2 (ID,LNAME,FNAME,PROF,TENSU) VALUES(?,?,?,?,?)", 
            [Id, "徳川","綱吉",'5代目', 'a']); 
        });
    });
    res.send('end');
});

/tranCommitを実行すると、それぞれの物理ファイルに正しくレコードが追加されます。
/tranRollbackを実行すると、member2 のインサート文でエラーが発生し、memberにレコードは追加されませんでした。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1