Pass in the value buffer
To obtain the column value, you must pass in a pointer to a value buffer as an argument to mi_value() or mi_value_by_name(). The value buffer is the place that these functions put the column value that they retrieve from the current row. Both mi_value() and mi_value_by_name() represent a column value as a pointer to an MI_DATUM structure.
You can declare the value buffer in either of the following ways:
- If you know the data type of the column value, declare the value
buffer of this data type.
Declare the value buffer as a pointer to the column data type, regardless of whether the data type is passed by reference or by value.
- If you do not know the data type of the column value, declare
the value buffer with the MI_DATUM data type.
Your code can dynamically determine column type with the mi_column_type_id() or mi_column_typedesc() function. You can then convert (or cast) the MI_DATUM value to the data type that you need.
The mi_value() and mi_value_by_name() functions
allocate memory for the value buffer. However, this memory is only
valid until a new SQL statement executes or until the query completes.
In addition, the DataBlade®
API might
overwrite the value-buffer data in any of the following cases:
- The mi_next_row() function is called on the same connection.
- A call to mi_row_create() uses the row descriptor.
- The mi_row_free() function is called on the row structure.
- The mi_row_desc_free() function is called on the row descriptor.
If you need to save the value-buffer data for later use, you must
create your own copy of the data in the value buffer.
Tip: If
your DataBlade®
API module
requires simultaneous access to several rows at a time, you can use
a save set to hold rows. Save sets are useful for comparing or processing
multiple rows.