ade_odaddfield

Land Desktop Development ARX CPP SDK

Up a level
ade_odaddfield
 
 

Adds fields to a table.

int

ade_odaddfield(

char* tabname,

struct resbuf* fieldlist);

Returns RTNORM or an error code.

tabname The table name, which can be up to 25 characters long. It must be unique, contain no spaces, and start with an alphanumeric character.
fieldlist The list of fields to add; a sequence of field definitions.

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

Field propertyValue
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

The function adds fields to the table and to each of its records. In each record, the new fields are assigned default values in accord with their field definitions. The function has no effect on existing fields. In other words, the function adds fields to each set of object data defined by the table and attached to an object.

You must release the resbuf.

For an example, see Adding Fields to a Table.

The following sample creates a resbuf containing specifications for a new field, "field1" in the existing object data table, "table1". This resbuf is passed to ade_odaddfield() which returns a result code indicating the success of the operation. Then it releases the resbuf, as required.

struct resbuf* pAddFieldsRb = NULL;
char* pszOdTable = "table1";
pAddFieldsRb = acutBuildList(
                    RTSTR, "columns",
                    RTLB,
                        RTLB,
                            RTSTR, "colname", RTSTR, "field1",
                        RTDOTE,
                        RTLB,
                            RTSTR, "coldesc", RTSTR, "Field 1 Description",
                        RTDOTE,
                        RTLB,
                            RTSTR, "coltype", RTSTR, "character",
                        RTDOTE,
                        RTLB,
                            RTSTR, "defaultval", RTSTR, "Default Value",
                        RTDOTE,
                    RTLE,
                    // Define more fields as needed
                    0);
int nResultCode = ade_odaddfield(pszOdTable, pAddFieldsRb);
acutRelRb(pAddFieldsRb);
if (RTNORM == nResultCode) {
    acutPrintf(
        "\nThe specified field has been successfully added.");
}
else {
    acutPrintf(
        "\nThe specified field has not been added.");
}
acutRelRb(pAddFieldsRb);