首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL二进制协议准备响应

MySQL二进制协议准备响应
EN

Stack Overflow用户
提问于 2015-07-08 18:09:40
回答 1查看 433关注 0票数 0

处理一些使用MySQL二进制协议与DB对话的代码。

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

我有张桌子:

代码语言:javascript
复制
CREATE TABLE People ( ID  INTEGER, Name VARCHAR(64), Age  SMALLINT, Sex  CHAR(1), Height DOUBLE);

当我用语句COM_STMT_PREPARE向服务器发送"SELECT * FROM People where sex=? or Age=?"时。我从服务器得到一个COM_STMT_PREPARE_OK

此包包含2参数和5列,它们都定义在具有以下值的ColumnDefinition41数据包中:

代码语言:javascript
复制
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,因为它绑定到具有这种类型的表People中的列Age

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

如果值得注意的话:

代码语言:javascript
复制
> 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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-29 18:28:02

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31300414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档