Function DbRelation() Foundation

Returns the linking expression of a relation.

Syntax
DbRelation( <nRelation> | <cRelName> ) --> cLinkExpression
Parameters
<nRelation>
<nRelation> is a positive integer indicating the ordinal position of the relation in a work area. The link expression for this relation is returned. The relations are numbered in the order like they were defined using DbSetRelation() or SET RELATION TO.
<cRelName>
Instead of the numeric ordinal, a string containing the name of the desired relation can be specified as first parameter.
Return

The return value of DbRelation() is a character string containing the linking expression for the relation specified. If no relation exists, or if a non-existent relation is referred to, a null string ("") is returned.

Description

The function DbRelation() determines the expression used when a parent work area navigates the record pointer of a child work area. The expression returned is the one specified to the command SET RELATION TO or the function DbSetRelation() defining the link between the two work areas. It usually corresponds to the index expression of the controlling index in a child work area.

If the function is used without the alias operator, it returns the linking expressions through which the current work area navigates its child work area.

The function DbRelation() is generally used with DbRSelect(). DbRSelect() returns the Select() number (ordinal number) of the child work area for a specified relation.

Examples
DbRelation()
// In the example, a link is created between an invoice file, 
// an item file, and a customer file. The return values of 
// DbRelation() are displayed. 

PROCEDURE Main 
   USE Customer ALIAS Cust NEW EXCLUSIVE 
   INDEX ON CustNo TO CustNo 
   SET INDEX TO CustNo 

   USE Item ALIAS Item NEW EXCLUSIVE 
   INDEX ON ItemNo TO ItemNo 
   SET INDEX TO ItemNo 

   USE Invoice ALIAS Inv NEW 

   SET RELATION TO CustNo  INTO Cust , ; 
                TO ItemNo  INTO Item 

   ? Alias()                      // result: Inv 
   ? DbRelation(1)                // result: CustNo 
   ? DbRelation(2)                // result: ItemNo 

   SELECT Cust 
   ? Alias()                      // result: CUST 
   ? DbRelation(1)                // result:     (null string ("") 

   ? Inv->( DbRelation(1) )       // result: CustNo 
   ? Inv->( DbRelation(2) )       // result: ItemNo 

   CLOSE DATABASES 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.