Recursive queries


Recursive queries retrieve information from forms that store hierarchical (parent-child) data. For example, A Bill of Materials form might contain information about the relationship between assemblies, their subassemblies, and the subassemblies' subassemblies.

The ARMultiSchemaFuncQueryFromList structure of the ARGetListEntryWithMultiSchemaFields function represents a list of items that are included in the FROM clause of the query generated by the function. The items can include multiple forms (schemas) and one recursive query.

The ARMultiSchemaRecursiveFuncQueryStruct structure represents the recursive query. The query can retrieve hierarchical data from only one form. To retrieve hierarchical data, specify that form in the structure's queryFromList parameter, and then give it an alias (recursiveSchemaAlias). To specify the hierarchical node or nodes to begin the recursion, use start with a qualifier (*startQual). To apply conditions from other forms during the recursion, you must add those forms to the recursion qualifier (*recursionQual).


Example 1

To retrieve a list of all employees who work for Jane Smith in the Seattle office:

  1. Set up the appropriate recursive query on the Employee form, which contains hierarchical information about relationships between employees and managers.
  2. In the levelsToRetrieve element, specify 0 to search all levels in the hierarchy.
  3. In the recursion qualifier, the value in the City field on the Location form for each employee must be Seattle.

The recursive query finds 35 employees who work for Jane: Two reporting directly and 33 reporting either to her direct reports or to subordinates of her direct reports. Only 12 of those employees, however, work in the Seattle office, so the query returns only 12 records.

Example 2
The following C and Java examples show how to use a recursive query to find all employees who either report directly to Bob Jones or who report to his direct reports:

The query retrieves the root or parent level (startQual) and two levels below the root.

Important

For recursive queries, set the sortList parameter to NULL.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*