【问题标题】:MySQL COM_EXECUTE_STMT fails with error but the error does not make senseMySQL COM_EXECUTE_STMT 失败并出现错误,但该错误没有意义
【发布时间】:2013-05-11 11:38:06
【问题描述】:

我正在发送 COM_EXECUTE_STMT 消息,而服务器总是返回:

错误 1048 - #23000 - 列“number_tinyint”不能为空

查询是这样的:

insert into numbers (
number_tinyint,
number_smallint,
number_mediumint,
number_int,
number_bigint,
number_decimal,
number_float,
number_double
) values
(
?, 679, 778, 875468, 100007654, 198.657809, 432.8, ?)

而我发送的是:

0: 18 00 00 00 17 01 00 00     . . . . . . . .
1: 00 00 01 00 00 00 00 00     . . . . . . . .
2: 01 01 05 0a 29 5c 8f c2     . . . . ) \ . .
3: f5 b0 58 40                 . . X @

并简化阅读:

18 00 00 - size
00 - sequence
17 - type
01 00 00 00 - statement id
00 - flags
01 00 00 00 - iteration-count
00 00 - null bitmap
01 - new params bound flag
01 - byte type
05 - double type
0a - byte value - 10
29 5c 8f c2 f5 b0 58 40 - double value

语句参数为 10(对于 tinyint 列)和 98.765(对于 double 列)。据我所知,消息编码正确,但由于某种原因总是失败 (at least from what the documentation says)

我在这里错过了什么吗?

【问题讨论】:

  • 你的空位图不应该是 1 字节长吗:(2+7)/8 = 9/8 = 1?
  • 好问题,让我试试。
  • 圣母@eggyal!就是这样!你能回答这个问题吗?

标签: mysql database networking database-connection


【解决方案1】:

来自您链接到的文档:

有效载荷: [ deletia ] n NULL 位图,长度:(num-params+7)/8

因此,在您的情况下,使用两个参数,NULL 位图的长度应为 (2+7)/8 = 1 字节,而您当前有一个 2 字节位图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多