DF_FILE_LAST_INDEX_NUMBER
See Also: Get_Attribute, Set_Attribute, DF_INDEX_NUMBER_SEGMENTS
The number of the last index of the file.
Level
Table
Supported by
All Drivers
Type
Numeric, permanent
Access
Read Only
Values
0 ..
Remarks
The DataFlex way to handle indices is by assigning a number to an index and using that number to identify the sort order used in find operations. The Embedded Database uses this concept and identifies an index by using an index number. Pervasive.SQL also uses index numbers to identify its indices. In databases accessed through the DataFlex SQL Drivers, indices are usually identified by a name. The DataFlex SQL Drivers offer ways to map an index name to an index number.
Index numbering does not have to be continuous; the range of index numbers defined for a table can contain “holes”. The DF_FILE_LAST_INDEX_NUMBER attribute returns the last index number actually in use. To test if an index exists, use the DF_INDEX_NUMBER_SEGMENTS attribute; when it returns 0 (zero), the index does not exist. When it returns a value greater than 0 (zero), the index does exist.
This attribute cannot be set directly. It is manipulated by using the Create_Index and Delete_index commands.
In some database systems, database files (e.g., DataFlex files) can have index "holes". For example, a DataFlex file may have indexes 1, 2, 4, and 8. In this case, there would be no index number 3, 5, 6, and 7. For such a file, DF_FILE_LAST_INDEX_NUMBER would be 8. To determine which index numbers are used and which are not, examine the DF_INDEX_NUMBER_SEGMENTS attribute for each index number. Those showing 0 are unused (no segments).
Example Code
Procedure ShowIndices Handle hTable
String sTable
Integer iLastIndex
Integer iIndex
Integer iNumSegments
Integer iSegment
Integer iColumn
String sColumn
String sIndex
Get_Attribute DF_FILE_LOGICAL_NAME Of hTable To sTable
Showln "Index information for table: " sTable
Get_Attribute DF_FILE_LAST_INDEX_NUMBER Of hTable To iLastIndex
For iIndex From 1 To iLastIndex
Get_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To iNumSegments
If (iNumSegments > 0) Begin
Move "" To sIndex
For iSegment From 1 To iNumSegments
Get_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex iSegment To iColumn
Get_Attribute DF_FIELD_NAME Of hTable iColumn To sColumn
If (iSegment > 1) ;
Move (sIndex + ",") To sIndex
Move (sIndex * sColumn) To sIndex
Loop
Showln " Index number: " iIndex " (" sIndex ")"
End
Loop
If (iLastIndex = 0) ;
Showln " NO index defined."
End_Procedure // ShowIndices
The sample procedure above shows all indices of a table, presenting an index by the names of the segments separated by commas.