Trying to rollback a transaction and it is not working

Article ID: 1124
Last updated: 05 Feb, 2008
Article ID: 1124
Last updated: 05 Feb, 2008
Revision: 1
Views: 4029
Posted: 05 Aug, 1997
by Dean J.
Updated: 05 Feb, 2008
by Dean J.
Problem


No matter what I do, rollbackTransaction() never rolls back my transaction.


Cause


Typically with DBTools.h++, you start a transaction by setting autoCommit(FALSE) on a connection. Anything to be included on that transaction should be done on the same connection. Otherwise, it gets commited automatically. So, if you were to write code like this :

 

 RWDBConnection conn = db.connection();

// DBTools 3.10 and below
// conn.autoCommit(FALSE);
//DBTools 3.21 and above
conn.beginTransaction();
RWDBTable table = db.table(Junk);
RWDBinserter ins = table.inserter();
ins<<10;
ins.execute();
conn.rollbackTransaction(); // <- This doesn't rollback the insert.



Action


What you need to do is execute() on the same connection on which you have started the transaction.

So, replace

    ins.execute();
with
    ins.execute(conn);
and it should work just fine. Consult both your User's Guide and Class Reference for more detailed information on this topic.


This article was:   Helpful | Not helpful
Report an issue
Article ID: 1124
Last updated: 05 Feb, 2008
Revision: 1
Views: 4029
Posted: 05 Aug, 1997 by Dean J.
Updated: 05 Feb, 2008 by Dean J.

Others in this category