Click or drag to resize

DbSortFox Function

X#
Copy records to a database file in sorted order.

Namespace:  XSharp.VFP
Assembly:  XSharp.VFP (in XSharp.VFP.dll) Version: 2.19
Syntax
 FUNCTION DbSortFox(
	cTargetFile,
	acFields,
	cbForCondition,
	cbWhileCondition,
	nNext,
	nRecord,
	lRest,
	lNoOpt,
	lDesc,
	acOutPutFields
) AS LOGIC CLIPPER
Request Example View Source

Parameters

cTargetFile (Optional)
Type: Usual
The name of the target database file to write the sorted records, including an optional drive, directory, and extension. See SetDefault() and SetPath() for file searching and creation rules.
The default extension for database files is determined by the RDD .
If cTargetFile does not exist, it is created.
If it exists, this function attempts to open the file in exclusive mode and, if successful, the file is overwritten without warning or error.
If access is denied because, for example, another process is using the file, NetErr() is set to TRUE.
acFields (Optional)
Type: Usual
The sort keys, specified as an array of field names. You may optionally add, after the field name, /A (to sort in dictionary order), /C (to ignore capitalization), or /D (to sort in descending order). The default setting is /A.
cbForCondition (Optional)
Type: Usual
A code block that defines a condition that each record within the scope must meet in order to be processed.
cbWhileCondition (Optional)
Type: Usual
A code block that defines another condition that each record must meet in order to be processed. As soon as a record is encountered that causes the condition to fail, the operation terminates.
If no scope is specified, cbWhileCondition changes the default scope to lRest.
You define the scope using one of these three, mutually exclusive arguments.
The default is all records.
nNext (Optional)
Type: Usual
The number of records to process, starting at nRecord. Specify 0 to ignore this argument.
nRecord (Optional)
Type: Usual
A single record number to process. Specify 0 to ignore this argument.
lRest (Optional)
Type: Usual
TRUE processes only records from nStart to the end of the file. FALSE processes all records.
lNoOpt (Optional)
Type: Usual
Disable (Rushmore) optimizations (not supported yet).Disable (Rushmore) optimizations (not supported yet).
lDesc (Optional)
Type: Usual
Should the default sort order be Descending
acOutPutFields (Optional)
Type: Usual
A list of fields to copy to cTargetFile.
The default is all fields

Return Value

Type: Logic
TRUE if successful; otherwise, FALSE.
Remarks
Tip Tip
The nNext, nRecord, and lRest arguments are mutually exclusive. You should not pass all three of them. And if you pass the cbWhile argument then this also controls the scope behavior.
DBSort() copies records from the current work area to another database file in sorted order. X# sorts character fields in accordance with the ASCII value of each character within the string. Numeric fields are sorted in numeric order, date fields are sorted chronologically, and logical fields are sorted with TRUE as the high value. Memo fields cannot be sorted. DBSort() performs as much of its operation as possible in memory, then it spools to a uniquely named temporary disk file.
This temporary file can be as large as the size of the source database file. Note also that DBSort() uses up three file handles: the source database file, the target database file, and the temporary file. If the database is opened in shared mode, you must lock the file to be sorted with FLock(). DBSort() is the functional equivalent of the SORT command.
Tip Tip
Deleted Source Records:
If SetDeleted() is TRUE, VODBSort() copies deleted records to the target database file; however, the deleted records do not retain their deleted status. No record is marked for deletion in the target file regardless of its status in the source file.
If SetDeleted() is FALSE, deleted records are not copied to the target database file. Similarly, filtered records are ignored during a sort and are not included in the target file.
Examples
The following example sorts a database on two fields (ignoring case) and uses it as the current file:
X#
1IF DBSort("sortdb.dbf", {"Last/C", "First/C"})
2    DBCloseArea()
3    USE sortdb NEW
4ENDIF
See Also