xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SORT

Creates a new, physically sorted database.

Syntax

    SORT TO <cDatabase> ;
         ON <fieldName1> [/[A | D][C]] ;
         [, <fieldNameN> [/[A | D][C]]] ;
           [<Scope>] ;
     [WHILE <lWhileCondition>] ;
       [FOR <lForCondition>] ;
  [CODEPAGE <cCodePage>] ;
[CONNECTION <nConnection>] ]

Arguments

TO <cDatabase>
This is the name of the database file to create. It can include path and file extension. When no path is given, the file is created in the current directory. The default file extension is DBF. <cDatabase> can be specified as a literal file name or as a character expression enclosed in parentheses.
ON <fieldName>
The field names to use from the current work area for the sort operation must be specified as literal names, or as character expressions enclosed in parentheses.
/A | /D
These flags define the sorting order for a field. /D means Descending. /A stands for Ascaneding and is the default.
/C
This flag is only meaningful for fields of data type Character. If the flag is used, sorting of character values is case-insensitive.
<Scope>
This option defines the number of records to sort. It defaults to ALL. The NEXT <nCount> scope sorts the next <nCount> records, while the REST scope sorts records beginning with the current record down to the end of file.
WHILE <lWhileCondition>
This is a logical expression indicating to continue sorting while the condition is true. The SORT command stops processing as soon as <lWhileCondition> yields .F. (false).
FOR <lForCondition>
This is a logical expression which is evaluated for all records in the current work area. Those records where <lForCondition> yields .T. (true) are added to the target database.
CODEPAGE <cCodePage>
This is a character string specifying the code page to use for character strings stored in the new database. It defaults to the return value of HB_SetCodePage().
CONNECTION <nConnection>
This option specifies a numeric server connection handle. It is returned by a server connection function which establishes a connection to a database server, such as SR_AddConnection() of the xHarbour Builder SQLRDD. When CONNECTION is used, the SORT TO command creates a database on the server.

Description

The SORT command creates a new database file and adds to it records from the current work area in sorted order. Fields of data type Character are sorted according to their ASCII values, unless the /C flag is used. In this case, the sorting of character values is case-insensitive. Numeric fields are sorted by value, Date fields in chronological order and Logical fields with .T. (true) being the high value. Memo fields cannot be sorted.

The default sorting order is ascending (/A flag). It can be changed to descending using the /D flag.

The SORT command requires a file lock in the current work area (see function FLock()). Alternatively, the database must be used in EXCLUSIVE mode.

Records marked for deletion are not included in the target database when SET DELETED is set to ON.

Info

See also:ASort(), FLock(), INDEX, OrdCreate(), USE
Category: Database commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example creates a physically sorted database.

   PROCEDURE Main
      USE Customer

      SORT TO Cust01 ON Lastname, Firstname

      USE Cust01

      Browse()

      CLOSE Cust01
   RETURN

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