xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SET ORDER

Selects the controlling index.

Syntax

SET ORDER TO <nIndexPos>
SET ORDER TO TAG <cIndexName> [IN <cIndexFile]

Arguments

TO <nIndexPos>
This is a numeric value specifying the ordinal position of the index to select as controlling index. Indexes are numbered in the sequence they are opened, beginning with 1.

When no argument is passed or when the order is 0, all indexes remain open, but database navigation follows the physical order of records. That is, there is no controlling index.

TO TAG <cIndexName>
This is the symbolic name of the index to select as the controlling index. It can be specified as a literal name or a character expression enclosed in parentheses. The TAG option is usually supported by RDDs capable of maintaining multiple-index files, such as DBFCDX.
IN <cIndexFile>
<cIndexFile> is the name of the file containing the index to select. If not specified, all index files open in the current work area are searched for the index with the name <cIndexTag>. The file name can be specified as a literal name or a character expression enclosed in parentheses. When the file extension is omitted, it is determined by the database driver that opened the file.

Description

The SET ORDER TO command selects the controlling index from a list of indexes open in the current work area. Indexes are opened with the SET INDEX command or the INDEX option of the USE command. The latter, however, is not recommended in a network environment.

The controlling index can either be specified by its ordinal position <nIndexPos>, or by its symbolic name <cIndexName>. The former is determined by the order in which indexes are opened (beginning with 1), while the latter is specified with the TAG option of the INDEX command when the index is created.

A controlling index affects the logical order of records in a work area. Relative database navigation with SKIP, GO TOP and GO BOTTOM follows this order, rather than the physical order how records are stored in a database.

The controlling index can be disabled temporarily by setting the index order to 0. This leaves all indexes open but database navigation follows the physical order.

Info

See also:DbSetOrder(), INDEX, IndexKey(), IndexOrd(), OrdNumber(), OrdSetFocus(), SEEK, SET INDEX, USE
Category: Database commands , Index commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example creates three index files holding one index each.

   PROCEDURE Main
      USE Customer
      INDEX ON Upper(FirstName)           TAG FName TO Cust01
      INDEX ON Upper(LastName+Firstname)  TAG LName TO Cust02
      INDEX ON Upper(City)                TAG City  TO Cust03

      SET INDEX TO Cust01, Cust02, Cust03
      ? OrdNumber(),OrdKey()     // result: 1 Upper(FirstName)

      SET ORDER TO TAG LName
      ? OrdNumber(),OrdKey()     // result: 2 Upper(LastName+FirstName)

      SET ORDER TO 3
      ? OrdNumber(),OrdKey()     // result: 3 Upper(City)

      SET ORDER TO 0             ** No controlling index
      ? OrdNumber(),OrdKey()     // result: 0 ""
                                 ** indexes are still open
      ? OrdKey(1)                // result: Upper(FirstName)
      ? OrdKey(2)                // result: Upper(LastName+FirstName)
      ? OrdKey(3)                // result: Upper(City)
      CLOSE Customer
   RETURN

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