处理一些使用MySQL二进制协议与DB对话的代码。
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);当我用语句COM_STMT_PREPARE向服务器发送"SELECT * FROM People where sex=? or Age=?"时。我从服务器得到一个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.发布于 2015-08-29 18:28:02
通过二进制协议传递给SQL服务器的参数始终被编码为字符串。然后,SQL服务器解析字符串并在内部将它们转换为正确的类型。
https://stackoverflow.com/questions/31300414
复制相似问题