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


5.4.17 mysql_fetch_field()

MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *result)

Description

Returns the definition of one column of a result set as aMYSQL_FIELD structure. Call this function repeatedly to retrieve information about all columns in the result set.mysql_fetch_field() returnsNULL when no more fields are left.

mysql_fetch_field() is reset to return information about the first field each time you execute a newSELECT query. The field returned bymysql_fetch_field() is also affected by calls tomysql_field_seek().

If you've calledmysql_real_query() ormysql_query() to perform aSELECT on a table but have not calledmysql_store_result(), MySQL returns the default blob length (8KB) if you callmysql_fetch_field() to ask for the length of aBLOB field. (The 8KB size is chosen because MySQL does not know the maximum length for theBLOB. This should be made configurable sometime.) Once you've retrieved the result set,field->max_length contains the length of the largest value for this column in the specific query.

Return Values

TheMYSQL_FIELD structure for the current column.NULL if no columns are left.

Errors

None.

Example

MYSQL_FIELD *field;while((field = mysql_fetch_field(result))){    printf("field name %s\n", field->name);}