Documentation Home
MySQL 9.3 C API Developer Guide
Download this Manual
PDF (US Ltr) - 1.4Mb
PDF (A4) - 1.4Mb


5.4.19 mysql_fetch_field_direct()

MYSQL_FIELD *mysql_fetch_field_direct(MYSQL_RES *result,                         unsigned int fieldnr)

Description

Given a field numberfieldnr for a column within a result set, returns that column's field definition as aMYSQL_FIELD structure. Use this function to retrieve the definition for an arbitrary column. Specify a value forfieldnr in the range from 0 tomysql_num_fields(result)-1.

For metadata-optional connections, this function returnsNULL when theresultset_metadata system variable is set toNONE. To check whether a result set has metadata, use themysql_result_metadata() function. For details about managing result set metadata transfer, seeSection 3.6.7, “Optional Result Set Metadata”.

Return Values

TheMYSQL_FIELD structure for the specified column.NULL if the result set has no metadata.

Errors

None.

Example

unsigned int num_fields;unsigned int i;MYSQL_FIELD *field;num_fields = mysql_num_fields(result);for(i = 0; i < num_fields; i++){    field = mysql_fetch_field_direct(result, i);    printf("Field %u is %s\n", i, field->name);}