Click or drag to resize

DbRelation Function

X#
Return the linking expression of a specified relation.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION DbRelation(
	nRelation
) AS STRING CLIPPER
Request Example View Source

Parameters

nRelation (Optional)
Type: Usual
The position of the desired relation in the list of current work area relations.
The relations are numbered according to the order in which they were defined by relation setting.

Return Value

Type: String
The linking expression defined to nRelation.
If there is no relation set for nRelation, DBRelation() returns a NULL_STRING.
Remarks
DBRelation() is a database function to determine the linking expression and work area of an existing relation. DBRelation() returns the linking expression defined by the TO clause. DBRSelect() returns the work area linked as defined by the INTO clause. By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying it within an aliased expression
Tip Tip
Declared variables: A string returned by DBRelation() cannot operate correctly when recompiled and executed using the macro operator (&) if the original expression contained references to local or static variables, or otherwise depends on compile-time declarations.
Examples
This example opens three database files, sets two child relations from the parent work area, and then displays the linking expression to the second child work area:
X#
1USE invoices INDEX invoices NEW
2USE backorder INDEX backorder NEW
3USE customer INDEX customer NEW
4SET RELATION TO custnum INTO invoices, OrderNum ;
5        INTO backorder
6QOut(DBRelation(2))                // Result: Ordernum
Later you can query the same linking expression from an unselected work area by using an aliased expression like this:
X#
1USE archive NEW
2QOut(Customer->DBRelation(2))
3// Result: OrderNum
This example is a function, Relation(), that returns the results of both DBRelation() and DBRSelect() as an array:
X#
1FUNCTION Relation(nRelation)
2    RETURN {;
3                DBRelation(nRelation), ;
4                Alias(DBRSelect(nRelation)) ;
5            }
See Also