I have a script as shown below. In cases where the main method requires calling several methods, 1 method for 1 table, and each method launches a set of operators that must be atomic. Thus, they are enclosed in a begin_work, commit, rollback block.
Also call_method_for_table1, call_method_for_table2, call_method_for_table3 should all succeed or crash together, which means that they must be atomic. That is why the begin_work, commit, rollback block is added in the main method. But I see that perl does not allow me. I get an exception - "DBD :: ODBC :: db begin_work failed: already in the transaction . Now I have no way to change the call_method_for_table * methods, since it is in the library and it cannot be changed for many reasons.
Can I use breakpoints 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;
}
}
source
share