I have two SQLite3 tables, A and B. When column A.X is updated, I want to modify B.Y, and when B.Y is updated, I want to modify A.X.
I can use two triggers:
CREATE TRIGGER AtoB AFTER UPDATE OF X ON A BEGIN UPDATE B SET Y = ...
and
CREATE TRIGGER BtoA AFTER UPDATE OF Y ON B BEGIN UPDATE A SET X = ...
but it seems that both triggers are called once, no matter which table I modify, i.e. one always invokes the other.
I only want one of them to execute, since the updates are lossy in the direction of A to B. I don't want the loss in the reverse direction B to A, but if both triggers fire, then it makes it lossy in both directions.
A simple solution would be to implement three UDFs "increment_trigger_depth", "decrement_trigger_depth", and "get_trigger_depth", and then use "WHEN trigger_depth == 1" in the update statements. But, is there an easier way to determine trigger depth in SQLite3?