C API Prepared Statement Data Structures
2192
the statement. To specify the statement to prepare, pass the
MYSQL_STMT
pointer and the statement
string to
mysql_stmt_prepare()
.
• To provide input parameters for a prepared statement, set up
MYSQL_BIND
structures and pass
them to
mysql_stmt_bind_param()
. To receive output column values, set up
MYSQL_BIND
structures and pass them to
mysql_stmt_bind_result()
.
• The
MYSQL_TIME
structure is used to transfer temporal data in both directions.
The following discussion describes the prepared statement data types in detail. For examples that
show how to use them, see
Section 20.6.10.10, “
mysql_stmt_execute()
”
, and
Section 20.6.10.11,
“
mysql_stmt_fetch()
”
.
•
MYSQL_STMT
This structure is a handle for a prepared statement. A handle is created by calling
mysql_stmt_init()
, which returns a pointer to a
MYSQL_STMT
. The handle is used for all
subsequent operations with the statement until you close it with
mysql_stmt_close()
, at which
point the handle becomes invalid.
The
MYSQL_STMT
structure has no members intended for application use. Applications should not try
to copy a
MYSQL_STMT
structure. There is no guarantee that such a copy will be usable.
Multiple statement handles can be associated with a single connection. The limit on the number of
handles depends on the available system resources.
•
MYSQL_BIND
This structure is used both for statement input (data values sent to the server) and output (result
values returned from the server):
• For input, use
MYSQL_BIND
structures with
mysql_stmt_bind_param()
to bind parameter data
values to buffers for use by
mysql_stmt_execute()
.
• For output, use
MYSQL_BIND
structures with
mysql_stmt_bind_result()
to bind buffers to
result set columns, for use in fetching rows with
mysql_stmt_fetch()
.
To use a
MYSQL_BIND
structure, zero its contents to initialize it, then set its members appropriately.
For example, to declare and initialize an array of three
MYSQL_BIND
structures, use this code:
MYSQL_BIND bind[3];
memset(bind, 0, sizeof(bind));
The
MYSQL_BIND
structure contains the following members for use by application programs. For
several of the members, the manner of use depends on whether the structure is used for input or
output.
•
enum enum_field_types buffer_type
The type of the buffer. This member indicates the data type of the C language variable bound
to a statement parameter or result set column. For input,
buffer_type
indicates the type
of the variable containing the value to be sent to the server. For output, it indicates the type
of the variable into which a value received from the server should be stored. For permissible
buffer_type
values, see
Section 20.6.8.1, “C API Prepared Statement Type Codes”
.
•
void *buffer
A pointer to the buffer to be used for data transfer. This is the address of a C language variable.
For input,
buffer
is a pointer to the variable in which you store the data value for a statement
parameter. When you call
mysql_stmt_execute()
, MySQL use the value stored in the variable
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...