Subject Re: Replace the statement REPLACE
Author Adam
--- In Firebird-Architect@yahoogroups.com, "Ann W. Harrison"
<aharrison@...> wrote:
>
> Adam wrote:
> >
> > Perhaps both 'insert or update' and 'update or insert' could be both
> > implemented, and the one you choose would determine which triggers are
> > fired first.
> >
>
> for what little it's worth, Firebird triggers fire on row update, not
> on verb, so an insert that fails because of a duplicate key value
> doesn't file the insert trigger, nor does an update that finds no
> rows. The question of "which triggers are fired first" doesn't come
> up.

The before insert trigger(s) would fire regardless, otherwise the
autoinc simulation

CREATE TRIGGER A_BI FOR A
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
BEGIN
NEW.ID = GEN_ID(GEN_AID, 1);
END
END
^

would fail to work.

Running an update which affects 0 rows would not fire any update trigger.

So if it tried insert then update:

Before insert trigger -> attempt insert -> fails -> before update
trigger -> update -> after update trigger.

Or if it tried update and insert:

The update wouldn't affect any row, so no update triggers are fired,
therefore the insert is attempted.

So depending on the methodology chosen, the before insert triggers may
be fired.

Adam