Subject Re: [firebird-support] Are before triggers absolutely reliable? What happens if they fail?
Author Helen Borrie
At 09:57 PM 29/10/2007, you wrote:
>I have a before insert trigger which includes NEW.DOC_CREATED_DATE =
>CURRENT_TIMESTAMP;
>
>99% of the time this works, but 1% of the time there is a null value.
>
>I assume that there can be only 2 causes. Either 1. the trigger is
>failing or 2. the column is being overwritten somehow after the insert.

or 3. (most likely) your trigger code logic is branching under the 1/100 condition and bypassing this statement. Review any conditional blocks in your code, including exception handlers.


>In order to discount #1, would it be true to say that if a trigger
>and/or generator fails for some reason that there would be an error
>message and the insert would not occur?

Correct that, if an unhandled exception occurs, execution stops and control is returned to the client. Generators don't fail.


>Can transaction control be used to enforce this at the trigger level

Not transaction control per se. In PSQL you use WHEN handler blocks to set up the equivalent of savepoints.

>or do transactions only exist in the context of an external application?

Yes. Client applications start transactions and finish transactions. (Internally, the engine can act as a kind of client and start/complete things like the SS garbage collector and sweep in transactions under its control.) PSQL doesn't have the capability to start, commit or rollback transactions.

./heLen