Documentation Home
MySQL 8.0 C API Developer Guide
Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb
HTML Download (TGZ) - 159.0Kb
HTML Download (Zip) - 190.2Kb

11.23 mysql_stmt_result_metadata()

mysql_stmt_result_metadata(MYSQL_STMT *stmt)


mysql_stmt_result_metadata() is used to obtain result set metadata for a prepared statement. Its use requires that these conditions be satisified:

mysql_stmt_result_metadata() may be called after preparing the statement with mysql_stmt_prepare() and before closing the statement handler. The result set metadata returned by mysql_stmt_result_metadata() is in the form of a pointer to a MYSQL_RES structure that can be used to process the meta information such as number of fields and individual field information. This result set pointer can be passed as an argument to any of the field-based API functions that process result set metadata, such as:

When you are done with the metadata result set structure, free it by passing it to mysql_free_result(). This is similar to the way you free a result set structure obtained from a call to mysql_store_result().

If the executed statement is a CALL statement, it may produce multiple result sets. In this case, do not call mysql_stmt_result_metadata() immediately after mysql_stmt_prepare(). Instead, check the metadata for each result set separately after calling mysql_stmt_execute(). For an example of this technique, see Chapter 25, C API Prepared CALL Statement Support.

The result set returned by mysql_stmt_result_metadata() contains only metadata. It does not contain any row results. To obtain the row results, use the statement handler with mysql_stmt_fetch() after executing the statement with mysql_stmt_execute(), as usual.

Return Values

A MYSQL_RES result structure. NULL if no meta information exists for the prepared statement.



See the Example in Section 11.11, “mysql_stmt_fetch()”.