bazz
06-11-2009, 08:36 PM
Hi,
is this how transactions should be written in perl using DBI?
Consider the preprare statements to be prior to this.
Instead of :
$do_this->execute;
$do_that->execute($var,$another_var);
$insert_this->execute;
$update_this->execute;
should it be like this:
eval {
$do_this->execute;
$do_that->execute($var,$another_var);
$insert_this->execute;
$update_this->execute;
$dbh->commit; # commit the changes if we get this far
};
if ($@) {
warn "Transaction aborted because $@";
$dbh->rollback; # undo the incomplete changes
# add other application on-error-clean-up code here
}
That's how I get it from the docs but I am not sure I have understood it.
bazz
is this how transactions should be written in perl using DBI?
Consider the preprare statements to be prior to this.
Instead of :
$do_this->execute;
$do_that->execute($var,$another_var);
$insert_this->execute;
$update_this->execute;
should it be like this:
eval {
$do_this->execute;
$do_that->execute($var,$another_var);
$insert_this->execute;
$update_this->execute;
$dbh->commit; # commit the changes if we get this far
};
if ($@) {
warn "Transaction aborted because $@";
$dbh->rollback; # undo the incomplete changes
# add other application on-error-clean-up code here
}
That's how I get it from the docs but I am not sure I have understood it.
bazz