DF_INDEX_SEGMENT_FIELD
See Also: Get_Attribute, Set_Attribute
The number of the column used for the index segment.
Level
Index segment
Supported by
All Drivers
Type
Numeric, permanent
Access
Read / Write
Values
1 ~ maximum number of columns allowed by the database
Remarks
- 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_Segment_Field.
Each index segment uses one column. Use this attribute to set or retrieve the column number of the index segment. The column the segment is using must exist at the time the attribute is set.
Procedure ShowIndices Handle hTable
Integer iLastIndex
Integer iIndex
Integer iNumSegments
Integer iSegment
Integer iColumn
String sColumn
String sIndex
Integer iCase
Integer iDirection
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
Get_Attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex iSegment To iCase
If (iCase = DF_CASE_IGNORED) ;
Move (sColumn * "uppercased") To sColumn
Get_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex iSegment To iDirection
If (iDirection = DF_DESCENDING) ;
Move (sColumn * "descending") 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 segments of all indices of a table. If a segment is “uppercased” and/or descending, this is added to the segment description.
Procedure CreateClockTable
Handle hTable
Handle hoWorkspace
String sPath
String sOrigFolder
Integer iColumn
Integer iIndex
//*** Make sure int file comes in first folder of datapath by
//*** making that folder current
Get phoWorkspace Of ghoApplication To hoWorkspace
Get psDataPath Of hoWorkspace To sPath
Get PathAtIndex Of hoWorkspace sPath 1 To sPath
Get_Current_Directory To sOrigFolder
Set_Directory sPath
//*** Create a SQL Server table to store clock in/out times
//*** of employees
Move 0 To hTable
Structure_Start hTable "MSSQLDRV"
Set_Attribute DF_FILE_PHYSICAL_NAME Of hTable To "Clock.int"
Set_Attribute DF_FILE_RECNUM_TABLE Of hTable To False
Set_Attribute DF_FILE_LOGIN Of hTable To "SERVER=(local);Trusted_Connection=yes;DATABASE=Northwind"
Set_Attribute DF_FILE_TABLE_NAME Of hTable To "Clock"
Set_Attribute DF_FILE_USE_DUMMY_ZERO_DATE Of hTable To True
Move 0 To iColumn
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "EmployeeID"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_BCD
Set_Attribute DF_FIELD_LENGTH Of hTable iColumn To 10
Set_Attribute DF_FIELD_NATIVE_TYPE Of hTable iColumn To SQL_INTEGER
Move 0 To iColumn
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "ClockInTime"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_DATE
Move 0 To iColumn
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "ClockOutTime"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_DATE
Move 0 To iIndex
Create_Index hTable At iIndex
Set_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To 3
Set_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex 1 To 1
Set_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex 2 To 2
Set_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex 2 To DF_DESCENDING
Set_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex 3 To 3
Set_Attribute DF_FILE_PRIMARY_INDEX Of hTable To iIndex
Set_Attribute DF_INDEX_NAME Of hTable iIndex To "ClockPK"
Structure_End hTable
//*** Reset current working folder to original value
Set_Directory sOrigFolder
//*** Add to filelist and generate fd
Move 0 To hTable
Get_Attribute DF_FILE_NEXT_EMPTY Of hTable To hTable
If (hTable > 0) Begin
Set_Attribute DF_FILE_ROOT_NAME Of hTable To "MSSQLDRV:Clock"
Set_Attribute DF_FILE_DISPLAY_NAME Of hTable To "Clock sample table"
Set_Attribute DF_FILE_LOGICAL_NAME Of hTable To "Clock"
Open hTable
Get psDDSRCPath Of hoWorkspace To sPath
Get PathAtIndex Of hoWorkspace sPath 1 To sPath
If (Right(sPath, 1) <> Sysconf(Sysconf_Dir_Separator)) ;
Move (sPath - Sysconf(Sysconf_Dir_Separator)) To sPath
Move (sPath - "Clock.fd") To sPath
Output_Aux_File DF_AUX_FILE_FD For hTable To sPath
Close hTable
End
End_Procedure // CreateClockTable
The procedure above creates a new table in the SQL Server Northwind database. It is used to store clock in and clock out information of employees. One index called ClockPK is created on this table. The index has 3 segments.