Candidate(), Primary(), Descending(), For(), Sys(2021), Key(), Sys(14), Tag(), Unique(), ATagInfo()
These functions give you information about an index, either a stand-alone index or a tag. DESCENDING(), FOR() and, to a lesser extent, UNIQUE(), were welcome additions in FoxPro 2.6. CANDIDATE() and PRIMARY() were added in VFP 3. This group of functions tells you everything you'd need to know about an index in order to re-create it (except, of course, for the shortcomings we point out below). ATAGINFO(), added in VFP 7, fills an array with complete information about the indexes for a table, making the other functions somewhat less important for this purpose now.These functions can all give information about indexes for the current work area or for another work area. For the specified work area, most let you get index information for the current master index or another index. Some of them let you specify a particular CDX file, as well.The indexes open for any table are numbered based on the type of index and the order in which it was opened, with a catch. The order of indexes is:
Parameter |
Value |
Meaning |
cIndexName |
Character |
The name of a compound CDX file or a stand-alone IDX file, about which to return information. |
Omitted |
Return information about either the current index or all indexes, depending on the function. |
|
nIndexNumber |
Numeric |
The relative position of the index the function will report on. |
Omitted |
Return information about the master tag in the specified work area. |
|
nWorkArea |
Numeric |
Return information about the specified index for the table open in work area nWorkArea. |
Omitted |
If cAlias is also omitted, return information about the specified index for the table open in the current work area. |
|
cAlias |
Character |
Return information about the specified index for the table open with alias cAlias. |
Omitted |
If nWorkArea is also omitted, return information about the specified index for the table open in the current work area. |
|
ArrayName |
Array Name |
The array to fill with index information. |
nIndexes |
Numeric |
The number of rows in the array. |
Usage |
lIsCandidate = CANDIDATE( [ nIndexNumber [, nWorkArea | cAlias ] ] ) lIsPrimary = PRIMARY( [ nIndexNumber [, nWorkArea | cAlias ] ] ) |
Example |
OPEN DATA TasTrade USE Customer * This table has two tags, Company_Na, a regular index * and Customer_I, the primary index ? CANDIDATE(1) && Returns .F. ? CANDIDATE(2) && Returns .F. ? PRIMARY(1) && Returns .F. ? PRIMARY(2) && Returns .T. |
Usage |
lIsDescending = DESCENDING( [ cIndexName, ] nIndexNumber [, nWorkArea | cAlias ] ) |
Example |
USE Customer DISPLAY STATUS && shows two tags: Company_Na and Customer_I ? DESCENDING(1) && returns .F. ? DESCENDING(2) && returns .F. SET ORDER TO Company_Na DESCENDING && reverse name order ? DESCENDING(1) && returns .T. * Now for the complication SELECT 0 USE Customer AGAIN ALIAS MoreCust ? DESCENDING(1) && returns .T.! ? DESCENDING(2) && returns .F. |
Usage |
cFilter = FOR( [ nIndexNumber [, nWorkArea | cAlias ] ] ) cFilter = SYS( 2021, nIndexNumber [, nWorkArea | cAlias ] ) |
FOR() returns the filter expression in all caps. This is no big deal, except for one thing. Even a string enclosed in quotes in the filter expression is returned in capital letters. That means that you can't necessarily re-create the index using the results of this function. Because SYS(2021) is smart enough to not capitalize quoted strings, we suppose we have to change our minds and our advice and tell you to use SYS(2021) even though FOR() is more readable. ATAGINFO() also works correctly, so if you want more than just the filter expression, use that function instead. |
Example |
USE Customer * create a filtered index INDEX ON UPPER(Company_Name) ; FOR Country = "France" ; TAG FrComps ? FOR() && The new index is the master index && This returns the filter expression: && COUNTRY="FRANCE" ? SYS(2021,3) && Returns: COUNTRY = "France" ? FOR(1) && Returns "" since the first tag, Company_Na && has no filter. * Don't forget to delete this tag |
Usage |
cKey = KEY( [ [ cIndexName, ] nIndexNumber [, nWorkArea | cAlias ] ] ) cKey = SYS( 14, nIndexNumber [, nWorkArea | cAlias ] ) |
Example |
USE Customer * Customer has two index tags, Company_Na and Customer_I ? KEY(1) && Returns "UPPER(COMPANY_NAME)" ? SYS(14,2) && Returns "CUSTOMER_ID" SELECT 0 && Go to another work area ? KEY(2,"Customer") && Returns "CUSTOMER_ID" |
Usage |
CTagName = TAG( [ [ cIndexName, ] nIndexNumber [, nWorkArea | cAlias ] ] ) |
Example |
USE Customer ? TAG(1) && Returns "COMPANY_NA" ? TAG(2) && Returns "CUSTOMER_I" |
Usage |
lIsUnique = UNIQUE( [ [ cIndexName, ] nIndexNumber [, nWorkArea | cAlias ] ] ) |
Example |
USE Customer ORDER Company_Na ? UNIQUE() && Returns .F. ? UNIQUE(2) && Returns .F. |
Usage |
nIndexes = ATAGINFO( ArrayName [, cIndexName, [, nWorkArea | cAlias ] ] ) |
Column |
Type |
Content |
Replaces |
1 |
Character |
Tag or IDX name |
TAG() |
2 |
Character |
Tag type: "PRIMARY", "CANDIDATE", "REGULAR", or "UNIQUE" |
PRIMARY(), CANDIDATE(), UNIQUE() |
3 |
Character |
Key expression |
KEY(), SYS(14) |
4 |
Character |
Filter expression |
FOR(), SYS(2021) |
5 |
Character |
Order: "ASCENDING" or "DESCENDING" |
DESCENDING() |
6 |
Character |
Collate sequence |
IDXCOLLATE() |
Example |
USE Customer * Customer has two index tags, Company_Na and Customer_I * Create another one in an IDX INDEX ON UPPER(Address) TO Temp ATAGINFO(laTags) DISPLAY MEMORY LIKE laTags * Don't forget to delete this tag |
See Also |
Alter Table, Create Table, IDXCollate(), Index, Order(), Set Index, Set Order, TagCount(), TagNo(), Use |