xHarbour Reference Documentation > Function Reference |
Creates a new index.
OrdCreate( <cIndexFile> , ; [<cIndexName>], ; <cIndexExpr> , ; <bIndexExpr> , ; [<lUnique>] ) --> NIL
The function returns NIL.
The index function OrdCreate() creates an index for the database open in the current work area. Use an aliased expression to create an index in a different work area.
Indexes are created by the RDD used to open the database, according to the conditions specified with function OrdCondSet(). If the RDD does not support multiple indexes per index file (DBFNTX, for example) an existing index file <cIndexFile> is overwritten. If multiple indexes are supported by an RDD (DBFCDX, for example) and <cIndexFile> is open, a new index <cIndexName> is added to the file. If <cIndexName> exists already in the list of open indexes, it is replaced with a new index having the expression <cIndexExpr>.
During index creation, the code block <bIndexExpr> is evaluated for each record of the work area and its return value is added to the index. When index creation is complete, the new index becomes the controlling index. As a result, records are viewed in logical index order and no longer in physical order.
See also: | DbCreateIndex(), DbOrderInfo(), INDEX, OrdCondSet(), OrdListAdd(), OrdListClear(), Set() |
Category: | Database functions , Index functions |
Source: | rdd\dbcmd.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example creates two indexes in one index file. REQUEST Dbfcdx PROCEDURE Main USE Customer ALIAS Cust NEW VIA "DBFCDX" OrdCreate( "Customer", "ID" , "CUSTNO" ) OrdCreate( "Customer", "NAME", "Upper(LastName+FirstName)" ) OrdListClear() OrdListAdd( "Customer" ) ? OrdNumber() // result: 1 ? OrdName() // result: ID ? OrdKey() // result: CUSTNO ? OrdSetfocus( "NAME" ) // result: ID ? OrdNumber() // result: 2 ? OrdName() // result: NAME ? OrdKey() // result: Upper(LastName+FirstName) CLOSE Cust RETURN
http://www.xHarbour.com