Subject Re: Exception question
Author johnsparrowuk
Hi Dan,

I don't follow you - the code I quoted was FB sproc code (sorry, I
didn't say explicitly) so I can't have a transaction rollback in the
exception handler! You can't begin, commit or rollback transactions
in stored procedures or triggers (unless things have changed *very*
radically while I've been away!).

They rely on exception handling and undoing to maintain atomicity.
Transactions are started and ended by client (code) request.

Anyway, I've been playing since I wrote that message, and answered
my own question, it would undo the insert in:

> > begin
> > insert into mytable values ('a');
> > execute procedure xx; /* xx throws exception, insert is undone
*/
> > when any do
> > begin
> > ...
> > end
> > end!!

If I didn't want the insert to be undone, I should do something like:

> > begin
> > insert into mytable values ('a'); /* not undone */
> > BEGIN
> > insert into mytable values ('b'); /* is undone */
> > execute procedure xx; /* xx throws exception */
> > when any do
> > begin
> > ...
> > end
> > END
> > end!!

Basically, if you catch an exception, it will undo upto and
including the begin...end block in which you catch it. Everything
else is left as-is.

'Rollback' without rollback, cool eh?? ;)

Thanks,

John

--- In firebird-support@yahoogroups.com, "Dan Wilson" <dwilson@d...>
wrote:
>
>
> if the actions in your exception code include a transaction
rollback, then everything in the transaction context will be undone,
including the insert. Note that actions outside of transaction
scope, such as generator increments, will not be undone. It all
depends on what you decide to do in your exception code.


> > If I have code something like:
>
> > begin
> > insert into mytable values ('a');
> > execute procedure xx; /* xx might throw exception */
> > when any do
> > begin
> > ...
> > end
> > end!!
>
> > and sproc 'xx' does throw an exception, will it automatically
undo
> > actions performed in 'xx' even though the exception is being
handled
> > one block up?
>
> > Would it undo the 'insert...'?