Set_Attribute
See Also: Execute Structure_Start, Get_Attribute, Structure_Start, Structure_End, Creating and Modifying Table Structures in the Database Essentials section of the Developing Database Applications book, DF_FILE_PHYSICAL_NAME for examples of creating a new table.
Purpose
To set a global, driver, database/connection, table, column, or index attribute.
Syntax
For table attributes:
Set_Attribute {attribute} [of {tableHandle} [{columnNum} | {indexNum} [{segmentNum}]]] ;
to {variable}
For driver attributes:
Set_Attribute {attribute} of {driverId} to {variable}
For database attributes:
Set_Attribute {attribute} of {driverId} {databaseHandle} to {variable}
Argument Explanation
- {attribute}: Attribute Id to be retrieved.
- {tableHandle}: Optional Handle for either a table or a structure.
- {columnNum}: Optional column to be interrogated.
- {indexNum}: Optional index to be interrogated.
- {segmentNum}: Number of a segment in
indexNumto be modified. - {variable}: A variable to hold the value of the attribute. It should be of the same type as the attribute, if known. Otherwise, you can safely use a String variable here.
- {driverId}: Identifier for a database driver.
- {databaseHandle}: Identifier of a database.
What It Does
DataFlex stores information about database drivers, connections, and tables as a set of system, table, index, and column attributes. Set_Attribute allows your program to modify the current setting of a given attribute.
Example – Runtime Attribute
Integer iFreq
Move 1000 to iFreq
Set_Attribute DF_RUNTIME_PROGRESS_FREQUENCY to iFreq
This example sets the interval between runtime progress updates to 1000 milliseconds (1 second).
Example – Global Attribute
String sFileListName
Move "filelist2.cfg" to sFileListName
Set_Attribute DF_FILELIST_NAME to sFileListName
This example changes the current filelist in use to filelist2.cfg.
Example – Driver Attribute
Procedure ShowDriverAttribute Integer iDriver
Set_Attribute DF_DRIVER_SILENT_LOGIN of iDriver to True
End_Procedure
This example sets silent driver login to true.
Driver Ids
Drivers can be enumerated using this function:
Function DriverIndex String sDriver Returns Integer
String sCurrentDriver
Integer iDriver iNumDrivers
Get_Attribute DF_NUMBER_DRIVERS to iNumDrivers
For iDriver From 1 To iNumDrivers
Get_Attribute DF_DRIVER_NAME of iDriver to sCurrentDriver
If (Uppercase(sDriver) = Uppercase(sCurrentDriver)) Begin
Function_Return iDriver
End
Loop
Function_Return 0
End_Function
Example – Database Attribute
Procedure ShowDBAttribute Integer iDriver Handle hDatabase
Integer iAttribValue
Get_Attribute DF_DATABASE_FIND_CACHE_TIMEOUT of iDriver hDatabase to iAttribValue
Move (iAttribValue * 2) to iAttribValue
Set_Attribute DF_DATABASE_FIND_CACHE_TIMEOUT of iDriver hDatabase to iAttribValue
End_Procedure
This example retrieves the database's find cache timeout and sets it to double its prior value.
Database Handles
Database Handles can be obtained via the DF_DATABASE_ID attribute.
Example – Table Attribute
Procedure AddTableToFilelist
Handle hTable
Move 20 to hTable // new number
Set_Attribute DF_FILE_LOGICAL_NAME of hTable to "OrderHea"
Set_Attribute DF_FILE_ROOT_NAME of hTable to "OrderHea"
Set_Attribute DF_FILE_DISPLAY_NAME of hTable to "Order Header Table"
End_Procedure
This example adds the OrderHea table to the current filelist as table number 20.
Example – Column Attribute
Integer iColumn iIndex
Handle hTable
Open Customer
Move Customer.File_Number to hTable
Move 1 to iColumn
Move 2 to iIndex
Structure_Start hTable "DATAFLEX"
Set_Attribute DF_FIELD_INDEX of hTable iColumn to iIndex
Structure_End hTable DF_STRUCTEND_OPT_NONE
This example sets the main index for column 1 in the Customer table to index 2.
Example – Index Attribute
Integer iIndex iSegment iColumn iNumSegments
Handle hTable
Open Customer
Move Customer.File_Number to hTable
Get_Attribute DF_FILE_LAST_INDEX_NUMBER of hTable to iIndex // get last index
Increment iIndex // add 1 to last index number
Move 2 to iNumSegments
Move 1 to iSegment
Structure_Start hTable "DATAFLEX"
Create_Index hTable at iIndex
Set_Attribute DF_INDEX_NUMBER_SEGMENTS of hTable iIndex to iNumSegments
Field_Map hTable "STATE" to iColumn // get column number of STATE column
Set_Attribute DF_INDEX_SEGMENT_FIELD of hTable iIndex iSegment to iColumn
Increment iSegment // next segment
Field_Map hTable "NAME" to iColumn // get column number of NAME column
Set_Attribute DF_INDEX_SEGMENT_FIELD of hTable iIndex iSegment to iColumn
Structure_End hTable DF_STRUCTEND_OPT_NONE
This example adds an index after the last index to the Customer table. The index has 2 segments: the STATE column and the NAME column.
Example – Index-Segment Attribute
Integer iIndex iSegment iColumn iNumSegments
Handle hTable
Open Customer
Move Customer.File_Number to hTable
Get_Attribute DF_FILE_LAST_INDEX_NUMBER of hTable to iIndex // get last index
Increment iIndex // add 1 to last index number
Move 2 to iNumSegments
Move 1 to iSegment
Structure_Start hTable "DATAFLEX"
Create_Index hTable at iIndex
Set_Attribute DF_INDEX_NUMBER_SEGMENTS of hTable iIndex to iNumSegments
Field_Map hTable "NAME" to iColumn // get column number of NAME column
Set_Attribute DF_INDEX_SEGMENT_FIELD of hTable iIndex iSegment to iColumn
Increment iSegment // next segment
// get column number of CUSTOMER_NUMBER column
Field_Map hTable "CUSTOMER_NUMBER" to iColumn
Set_Attribute DF_INDEX_SEGMENT_FIELD of hTable iIndex iSegment to iColumn
Structure_End hTable DF_STRUCTEND_OPT_NONE
This example adds an index after the last index to the Customer table. The index has 2 segments: the NAME column and the CUSTOMER_NUMBER column.
Lists of Attributes
- Database API Attributes
- Column Attributes
- Database Attributes
- Driver Attributes
- Global Attributes
- Index Attributes
- Index Segment Attributes
- Runtime Attributes
- Table Attributes
Notes
Set_Attribute may be executed only after a Structure_Start, except for global attributes. See Structure_Start for more information.