I'm trying to update a closure table using data macros, which requires running the following code whenever a new record is inserted into the main table:
INSERT INTO tblClosure (parent_id, child_id, depth)
SELECT p.parent_id, c.child_id, p.depth+c.depth+1
FROM tblClosure AS p, tblClosure AS c
WHERE p.child_id=$PARENT_ID and c.parent_id=$CHILD_ID;
As you can see, it would be possible to perform this operation using a nested loop:
Iterate through tblClosure
For each record p with child_id = $PARENT_ID {
Iterate through tblClosure
For each record c with parent_id = $CHILD_ID {
Insert (p.parent_id, c.child_id, p.depth + c.depth + 1) into tblClosure
}
}
Both the main table (tblNodes) and the closure table (tblClosure) are stored in the backend database, so it seems a data macro should be able to do what I want.
Data macros also seem to have functions Create Record (in...) and For Each Record (in...). But I can't get that second one to fire at all.
This is my code (I have defined temp_node
and temp_parent
as parameters):