**已关闭。**此问题需要debugging details。它目前不接受回答。
编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
13天前关闭
Improve this question的
我使用的是Mariadb C API。我可以有一个用空值绑定列数据的示例吗?
我一直在效仿这个例子:https://mariadb.com/kb/en/bulk-insert-column-wise-binding/的
下面的代码是我所拥有的代码的一部分:
double test_data[1] = {1,NULL,2};
my_bool *isNull = new my_bool[3];
isNull[0] = '0';
isNull[1] = '1';
isNull[2] = '0';
MYSQL_BIND *bind = new MYSQL_BIND;
bind.buffer_type = MYSQL_TYPE_DOUBLE;
bind.buffer = &test_data;
bind.is_null = isNull;
mysql_stmt_attr_set(insertStmt, STMT_ATTR_ARRAY_SIZE,&numRows);
mysql_stmt_bind_param(insertStmt,bind);
mysql_stmt_execute(insertStmt);
字符串
但它不会将test_data中的NULL值绑定为null,而是返回0。
这是用C++编译的。
1条答案
按热度按时间fdx2calv1#
is_null
绑定参数仅在逐行执行语句时有效。当在MariaDB二进制协议中添加批处理操作时,我们注意到缺少了几件事:例如支持默认值、忽略值。因此,我们没有向bind结构添加额外的成员,而是添加了一个包含指示符的联合。除了你的数据数组,你还需要一个指标数组:
字符串
除了STMT_INDICATOR_NULL之外,还支持以下指示符:
您可以在Connector/C unittests中找到一些批处理执行的示例。
关于你的代码的一些评论:
test_data[1]
不能存储3个不同的值bind->member
而不是bind.member
赋值