Facing Issue with multiple insert statement and rollback them if having some error

37 views
Skip to first unread message

Atul Kumar

unread,
Jan 17, 2017, 2:47:48 AM1/17/17
to node-ibm_db
Hi,
I have a requirement to process a batch of Insert statements in dashdb and if some insert gives error and need to rollback all transaction otherwise commit. I tried ibm_db node modules but unable to resolve my problem. Could you please help me with some sample solution?

Some code snippet as below:
First I am beginning the transaction-
    conn.beginTransaction()
    var stmt = conn.prepareSync("insert into mytable values(?, ?)"); // mytable (c1 int, c2 varchar(20))
Now having a loop where I am creating params and binding them to above query statement.
    stmt.bind(params);

Now my requirement is if we have any issue with executing any of statement and I will rollback all statements otherwise will commit.
I tried multiple method -  stmt.executeSync() or conn.commitTransaction() or conn.rollbackTransaction().
If I put any wrong insert (ex stmt.bind(['a', 'amit'])), it should rollback all previous transaction. But it doesn't rollback.

Can we do this using ibm_db node module?

Thanks,
Atul

bimaljha

unread,
Jan 17, 2017, 4:15:05 AM1/17/17
to node-ibm_db
Check your answer here: https://github.com/ibmdb/node-ibm_db/issues/215 Thanks.
Reply all
Reply to author
Forward
0 new messages