f2s_column_identity_state

Applies to: Oracle, MS SQL, MySql/MariaDB, PostgreSQL Drivers

Syntax

set_attribute f2s_column_autonumber_state of {FileNumber} {FieldNumber} to {variable}
get_attribute f2s_column_autonumber_state of {FileNumber} {FieldNumber} to {variable}

Parameter

Description

FileNumber

Number of the file (filename.File_Number)

FieldNumber

Number of the field

variable

Boolean variable. If true, this field auto increments. If false, it does not.

Description

Auto incrementing is a technique used in Dataflex usually for fields that are set as the unique identifier. Instead of generating a value or manually inserting data into the column, when a field auto increments, the value of the field increases by one (usually) with each record. This field is used to get or set whether the field uses this technique or not.

The attribute can only be set inside of a Structure_Start/Structure_End block during table creation. Existing fields cannot be set as Identity columns. A table may only have one identity column.

Getting the attribute’s value can be done at anytime. The value is stored as a boolean, either true or false.

Note

This attribute does not work properly for recnum fields. For example, using the Order Entry table from the DataFlex example:

get_attribute f2s_column_identity_state of inventory.FileNumber 0 to bIdent

bIdent will be 0.

Examples

get_attribute

Integer iField iFields
String sField
boolean bCreated

//use the dataflex attribute to the get the total number of fields
Get_Attribute DF_FILE_NUMBER_FIELDS of newcust.File_Number to iFields
//loop through the fields to see which ones are auto-increment
For iField from 0 to iFields
  Get_Attribute f2s_column_identity_state of newcust.File_Number iField to bCreated
  Get_Attribute DF_FIELD_NAME of newcust.File_Number iField to sField
  If (bCreated) Showln "Field " sField " is an identity field"
  Else Showln "Field " sField " is NOT an identity field"
Loop
set_attribute

In this example, a new table, SiteInfo is created. It’s identity column is SiteInfoID. It is assumed that the server has been logged into and the database set.

Handle hTable

//turns off the warning message that I am restructing data
Set_Attribute f2s_restructure_warning_state of _f2s_ActiveDriverId to False

Showln "******************Creating table SiteIfo***********************"

//setting hTable to 0, this is a new table
Move 0 to hTable

Structure_Start hTable _f2s_ActiveDriver
    Set_Attribute DF_FILE_PHYSICAL_NAME of hTable to "SiteInfo"
   //Don't want a recnum
    Set_Attribute DF_FILE_RECNUM_TABLE of hTable to False
    //create the id column - should be identity column
    Move 0 to iColumn
    Create_Field hTable At iColumn
    Set_Attribute DF_FIELD_NAME of hTable iColumn to "SiteInfoID"
    Set_Attribute DF_FIELD_TYPE of hTable iColumn to DF_BCD
    Set_Attribute DF_FIELD_LENGTH of hTable iColumn to 6
    Set_Attribute f2s_column_identity_state of hTable iColumn to True

    Move 0 to iColumn
    Create_Field hTable At iColumn
    Set_Attribute DF_FIELD_NAME of hTable iColumn to "SiteNumber"
    Set_Attribute DF_FIELD_TYPE of hTable iColumn to DF_BCD
    Set_Attribute DF_FIELD_LENGTH of hTable iColumn to 6

    Move 0 to iColumn
    Create_Field hTable At iColumn
    Set_Attribute DF_FIELD_NAME of hTable iColumn to "SiteName"
    Set_Attribute DF_FIELD_TYPE of hTable iColumn to DF_ASCII
    Set_Attribute DF_FIELD_LENGTH of hTable iColumn to 100

    Move 0 to iColumn
    Create_Field hTable At iColumn
    Set_Attribute DF_FIELD_NAME of hTable iColumn to "Comment"
    Set_Attribute DF_FIELD_TYPE of hTable iColumn to DF_ASCII
    Set_Attribute DF_FIELD_LENGTH of hTable iColumn to 255

    Move 0 to iIndex
    Create_Index hTable At iIndex
    Set_Attribute DF_INDEX_NUMBER_SEGMENTS of hTable iIndex to 1
    Set_Attribute DF_INDEX_SEGMENT_FIELD of hTable iIndex 1 to 1

Structure_End hTable

Replaces

DF_FIELD_AUTO_INCREMENT