A customer app built in Uniface 10 lets users link customers: a branch belongs to a company, a subsidiary to a group. The table is simple:
CUSTOMER_RELATION ( CHILD_ID , PARENT_ID , RELATION_TYPE , . . . )
Enter fullscreen mode
Exit fullscreen mode
Nothing stops a user from saying "A belongs to B" and later "B belongs to A". Every report that walks up or down the hierarchy then has a problem. This article shows two queries from a check module: one finds such loops, the other adds up revenue per group.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, November 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).
Walking up the tree
WITH RECURSIVE builds a result step by step. The first SELECT is the start, the second is joined to the rows found so far until it returns nothing:
WITH RECURSIVE walk ( START_ID , CUR_ID , DEPTH , PATH ) AS ( SELECT CHILD_ID , PARENT_ID , 1 , CHILD_ID || ' > ' || PARENT_ID FROM CUSTOMER_RELATION UNION ALL SELECT w . START_ID , r .…