Skip to content

DF_FILE_TABLE_CHARACTER_FORMAT

The format of the character data in the table.

Level

Table

Supported by

The DataFlex SQL Drivers (SQL Server, DB2, and ODBC)

Type

String, permanent

Access

Read / Write

Values

  • "OEM"
  • "ANSI"

Syntax

Use cli.pkg
Get_Attribute DF_FILE_TABLE_CHARACTER_FORMAT of {tableNumber} to {stringVariable}
Set_Attribute DF_FILE_TABLE_CHARACTER_FORMAT of {tableNumber} to {"OEM" | "ANSI"}

Remarks

This attribute determines in what character format data is stored in SQL databases. The DataFlex SQL drivers perform character translations based on this setting.

DataFlex 2021 and later support ANSI and Unicode character formats. When DF_FILE_TABLE_CHARACTER_FORMAT is set to ANSI, it should be interpreted as ANSI or Unicode. ANSI/Unicode is the default table character format and should normally not be changed.

DataFlex versions before DataFlex 2021 and the associated SQL Drivers (6.3) only supported ANSI or OEM data. ANSI and OEM are single-byte encodings that are limited to 256 characters (no Unicode).

The OEM character format is still supported for backward compatibility with earlier DataFlex versions, but it is strongly recommended to convert OEM tables to ANSI/Unicode, and this is mandatory for applications to support Unicode data.

See Character Formats (OEM or ANSI) for further information about character formats and converting character formats.

Be aware that setting this attribute’s value will only change the way data is presented and new data is stored. Existing data will not be converted from OEM to ANSI or vice versa. You need to run a conversion utility (like the OEM to ANSI Conversion Wizard) to convert existing data. Just changing this setting without conversion may corrupt your data!

This attribute can be set both inside and outside of a Structure_Start ... Structure_End operation. The value of the attribute is stored in the intermediate file using the keyword Table_Character_Format.

Example

Procedure ConvertRow Handle hTable String sOrgFormat String sNewFormat
    String sValue
    Integer iNumColumns
    Integer iType
    Integer iColumn

    //*** Loop through the fields and convert ASCII and text fields
    Get_Attribute DF_FILE_NUMBER_FIELDS Of hTable To iNumColumns
    For iColumn From 1 To iNumColumns
        Get_Attribute DF_FIELD_TYPE Of hTable iColumn To iType
        If ((iType = DF_ASCII) Or (iType = DF_TEXT)) Begin
            Set_Attribute DF_FILE_TABLE_CHARACTER_FORMAT Of hTable To sOrgFormat
            Get_Field_Value hTable iColumn To sValue
            Set_Attribute DF_FILE_TABLE_CHARACTER_FORMAT Of hTable To sNewFormat
            Set_Field_Value hTable iColumn To sValue
        End
    Loop
End_Procedure // ConvertRow

Procedure ConvertTableCharacterFormat Handle hTable Integer iIndex String sNewFormat
    String sFormat
    Boolean bFound
    String sOrgFormat

    Get_Attribute DF_FILE_TABLE_CHARACTER_FORMAT Of hTable To sFormat
    If (Uppercase(sFormat) <> Uppercase(sNewFormat)) Begin
        If (Uppercase(sNewFormat) = "ANSI") Move "OEM" To sOrgFormat
        Else If (Uppercase(sNewFormat) = "OEM") Move "ANSI" To sOrgFormat
        Else Procedure_Return

        Begin_Transaction
            Clear hTable
            vFind hTable iIndex Gt
            While (Found)
                Send ConvertRow hTable sOrgFormat sNewFormat
                Get_Attribute DF_FILE_STATUS Of hTable To iStatus
                If (iStatus = DF_FILE_ACTIVE_CHANGED) SaveRecord hTable
                vFind hTable iIndex Gt
            End
        End_Transaction
    End
End_Procedure // ConvertTableCharacterFormat

The sample procedure above converts a table from one format to the other. It does this in one big transaction. To run this procedure, the transaction log of the database must be big enough to hold this size of transaction. Note that the procedure uses the feature that moving a value to a column that already has that value is not seen as a change. This decreases the transaction size to those records that actually do change.