DF_INDEX_NUMBER_SEGMENTS
See Also: Get_Attribute, Set_Attribute, Delete_Index, DF_FILE_LAST_INDEX_NUMBER
The number of segments in the index.
Level
Index
Supported by
All Drivers
Type
Numeric, permanent
Access
Read / Write
Values
0 ~ maximum number of segments allowed by the database
Remarks
The DF_INDEX_NUMBER_SEGMENTS attribute values range from 0 to the maximum number of segments in an index for the database in use. The attribute can be set to alter an index definition; however, it cannot be set to 0 (zero). To delete an index, use the Delete_Index command. To create an index, use the Create_Index command and set the DF_INDEX_NUMBER_SEGMENTS attribute.
The attribute can be used to determine if an index exists at a certain number. If the number of segments is 0 (zero), no index exists; if the number of segments is 1 or greater, the index exists.
There are no Create_IndexSegment or Delete_IndexSegment commands. Segments are created or deleted by setting the DF_INDEX_NUMBER_SEGMENTS attribute to its new value and adjusting the individual index segment attributes.
For permanent indexes (DF_INDEX_SQL_TYPE = DF_INDEX_SERVER, DF_INDEX_CLIENT, DF_INDEX_SERVER_ONLY), this attribute can only be set inside a Structure_Start ... Structure_End operation.
For temporary indexes (DF_INDEX_SQL_TYPE = DF_INDEX_TEMPORARY), this attribute can only be set outside a Structure_Start ... Structure_End operation.
The value of this attribute may be stored in the intermediate file under the keyword Index_Number_Segments.
Example Procedures
ShowExistingIndices
Procedure ShowExistingIndices Handle hTable
Integer iLastIndex iIndex iNumSegments
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) ;
Showln " Index " iIndex
Else ;
Showln " Index " iIndex " does NOT exist"
Loop
End_Procedure
The sample procedure above shows all existing (and non-existing) indices of a given table up to the last index number defined for this table.
DeleteSegment
Procedure DeleteSegment Handle hTable Integer iIndex Integer iSegment
Integer iNumSegments iCurSegment iSegmentCase iSegmentDirection iSegmentColumn
Get_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To iNumSegments
If (iSegment = iNumSegments) ;
Set_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To (iNumSegments - 1)
Else If (iSegment > 0 And iSegment < iNumSegments) Begin
For iCurSegment From iSegment To (iNumSegments - 1)
//*** Move index segment attributes
Get_Attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex (iCurSegment + 1) To iSegmentCase
Get_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex (iCurSegment + 1) To iSegmentDirection
Get_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex (iCurSegment + 1) To iSegmentColumn
Set_attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex iCurSegment To iSegmentCase
Set_attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex iCurSegment To iSegmentDirection
Set_attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex iCurSegment To iSegmentColumn
Loop
Set_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To (iNumSegments - 1)
End
End_Procedure
The sample procedure above deletes an index segment from a given index for a given table. Note that the handle you need to pass must be a structure handle.
InsertSegment
Struct IndexSegment
Handle hTable
Integer iIndex
Integer iSegment
Integer iColumn
Integer iCase
Integer iDirection
End_Struct // IndexSegment
Procedure InsertSegment IndexSegment sSegment
Handle hTable
Integer iIndex iSegment iNumSegments iCurSegment iSegmentCase iSegmentDirection iSegmentColumn
//*** Move structure members to locals for shorter code
Move sSegment.hTable To hTable
Move sSegment.iIndex To iIndex
Move sSegment.iSegment To iSegment
Get_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To iNumSegments
If (iSegment > iNumSegments) Begin
Set_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To (iNumSegments + 1)
Move (iNumSegments + 1) To iCurSegment
End
Else If (iSegment > 0 And iSegment <= iNumSegments) Begin
Set_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To (iNumSegments + 1)
Move iNumSegments To iCurSegment
While (iCurSegment > sSegment.iSegment)
//*** Move index segment attributes
Get_Attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex (iCurSegment - 1) To iSegmentCase
Get_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex (iCurSegment - 1) To iSegmentDirection
Get_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex (iCurSegment - 1) To iSegmentColumn
Set_attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex iCurSegment To iSegmentCase
Set_attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex iCurSegment To iSegmentDirection
Set_attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex iCurSegment To iSegmentColumn
Decrement iCurSegment
End
//*** Now set new segment attributes
Set_attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex iCurSegment To sSegment.iCase
Set_attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex iCurSegment To sSegment.iDirection
Set_attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex iCurSegment To sSegment.iColumn
End
End_Procedure
The sample procedure above inserts an index segment into a given index for a given table. Note that the handle you need to pass must be a structure handle.