Reputation: 959
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
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; } }
Upvotes: 3
Views: 2948
Reputation: 91518
I think it's impossible without modifying the call_method_for_tableX
.
Suppose call_method_for_table1
succeeds, then the commit is done and you can't rollback after call_method_for_table2
eventually failed.
Upvotes: 1