The portable way to do transactions with DBI is by using begin_work, and commit/rollback.
Usually you'd wrap the transaction in an eval to catch errors, so the following would be the more common idiom (copied from the Transactions section in the DBI docs):
$dbh->begin_work; eval { local $dbh->{RaiseError} = 1; foo(...) # do lots of work here bar(...) # including inserts baz(...) # and updates $dbh->commit; # commit the changes if we get this far }; if ($@) { warn "Transaction aborted because $@"; # now rollback to undo the incomplete changes # but do it in an eval{} as it may also fail eval { $dbh->rollback }; # add other application on-error-clean-up code here }
Update: Added RaiseError code per runrig's comment.
In reply to Re: seeking barebones sqlite example with transaction
by rhesa
in thread seeking barebones sqlite example with transaction
by dimar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |