From: Neil Lunn <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: RE: executing atomic transactions in DBI
Date sent: Tue, 8 May 2001 13:38:33 +1000
Neil,
meanwhile I have performed some experiments and found out that I
misunderstood the effects of switching RaiseError() on. I thought
this would just write database errors to $@ *without* making the eval
block die; now I know that the eval block will *really* die upon a
database error, and so a commit() on the last line of the eval block
will not be reached in this case. Thus, your argumentation below is
convincing, and I thank you *very* much for your post
Bodo
[EMAIL PROTECTED]
> > Sorry to interfere so late in this thread, but
> >
> > if the commit() is placed here, won't it be always executed, because
> > there are no die statements which stop code execution upon errors
> > before ? Shouldn't committing be made dependent of the value of $@
> > like
> >
> > if ($@) {
> > warn "Transaction aborted because $@";
> > $dbh->rollback; # undo the incomplete changes
> > # add other application on-error-clean-up code here
> > }
> > else {
> >
> > $dbh->commit();
> > }
>
> Actually there is a very good reason for the code being represented the way
> it is within the DBI docs as Peter posted earlier.
>
> The question you must ask of the code represented above is, "What happens if
> commit fails?".
>
> The purpose is to raise an error and thus cause eval to fail before the
> commit is reached (last statement), if so then the condition of failure for
> the eval is to issue a $dbh->rollback.
>
> I guess it's the difference between "Do all the work but if the work fails,
> go back to the start" and "Do all of the work, if the work fails go back to
> the start, but if the work was successful *really* do all the work."
>
> I'm out of breath just saying that let alone coding it.
>
> Neil
>