Obtain row types
The mi_value() and mi_value_by_name() functions can return the MI_ROW_VALUE value status for a column with a row data type: unnamed or named. The contents of the MI_DATUM structure that these functions pass back is a pointer to a row structure that contains the fields of the row type.
The format of the field values depends on whether the control mode
for the query data is text or binary representation, as the following
table shows.
Control mode | Contents of fields within row structure |
---|---|
Text representation | Null-terminated strings |
Binary representation | Internal formats of field values |
For a list of the text and binary representations of data types, see Table 1.
You can extract the individual field value from the row type by passing the returned MI_ROW pointer to mi_value() or mi_value_by_name() for each field value you need to retrieve.
The get_data() function calls the get_row_data() function
for an mi_value() return value of MI_ROW_VALUE.
This function takes the pointer to a row structure as an argument
and uses mi_value() on it to obtain field values
in text representation.
mi_integer get_row_data(row)
MI_ROW *row;
{
mi_integer numflds, fldlen;
MI_ROW_DESC *rowdesc;
mi_integer i;
char *fldname, *fldval;
mi_boolean is_nested_row;
/* Get row descriptor */
rowdesc = mi_get_row_desc(row);
/* Get number of fields in row type */
numflds = mi_column_count(rowdesc);
/* Display the field names of the row type */
for ( i=0; i < numflds; i++ )
{
fldname = mi_column_name(rowdesc, i);
DPRINTF("trc_class, 11, ("%s\t", fldname));
}
DPRINTF("trc_class", 11, ("\n"));
/* Get field values for each field of row type */
for ( i=0, i < numflds; i++ )
{
is_nested_row = MI_FALSE;
switch( mi_value(row, i, &fldval, &fldlen) )
{
case MI_ERROR:
...
case MI_NULL_VALUE:
fldval = "NULL";
break;
case MI_NORMAL_VALUE:
break;
case MI_ROW_VALUE:
/* have nested row type - make recursive call */
is_nested_row = MI_TRUE;
get_row_data((MI_ROW *)fldval);
break;
default:
...
}
if ( is_nested_row == MI_FALSE )
DPRINTF("trc_class", 11, ("%s\t", fldval));
}
return (0);
}