C API Prepared Statement Function Overview
2197
MySQL converts the
MEDIUMINT
value (which requires less than 8 bytes) for storage into the
long
long int
(an 8-byte variable).
• If you fetch a numeric column with a value of 255 into a
char[4]
character array and specify a
buffer_type
value of
MYSQL_TYPE_STRING
, the resulting value in the array is a 4-byte string
'255\0'
.
• MySQL returns
DECIMAL
values as the string representation of the original server-side value,
which is why the corresponding C type is
char[]
. For example,
12.345
is returned to the client as
'12.345'
. If you specify
MYSQL_TYPE_NEWDECIMAL
and bind a string buffer to the
MYSQL_BIND
structure,
mysql_stmt_fetch()
stores the value in the buffer as a string without conversion. If
instead you specify a numeric variable and type code,
mysql_stmt_fetch()
converts the string-
format
DECIMAL
value to numeric form.
• For the
MYSQL_TYPE_BIT
type code,
BIT
values are returned into a string buffer, which is why the
corresponding C type is
char[]
. The value represents a bit string that requires interpretation on the
client side. To return the value as a type that is easier to deal with, you can cause the value to be
cast to integer using either of the following types of expressions:
SELECT b 0 FROM t
SELECT CAST(bit_col AS UNSIGNED) FROM t
To retrieve the value, bind an integer variable large enough to hold the value and specify the
appropriate corresponding integer type code.
Before binding variables to the
MYSQL_BIND
structures that are to be used for fetching column
values, you can check the type codes for each column of the result set. This might be desirable if you
want to determine which variable types would be best to use to avoid type conversions. To get the
type codes, call
mysql_stmt_result_metadata()
after executing the prepared statement with
mysql_stmt_execute()
. The metadata provides access to the type codes for the result set as
described in
Section 20.6.10.22, “
mysql_stmt_result_metadata()
”
, and
Section 20.6.4, “C API
Data Structures”
.
To determine whether output string values in a result set returned from the server contain binary
or nonbinary data, check whether the
charsetnr
value of the result set metadata is 63 (see
Section 20.6.4, “C API Data Structures”
). If so, the character set is
binary
, which indicates binary
rather than nonbinary data. This enables you to distinguish
BINARY
from
CHAR
,
VARBINARY
from
VARCHAR
, and the
BLOB
types from the
TEXT
types.
If you cause the
max_length
member of the
MYSQL_FIELD
column metadata structures to be set
(by calling
mysql_stmt_attr_set()
), be aware that the
max_length
values for the result set
indicate the lengths of the longest string representation of the result values, not the lengths of the
binary representation. That is,
max_length
does not necessarily correspond to the size of the buffers
needed to fetch the values with the binary protocol used for prepared statements. Choose the size
of the buffers according to the types of the variables into which you fetch the values. For example,
a
TINYINT
column containing the value -128 might have a
max_length
value of 4. But the binary
representation of any
TINYINT
value requires only 1 byte for storage, so you can supply a
signed
char
variable in which to store the value and set
is_unsigned
to indicate that values are signed.
20.6.9. C API Prepared Statement Function Overview
The functions available for prepared statement processing are summarized here and described
in greater detail in a later section. See
Section 20.6.10, “C API Prepared Statement Function
Descriptions”
.
Function
Description
mysql_stmt_affected_rows()
Returns the number of rows changed, deleted, or inserted by
prepared
UPDATE
,
DELETE
, or
INSERT
statement
mysql_stmt_attr_get()
Gets value of an attribute for a prepared statement
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 ...