문제

According to MySQL 5.5 documentation, the valid syntax for an UPDATE is the following:

UPDATE [LOW_PRIORITY] [IGNORE] table_references
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]

In our code we found this request:

UPDATE eMail SET Actif = 0 AND FKClient = 122;

The table is Innodb on a MySQL 5.5 and Actif is tinyint(1) nullable.

As far as I know this syntax is invalid and should not execute since the AND comparison is not permitted in a SET statement.

If you execute the code, all eMail rows will be set to Actif = 0.

Why does my UPDATE request work?

도움이 되었습니까?

해결책

Sure it is. It's parsed as:

UPDATE eMAIL SET Active = (0 AND FKCLient = 122)

FKClient= 122 will be a boolean comparison, returning true/false, so it becomes

UPDATE eMAIL SET Active = (0 AND bool)

0 AND anything is 0, so..

... SET Active = 0
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top