MySQL 8.4.1
Source Code Documentation
s_mysql_mysql_stmt_metadata Struct Reference

A service that provides the API to get information about statement metadata including the number of the parameters in a prepared statement and their metatdata. More...

#include <mysql_statement_service.h>

Public Attributes

mysql_service_status_t(* param_count )(my_h_statement statement, uint32_t *parameter_count)
 Get the number of parameters in the prepared statement. More...
 
mysql_service_status_t(* param_metadata )(my_h_statement statement, uint32_t index, const char *metadata, void *data)
 Get the metadata of a parameter in a prepared statement. More...
 

Detailed Description

A service that provides the API to get information about statement metadata including the number of the parameters in a prepared statement and their metatdata.

For prepared statement, to get the number of parameters uint64_t num_parameters; SERVICE_PLACEHOLDER(mysql_stmt_metadata)->param_count(statement, &num_parameters)

Member Data Documentation

◆ param_count

mysql_service_status_t(* s_mysql_mysql_stmt_metadata::param_count) (my_h_statement statement, uint32_t *parameter_count)

Get the number of parameters in the prepared statement.

Note
Calling this on regular statements would fail.
Parameters
[in]statementA handle to the statement
[out]parameter_countThe number of parameters
Returns
Status of the performed operation
Return values
falsesuccess
truefailure

◆ param_metadata

mysql_service_status_t(* s_mysql_mysql_stmt_metadata::param_metadata) (my_h_statement statement, uint32_t index, const char *metadata, void *data)

Get the metadata of a parameter in a prepared statement.

The metadata specifies whether the parameter can be null, the type of the parameter, whether the value is signed.

For example, in this query, "SELECT * FROM table WHERE col = ?", we need to know the parameter specified by '?' is null or not, its type, and if it is integer, whether it is signed. MySQL will provide this information and this function is to get these info.

auto is_nullable = bool{}; if (SERVICE_PLACEHOLDER(mysql_stmt_metadata) ->param_metadata(statement, index, "null_bit", &is_nullable)) return {}; auto sql_type = Sql_type{}; if (SERVICE_PLACEHOLDER(mysql_stmt_metadata) ->param_metadata(statement, index, "type", &sql_type)) return {}; auto is_unsigned = bool{}; if (SERVICE_PLACEHOLDER(mysql_stmt_metadata) ->param_metadata(statement, index, "is_unsigned", &is_unsigned)) return {};

Note
Calling this on regular statements would fail.
Parameters
[in]statementA handle to the statement
[in]index0-based index of the parameter
[in]metadataThe metadata argument is the attribute that you want to get

The following attributes are supported:

  • Parameter is null ("null_bit" of the returned bool type)
  • Parameter type ("type" of the returned uint64_t type)
  • Parameter is unsigned ("is_unsigned" of the returned bool type)
Parameters
[out]dataThe data argument is the value for the member
Returns
Status of the performed operation
Return values
falsesuccess
truefailure

The documentation for this struct was generated from the following file: