On 5 May 2001, at 18:28, Sterin, Ilya wrote:
> There is no || die anywhere in that eval? Even with RaiseError => 1
> turned on, in many cases the transaction does not fail, if not
> checking for some sort of return. You are right, that eval does exit
> on error, I think I replied a little to quick and didn't exress it
> right. In most cases you would want to somehow check for the
> statement return. Also I've had cases and still do, on SunOS where
> with error checking turned on it still does not fail the script, not
> sure if that is driver specific rather than DBI, but with the same
> version of DBD::Oracle on one machine it failed and on the other it
> did not. I believe there were also a few threads that mentioned the
> same problem (or maybe it is not a problem, but rather expected
> behavior in some cases and environments). I always use || die() or
> specifically check for return value when using eval with DBI.
Ummm ... maybe difference in environment requires different
methods ? I got my code from below or from the book and I tested
it with PostgreSQL ... it worked ... successful changes in the eval
were rolled back when one update/insert failed in the same eval.
I didn't mention the need to have RaiseError on in my example
(crucial oversight).
I'd like to see the code that implements multi inserts/updates
different than below.
http://theoryx5.uwinnipeg.ca/CPAN/data/DBI/DBI.html
> The recommended way to implement robust transactions in Perl
> applications is to use RaiseError and eval { ... } (which is very
> fast, unlike eval "..."). For example:
>
> $dbh->{AutoCommit} = 0; # enable transactions, if possible
> $dbh->{RaiseError} = 1;
> eval {
> 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 $@";
> $dbh->rollback; # undo the incomplete changes
> # add other application on-error-clean-up code here
> }
Peter
---------------------------
"Reality is that which, when you stop believing in it, doesn't go
away".
-- Philip K. Dick