The mi_column_default() function

The mi_column_default() function retrieves the default value of the specified column.

Syntax

mi_integer mi_column_default(row_desc, column_id, default_val)
   MI_ROW_DESC *row_desc;
   mi_integer  column_id;
   MI_DATUM    *default_val;
row_desc
A pointer to the row descriptor for the row that contains the column.
column_id
Indicates the column identifier, which specifies the position of the column in the specified row descriptor. Column numbering follows C array-indexing conventions: the first column in the row descriptor is at position zero.
default_val
A pointer to an MI_DATUM structure that contains the column default value. The mi_column_default() function allocates the MI_DATUM structure.
Valid in client LIBMI application? Valid in user-defined routine?
Yes Yes

Usage

The mi_column_default() function returns the default value that is defined for the column by the DEFAULT clause of the CREATE TABLE or ALTER TABLE statements. The mi_column_default() function returns the default_val structure, which contains a pointer to an MI_DATUM structure that holds the default value for the column. The format of the default value depends on whether the control mode for the retrieved data is text or binary representation. In binary mode, the format also depends on whether the MI_DATUM value is passed by reference or by value.

For example, you can create a table with two columns that have default values:

CREATE TABLE tab(col1 int DEFAULT 10, col2 varchar(12) DEFAULT 'permanent');

The mi_column_default() function returns a pointer to an MI_DATUM structure that contains the values of 10 and 'permanent'.

Return values

0
The specified column is not defined with a default value.
1 and a pointer to the MI_DATUM structure
The specified column contains a default value. If the value of the MI_DATUM structure is NULL, the default value of the column is NULL.
MI_ERROR
The function was not successful.