从我的创建表脚本中,我将 hasMultipleColors 字段定义为 BIT 类型:
hasMultipleColors BIT NOT NULL,
当运行INSERT语句时,对于这些BIT字段不会抛出任何警告,但选择这些行后发现所有BIT值都为空。手动尝试从命令行更新这些记录会产生奇怪的效果-显示记录被匹配并更改(如果适用),但仍然始终为空。
服务器版本: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
呢?从你字段名称的语义来看,使用BOOL
更合理。 - Romain