MySql 语句中的奇怪 'where 1970 and' 子句
Strange 'where 1970 and' clause in MySql statement
我正在审查一些旧的 PHP 代码,其中 MySql 语句是硬编码的。我发现了一个带有奇怪 where
子句的语句:
SELECT ...
FROM ...
WHERE 1970
AND Sale_Price.Server__ = `Server`.Server__
...
where
子句中这个 1970
数字的用途是什么?我以前从未见过这个。有特定目的吗?
它对我来说似乎是无害的 typo/bug,我可以删除它。你同意吗?
更新
这里是关于连接的更多信息:
SELECT ...
FROM `Server`, Product_Ref
LEFT JOIN Sale_Price ON Product_Ref.Product_Ref__ = Sale_Price.Product_Ref__
LEFT JOIN Purchase_Price ON Product_Ref.Product_Ref__ = Purchase_Price.Product_Ref__
LEFT JOIN Product_Category ON Product_Ref.Product__ = Product_Category.Product__
WHERE 1970
AND Sale_Price.Server__ = `Server`.Server__
AND Sale_Price.Date_Enter < NOW()
AND Sale_Price.Server__ IN ($this->salesServerIds)
正如我们在评论中讨论的那样,有几种可能性:
一个隐藏真实条件:
... WHERE 1 = 1;
... WHERE 1;
... WHERE 1970;
-- All numbers except 0 evaluate to TRUE and will return all entries.
第二个选项是错误。如果你有版本控制(git,svn,cvs),你可以检查它是什么时候添加的,以及我怀疑是拼写错误还是复制粘贴错误。拥有它的效果是您将获得所有结果;例如,您甚至会得到 Sale_Price.Date_Enter 将来的条目。
我正在审查一些旧的 PHP 代码,其中 MySql 语句是硬编码的。我发现了一个带有奇怪 where
子句的语句:
SELECT ...
FROM ...
WHERE 1970
AND Sale_Price.Server__ = `Server`.Server__
...
where
子句中这个 1970
数字的用途是什么?我以前从未见过这个。有特定目的吗?
它对我来说似乎是无害的 typo/bug,我可以删除它。你同意吗?
更新
这里是关于连接的更多信息:
SELECT ...
FROM `Server`, Product_Ref
LEFT JOIN Sale_Price ON Product_Ref.Product_Ref__ = Sale_Price.Product_Ref__
LEFT JOIN Purchase_Price ON Product_Ref.Product_Ref__ = Purchase_Price.Product_Ref__
LEFT JOIN Product_Category ON Product_Ref.Product__ = Product_Category.Product__
WHERE 1970
AND Sale_Price.Server__ = `Server`.Server__
AND Sale_Price.Date_Enter < NOW()
AND Sale_Price.Server__ IN ($this->salesServerIds)
正如我们在评论中讨论的那样,有几种可能性:
一个隐藏真实条件:
... WHERE 1 = 1;
... WHERE 1;
... WHERE 1970;
-- All numbers except 0 evaluate to TRUE and will return all entries.
第二个选项是错误。如果你有版本控制(git,svn,cvs),你可以检查它是什么时候添加的,以及我怀疑是拼写错误还是复制粘贴错误。拥有它的效果是您将获得所有结果;例如,您甚至会得到 Sale_Price.Date_Enter 将来的条目。