【发布时间】:2015-07-08 18:09:40
【问题描述】:
处理一些使用 MySQL 二进制协议与数据库通信的代码。
http://dev.mysql.com/doc/internals/en/client-server-protocol.html
我有一张桌子:
CREATE TABLE People ( ID INTEGER, Name VARCHAR(64), Age SMALLINT, Sex CHAR(1), Height DOUBLE);
当我使用声明 "SELECT * FROM People where sex=? or Age=?" 向服务器发送 COM_STMT_PREPARE 时。我从服务器收到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 的类型,因为它绑定到表People 中具有此类型的列Age。
参数是否总是具有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.
【问题讨论】:
标签: mysql database binary-data data-transfer