Domanda

In table 1 I have trigger 1 that inserts in table 3 with trigger 3 that uses results of trigger 2 in table 2. Is there is a way in Firebird 2.5 to lunch trigger 1 in table 1 only after trigger 2 in table 2? Maybe some "wait for trigger"?

È stato utile?

Soluzione

No, in Firebird 2.5 you can't specify the trigger to only run after some other trigger.

The execution order of triggers is determined by the order of statements that trigger them, ie if you use

INSERT INTO table2 ...
INSERT INTO table1 ...

then the (ON INSERT) triggers of the table2 is executed before table1 ones. If table has more than one trigger of given type then the order is determined by the POSITION clause of the trigger's declaration.

If you can't guarantee the order of INSERT statements then perhaps you can use database trigger as a workaround - create an ON TRANSACTION COMMIT trigger where you check for a flag you did set in the trigger2. If the flag is there then execute the stuff which requires the data generated in the trigger2. For setting up the flag you can use the RDB$SET_CONTEXT with the USER_TRANSACTION namespace. Something like

CREATE TRIGGER trigger2 ACTIVE AFTER INSERT ON table2
AS
BEGIN
  RDB$SET_CONTEXT ('USER_TRANSACTION', 'doTrigger1', 1);
END

CREATE TRIGGER trigger1 ACTIVE ON TRANSACTION COMMIT
AS
BEGIN
  IF(RDB$GET_CONTEXT ('USER_TRANSACTION', 'doTrigger1') = 1)THEN BEGIN
     -- proccess data
  END
END

See the Firebirds language reference for the complete TRIGGER DDL syntax.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top