[英]SQLite greater/less than operator giving false results
I have the following SQLite query. 我有以下SQLite查询。 It is intended to delete all entries where the time has not been updated in the past three seconds.
它旨在删除过去三秒内未更新时间的所有条目。
$expireTime = time() - 3;
$dbh->query("DELETE FROM `whois_online` WHERE (strftime('%s', `time`) > $expireTime)");
This query does not return any entries in the table, even though it should. 此查询不会返回表中的任何条目,即使它应该。 However, changing the
>
to <
causes the entires to appear, even though the numbers it is comparing should not let this happen. 但是,将
>
更改为<
会导致entires出现,即使它所比较的数字不应该让这种情况发生。
If I explicitly replace expireTime
with a number: 如果我用数字明确替换
expireTime
:
sqlite> SELECT strftime('%s', `time`) from whois_online WHERE (strftime('%s', `time`) > 1400005440);
I get the following result: 我得到以下结果:
1400005363
1400005365
1400005368
1400005443
This is clearly not logically correct, as all these numbers are less than 1400005440. What is going on here? 这显然不是逻辑上正确的,因为所有这些数字都小于1400005440.这里发生了什么?
strftime()
returns a string , not an integer. strftime()
返回一个字符串 ,而不是整数。 You need to use CAST()
to convert the type. 您需要使用
CAST()
来转换类型。
SELECT CAST(strftime('%s', `time`) AS integer)
FROM whois_online
WHERE CAST(strftime('%s', `time`) AS integer) > 1400005440;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.