DF_FIELD_INDEX
See Also: Get_Attribute, Set_Attribute
The number of the Main Index used for searching by the values in a field.
Level
Column
Supported by
All Drivers
Type
Integer, permanent
Access
Read / Write
Values
0 ~ highest index number defined on the table
Remarks
This attribute is also known as the field's Main Index. The main index is used when using a column name with the find command. For example, if you want to find the next customer by its name, you could issue the command:
Find Gt Customer.Name
The command will result in the find logic getting the DF_FIELD_INDEX attribute of the Customer.Name column and finding the next record according to that index. If there is no main index defined on a column and a find operation as described above is attempted, it will result in a DFERR_FIELD_NOT_INDEXED error.
The Main Index of a column is also used by the relate logic to determine which index to use to find a record in a file that is related through the field. When the relation is a multi-segment relation, the relate logic will use the main index of the first relating column. Assuming we have a relationship between two tables called Child and Parent, where Child.FKCol1 and Child.FKCol2 relate to Parent.PKCol1 and Parent.PKCol2, issuing a Relate Child command will find the parent record based on the main index of Parent.PKCol1.
When pressing a find key in a data entry object (DEO), the main index of the column edited by the DEO will be used by default. The data entry object calls the Field_Index function of the DataDictionary “owning” the table. That function will return the main index by default.
For the Embedded Database and DataFlex Pervasive.SQL Drivers, this is a permanent attribute that can only be set inside a Structure_Start ... Structure_End operation. For the DataFlex SQL Drivers, it is possible to set this attribute outside a structure operation. This support is intended to be used when opening tables without intermediate files so the main index can be set if needed.
At the time that this attribute is set, the index it points to must exist when using the Embedded Database. If the index does not yet exist, the DFERR_ATTRIBUTE_VALUE_WARNING error will be generated. The other drivers allow setting the attribute to a non-existent index. Make sure the index is created before ending the structure operation.
For the non-Embedded Database drivers, the permanent value of this attribute is stored in the intermediate file using the Field_Index keyword.
Procedure ChangeMainIndex Handle hTable Integer iColumn Integer iNewIndex
Integer iOldIndex
String sColumn
String sTable
String sMessage
Open hTable Mode DF_EXCLUSIVE
Get_Attribute DF_FILE_ROOT_NAME Of hTable To sTable
Get_Attribute DF_FIELD_NAME Of hTable iColumn To sColumn
Get_Attribute DF_FIELD_INDEX Of hTable iColumn To iOldIndex
If (iOldIndex > 0) Begin
If (iOldIndex <> iNewIndex) ;
Move ("Column" * sColumn * "of table" * sTable * "currently has main index:" * String(iOldIndex)) To sMessage
Else ;
Move ("Column" * sColumn * "of table" * sTable * "already has main index:" * String(iOldIndex)) To sMessage
End
Else ;
Move ("Column" * sColumn * "of table" * sTable * "currently has no main index.") To sMessage
Send Info_Box sMessage
If (iOldIndex > 0 And iOldIndex <> iNewIndex) Begin
Structure_Start hTable
Set_Attribute DF_FIELD_INDEX Of hTable iColumn To iNewIndex
Structure_End hTable
End
Else ;
Close hTable
End_Procedure // ChangeMainIndex
The sample code above changes the main index of a column. It first gets the current setting of the main index and shows this. Only when the main index is already set and the new value is different, it permanently changes the main index for the column.