I have a scenario like below. Where the main method needs to call multiple methods , 1 method for 1 table , and each method runs a set of statements which has to be atomic. So they are enclosed within a begin_work,commit,rollback block.
Also call_method_for_table1,call_method_for_table2,call_method_for_table3 should all succeed or fail together which means they have to be atomic. That is why begin_work,commit,rollback block are added in main method also. But i can see that perl does not allow me . I get exception - "DBD::ODBC::db begin_work failed: Already in a transaction". Now i do not have any way of modifying the call_method_for_table* methods since it is in a library and modifying it is not possible due to many reasons.
Can i use checkpoints to solve this problem
- Will Savepoints help (http://msdn.microsoft.com/en-us/library/ms378414%28v=SQL.105%29.aspx)
- Will Rolling back till savepoint work even if there are some commits in between (which is usually the case in my example)
- Is it fine even when there are parallel runs of the same process ?
- Will it cause data inconsistency?
sub main { $dbh->begin_work; eval { call_method_for_table1(); call_method_for_table2(); call_method_for_table3(); $dbh->commit; 1; }; if ($@) { $dbh->rollback; } } sub call_method_for_table1 { $dbh->begin_work; eval { $dbh->do($INSERTSTATEMENT_TABLE1); $dbh->do($UPDATESTATEMENT_TABLE1); $dbh->do($DELETESTATEMENT_TABLE1); $dbh->commit; }; if ($@) { $dbh->rollback; } }