Subject | Recursive Trigger |
---|---|
Author | s_m_t80 |
Post date | 2006-12-01T08:45:12Z |
on Firebird 1.5 and 2.0 I have this problem,
Table A and table B in relation, on table A there's a field WUPDATE, on
A and B a trigger
onAfterUpdate setting A.WUPDATE=1, that trigger on A handles only the
exception
of setting WUPDATE=0 and is coded as follow:
IF NOT (OLD.WUPDATE = 1 AND NEW.WUPDATE = 0) THEN BEGIN
UPDATE A SET WUPDATE=1 WHERE ID=OLD.ID;
END
logging new and old values I see what follows:
before update B
before update A old:0 new:1
after update A old:0 new:1
before update A old:1 new:0
after update A old:1 new:0
result: WUPDATE = 0
I don't understand why the last call is made with new value=0,
and I'm sure to miss something.
I wonder why the database behaves in such a way and if I can use
triggers to
accomplish my task in a better way.
Table A and table B in relation, on table A there's a field WUPDATE, on
A and B a trigger
onAfterUpdate setting A.WUPDATE=1, that trigger on A handles only the
exception
of setting WUPDATE=0 and is coded as follow:
IF NOT (OLD.WUPDATE = 1 AND NEW.WUPDATE = 0) THEN BEGIN
UPDATE A SET WUPDATE=1 WHERE ID=OLD.ID;
END
logging new and old values I see what follows:
before update B
before update A old:0 new:1
after update A old:0 new:1
before update A old:1 new:0
after update A old:1 new:0
result: WUPDATE = 0
I don't understand why the last call is made with new value=0,
and I'm sure to miss something.
I wonder why the database behaves in such a way and if I can use
triggers to
accomplish my task in a better way.