MySQL 二进制协议准备响应

MySQL Binary Protocol Prepare Response

正在编写一些使用 MySQL 二进制协议与数据库对话的代码。

http://dev.mysql.com/doc/internals/en/client-server-protocol.html

我有一个 table:

CREATE TABLE People ( ID  INTEGER, Name VARCHAR(64), Age  SMALLINT, Sex  CHAR(1), Height DOUBLE);

当我从服务器发回 COM_STMT_PREPARE to the server with the statement "SELECT * FROM People where sex=? or Age=?". I get a COM_STMT_PREPARE_OK 时。

此包包含 2 参数和 5 列,所有这些都在 ColumnDefinition41 数据包中定义,具有以下值:

PARAMETERS:
ColumnDefinition:
    catalog:                    def
    schema:                     <empty string>
    table:                      <empty string>
    orgTable:                   <empty string>
    name:                       ?
    orgName:                    <empty string>
    lengthOfFixedField:         12
    charSet:                    63
    columnLength:               0
    type:                       253(MYSQL_TYPE_VAR_STRING)
    flags:                      128
    decimal:                    0

ColumnDefinition:
    catalog:                    def
    schema:                     <empty string>
    table:                      <empty string>
    orgTable:                   <empty string>
    name:                       ?
    orgName:                    <empty string>
    lengthOfFixedField:         12
    charSet:                    63
    columnLength:               0
    type:                       253(MYSQL_TYPE_VAR_STRING)
    flags:                      128
    decimal:                    0


Columns:
ColumnDefinition:
    catalog:                    def
    schema:                     test
    table:                      People
    orgTable:                   people
    name:                       ID
    orgName:                    ID
    lengthOfFixedField:         12
    charSet:                    63
    columnLength:               11
    type:                       3(MYSQL_TYPE_LONG)
    flags:                      0
    decimal:                    0

ColumnDefinition:
    catalog:                    def
    schema:                     test
    table:                      People
    orgTable:                   people
    name:                       Name
    orgName:                    Name
    lengthOfFixedField:         12
    charSet:                    33
    columnLength:               192
    type:                       253(MYSQL_TYPE_VAR_STRING)
    flags:                      0
    decimal:                    0

ColumnDefinition:
    catalog:                    def
    schema:                     test
    table:                      People
    orgTable:                   people
    name:                       Age
    orgName:                    Age
    lengthOfFixedField:         12
    charSet:                    63
    columnLength:               6
    type:                       2(MYSQL_TYPE_SHORT)
    flags:                      0
    decimal:                    0

ColumnDefinition:
    catalog:                    def
    schema:                     test
    table:                      People
    orgTable:                   people
    name:                       Sex
    orgName:                    Sex
    lengthOfFixedField:         12
    charSet:                    33
    columnLength:               3
    type:                       254(MYSQL_TYPE_STRING)
    flags:                      0
    decimal:                    0

ColumnDefinition:
    catalog:                    def
    schema:                     test
    table:                      People
    orgTable:                   people
    name:                       Height
    orgName:                    Height
    lengthOfFixedField:         12
    charSet:                    63
    columnLength:               22
    type:                       5(MYSQL_TYPE_DOUBLE)
    flags:                      0
    decimal:                    31

第二个参数的类型为 MYSQL_TYPE_VAR_STRING 但我期望的类型为 MYSQL_TYPE_SHORT 因为它绑定到 table 中的列 Age People 有这种类型。

参数总是有一个类型 MYSQL_TYPE_VAR_STRING 还是有什么方法可以让服务器响应我绑定的参数类型?

万一值得注意:

> mysql --help
mysql  Ver 14.14 Distrib 5.6.22, for osx10.10 (x86_64) using  EditLine wrapper
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

通过二进制协议传递给 SQL 服务器的参数始终编码为字符串。 SQL 服务器然后解析字符串并在内部将它们转换为正确的类型。