当我尝试手动更新MySql表中的布尔值,然后将其实现到ruby脚本中时,我得到一个匹配但没有更改:
UPDATE calls SET ended = NOT ended WHERE incoming_Cid = '1234567890';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
除非我弄错了,否则这对我来说就像是正确的语法。
我查看了有关此问题的其他主题(翻转布尔值),例如here.
答案 0 :(得分:3)
这会有效吗?
UPDATE calls set ended = !ended WHERE incoming_Cid = '1234567890';
答案 1 :(得分:3)
您的ended
值很可能是SQL NULL
值。空值的逻辑not
仍为空,因此数据库正确报告“无更改”,因为ended
中的值未更改 - 它始于null,并且仍为null :
mysql> create table foo (x boolean);
mysql> insert into foo values (null);
Query OK, 1 row affected (0.04 sec)
mysql> update foo set x=not x;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> update foo set x=not x;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
请注意Changed: 0
。但是一旦将x重置为非空值:
mysql> update foo set x=true;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update foo set x=not x;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
行立即开始更改。