TOrdInfo
Fonte: source/classes/tordinfo.prg
Standalone class
TOrdInfo encapsulates index order metadata for DBF tables. It stores the tag name, index bag (file) name, key expression, uniqueness flag, field names, and filter conditions. It can also generate SQL-equivalent ORDER BY and DECLARE statements for migrating indexed DBF logic to SQL backends.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
cTagName | Character | Index tag name |
cBagName | Character | Index bag (file) name, e.g. "customers.cdx" |
cExpKey | Character | Index key expression as a string |
bExpKey | Block | Index key expression as a code block |
lUnique | Logical | .T. if the index enforces unique keys |
aFieldName | Array | Array of field names used in the index key |
Methods
| Method | Description |
|---|---|
New( cTag, cBag, cExpKey, bExpKey, lUniq, cFilt, aAscDsc, cFldRec ) | Create a new index order information object |
SqlOrder() | Generate an SQL ORDER BY clause from the index key expression |
SqlDeclare() | Generate an SQL DECLARE statement for the index |
Example: Translate DBF Index to SQL ORDER BY
#include "FiveWin.ch"
function Main()
local oIdx
// Describe a DBF index
oIdx := TOrdInfo():New( "NAME", "customers.cdx", ;
"UPPER(LAST)+UPPER(FIRST)", .F. )
? "Tag:", oIdx:cTagName
? "Bag:", oIdx:cBagName
? "Key expr:", oIdx:cExpKey
? "Unique:", oIdx:lUnique
// Generate equivalent SQL ORDER BY
? "SQL ORDER BY:", oIdx:SqlOrder()
// Output: ORDER BY UPPER(LAST), UPPER(FIRST)
// Generate SQL DECLARE
? "SQL DECLARE:", oIdx:SqlDeclare()
return nil
Notes
SqlOrder()parses the DBF index key expression and translates it into an equivalent SQL ORDER BY clause. It handles Funções like UPPER(), LOWER(), DTOS(), and STR() by converting them to SQL-compatible forms.SqlDeclare()produces a DECLARE statement suitable for creating an equivalent SQL index.- The
aFieldNamearray is populated automatically by parsing the key expression to extract field name references. - TOrdInfo is used internally by FWH's SQL translation layer to convert DBF navigation logic to SQL queries.