Rechercher dans le manuel MySQL
28.7.27 C API Optional Result Set Metadata
When a client executes a statement that produces a result set,
MySQL by default makes available both the data the result set
contains, and result set metadata that provides information about
the result set data. Metadata is contained in the
MYSQL_FIELD
structure (see
Section 28.7.5, “C API Data Structures”), which is returned by the
mysql_fetch_field()
,
mysql_fetch_field_direct()
, and
mysql_fetch_fields()
functions.
Clients can indicate on a per-connection basis that result set metadata is optional and that the client will indicate to the server whether to return it. Suppression of metadata transfer can improve performance, particularly for sessions that execute many queries that return few rows each.
There are two ways to indicate that result set metadata is optional for a connection. They are equivalent, so either one suffices:
At connect time, enable the
CLIENT_OPTIONAL_RESULTSET_METADATA
flag for theclient_flag
argument ofmysql_real_connect()
.Prior to connect time, enable the
MYSQL_OPT_OPTIONAL_RESULTSET_METADATA
option formysql_options()
.
For metadata-optional connections, the client sets the
resultset_metadata
system
variable to control whether the server returns result set
metadata. Permitted values are FULL
(return all
metadata; this is the default) and NONE
(return
no metadata).
For metadata-optional connections, the
mysql_fetch_field()
,
mysql_fetch_field_direct()
, and
mysql_fetch_fields()
functions
return NULL
when the
resultset_metadata
system
variable is set to NONE
.
To check whether a result set has metadata, use the
mysql_result_metadata()
function.
This function returns RESULTSET_METADATA_FULL
or RESULTSET_METADATA_NONE
to indicate that the
result set has full metadata or no metadata, respectively.
mysql_result_metadata()
can be
useful if the client does not know in advance whether a result set
has metadata. For example, if a client executes a stored procedure
that returns multiple result sets and might change the
resultset_metadata
system
variable, the client can invoke
mysql_result_metadata()
for each
result set to determine whether it has metadata.
For connections that are not metadata-optional, setting
resultset_metadata
to
NONE
produces an error.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-c-api-optional-metadata.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.