从我创建表的脚本,我已经定义了hasMultipleColors字段作为BIT:的MySQL总是返回位值作为空白
hasMultipleColors BIT NOT NULL,
当运行一个INSERT,没有抛出这个或警告的其他BIT字段,但选择行显示所有BIT值都是空白的。
手动尝试从命令行更新这些记录会产生奇怪的效果 - 显示记录匹配并已更改(如果适用),但始终显示空白。
Server版本:5.5.24-0ubuntu0.12.04.1(Ubuntu的)
mysql> update pumps set hasMultipleColors = 1 where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> select hasMultipleColors from pumps where id = 1;
+-------------------+
| hasMultipleColors |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
mysql> update pumps set hasMultipleColors = b'0' where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select hasMultipleColors from pumps where id = 1;
+-------------------+
| hasMultipleColors |
+-------------------+
| |
+-------------------+
1 row in set (0.00 sec)
有什么想法?
为什么你不使用'BOOL'而不是'BIT'?从你的字段名称的语义,它会更有意义。 – Romain 2012-07-23 09:11:48
对BOOL与BIT与TINYINT数据类型有一些了解,而我采取的外带手段是MySQL以非常差的方式处理BOOL - 不能移植到其他RDBMS解决方案 - 所以它通常适用于TINYINT或BIT(更高效)。 – CdrXndr 2012-07-24 04:33:45