ade_odmodifyfield

Land Desktop Development ARX CPP SDK

Up a level
ade_odmodifyfield
 
 

Modifies field properties in a table.

int

ade_odmodifyfield(

char* tableName,

struct resbuf* fieldList);

Returns RTNORM or an error code.

tableName Table name can be up to 25 characters long. Must be unique, contain no spaces, and start with an alphanumeric character.
fieldList Fields to modify. A sequence of field definitions. See Field Definitions below.

The ade_odmodifyfield function affects all active drawings in the drawing set. There should not be any queried objects for this operation.

Note  This function will not operate unless your end user has superuser privileges.

Field Definitions

The field definitions are introduced by the "columns" string. Each field definition is a list of a-lists, and each a-list consists of a field property and a value, as follows:

Field PropertyField Value
colname Field name (RTSTR) can be up to 31 characters long. Must be unique, contain no spaces, and start with an alphanumeric character
coldesc Field description (RTSTR)
coltype Field data type
defaultval Default field value

In the fieldlist argument, specify the fields to modify and their new field definitions. The function acts on these fields only and has no effect on any others. For each field you specify, the function replaces the existing field definition with the new field definition in the table and in each of its records. In each record, the modified fields are assigned default values that correspond to their new field definitions. In other words, the function replaces field definitions in each set of object data defined by the table and attached to an object.

The fieldlist argument has the same format as the fieldlist argument in ade_odaddfield. The entry for this function has source code examples.

If a new field definition changes the field type, field values in existing records are converted to the new type if possible. This conversion may alter the values. For example, if you change the field type from real to integer, existing field values are converted by truncating their decimal parts.

The following sample creates a resbuf containing the field defenitions to modify. ade_odmodifyfield() uses this resbuf and returns a result code indicating a successful operation. Then it releases the resbuf, as required.

struct resbuf* pModifyFieldRb = NULL;
char* pszOdTable = "table1";
pModifyFieldRb = acutBuildList(
                    RTSTR, "columns",
                    RTLB,
                        RTLB,
                            RTSTR, "colname", RTSTR, "FIELD1",
                        RTDOTE,
                        RTLB,
                            RTSTR, "coldesc", RTSTR, "Field 1 Description",
                        RTDOTE,
                        RTLB,
                            RTSTR, "coltype", RTSTR, "integer",
                        RTDOTE,
                        RTLB,
                            RTSTR, "defaultval", RTSTR, "0",
                        RTDOTE,
                    RTLE,
                    // Define more fields as needed
                    0);
int nResultCode = ade_odmodifyfield(pszOdTable, pModifyFieldRb);
if (RTNORM == nResultCode) {
    acutPrintf(
        "\nThe specified fields have been successfully modified.");
}
else {
    acutPrintf(
        "\nThe specified fields have not been modified.");
}
acutRelRb(pModifyFieldRb);