Reputation: 5
I have the following SQLite query. 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.
If I explicitly replace expireTime
with a number:
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?
Upvotes: 0
Views: 239
Reputation: 32242
strftime()
returns a string, not an integer. You need to use CAST()
to convert the type.
SELECT CAST(strftime('%s', `time`) AS integer)
FROM whois_online
WHERE CAST(strftime('%s', `time`) AS integer) > 1400005440;
Upvotes: 2