Note: RaiseError is set to false.
$dbh->begin_work;
$dbh->do("..."); # sql1, ok
$dbh->do("..."); # sql2, fails (e.g. syntax error)
$dbh->do("..."); # sql3, ok
$dbh->commit;
This will result in the effects of sql1 and sql3 to be committed, which is not desirable, since in this case I want the SQL statements to succeed/fail together. Currently my workaround is this:
eval {
local $dbh->{RaiseError} = 1;
$dbh->begin_work;
$dbh->do("..."); # sql1, ok
$dbh->do("..."); # sql2, fails (e.g. syntax error)
$dbh->do("..."); # sql3, ok
$dbh->commit;
};
$dbh->rollback if $@; # needed, RaiseError does not automatically rollback
but I don't quite like it. Is there another easier alternative? I prefer Postgres' behavior:
$dbh->begin_work;
$dbh->do("..."); # sql1, ok
$dbh->do("..."); # sql2, fails (e.g. syntax error)
$dbh->do("..."); # sql3, ok but fail because transaction status is now aborted
$dbh->commit; # becomes rollback
RaiseErrorusesdie(), can you re-define die() to give it acccess to$dbhand have it auto-rollback the tx and invalidate$dbh?DBD::SQLitesources or an underdocumented feature in SQLite's C API for the purpose. IfDBD::SQLiteis well written it shouldn't be too hard to add, as there should only be a few call sites for actual execution of queries that you'd need to wrap in a transaction-health test.