xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

DbRelation()

Returns the linking expression of a specified relation.

Syntax

DbRelation( <nRelation> ) --> cLinkExpression

Arguments

<nRelation>
The parameter is a numeric value indicating the ordinal position in the list of relations to retrieve the relation expression from. Relations are numbered in the sequence they are defined, beginning with 1.

Return

The function returns a character string containing the relation expression specified with <nRelation>, or a null string ("") when no relation exists for <nRelation>.

Description

The DbRelation() function can be used to query the relation expression for a given relation. In conjunction with DbRSelect(), all data required to save and restore relation data using the macro operator (&) can be obtained. Note, however, that this works only if a relation does not refer to lexical variables (GLOBAL, LOCAL, STATIC).

DbRelation() retrieves the expression of the TO clause of the SET RELATION command, while DbRSelect() retrieves the data of the INTO clause. Refer to the SET RELATION command for more information on relations.

By default, DbRelation() operates in the current work area. Use an aliased expression to query relation expressions of different work areas.

Info

See also:DbFilter(), DbRSelect(), DbSetRelation(), OrdSetRelation(), SET RELATION
Category: Database functions
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example opens three databases and defines two relations.
// The result of various DbRelation() calls is shown.

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

      USE Parts ALIAS Part NEW EXCLUSIVE
      INDEX ON PartNo TO PartNo

      USE Order ALIAS Ord NEW

      SET RELATION TO CustNo INTO Cust, ;
                   TO PartNo INTO Part

      ? Alias()                      // result: ORD
      ? DbRelation(1)                // result: CustNo
      ? DbRelation(2)                // result: PartNo

      SELECT Part
      ? Alias()                      // result: PART
      ? DbRelation(1)                // result: null string ("")

      ? Ord->( DbRelation(1) )       // result: CustNo
      ? Ord->( DbRelation(2) )       // result: PartNo

      CLOSE ALL
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe