为什么会这样?
SELECT strftime('%s', timestamp,'localtime') from locationLog WHERE strftime('%s', timestamp,'localtime') > 999999999999999999 ORDER BY _id DESC当我的所有行在"timestamp“中都有一个较低的值时,返回任何输出
在我的例子中,上面的查询返回
1334735588
1334735349
1334734317
1334734178
1334734172
and so on...它返回我的整个表。
如果我将>切换到<,它将不返回任何内容。
我想我正在尝试比较不同类型的变量或类似的东西。
发布于 2012-04-30 21:53:07
您正在将SQLite值与integer值进行比较,因此SQLite会将integer值转换为text,并执行字符串比较:
sqlite> select strftime('%s', '2002-02-02', 'localtime');
1012611600
sqlite> select typeof(strftime('%s', '2002-02-02', 'localtime'));
text
sqlite> select typeof(999999999999999999);
integer
sqlite> select strftime('%s', '2002-02-02', 'localtime') > 999999999999999999;
1
sqlite> select cast(strftime('%s', '2002-02-02', 'localtime') as integer) > 999999999999999999;
0如上所示,解决方案是将strftime的返回值转换为某种数值类型。
发布于 2012-04-30 18:38:27
据猜测,您使用的是32位平台,并且使用了一个大于2147483647的整数,这导致您在"Year 2038 Problem"上遇到了一个变体。
尝试使用2147483647作为您在查询中进行比较的数字。
这将继续工作到2038年,届时您可能会在64位平台上托管您的应用程序(或者到那时甚至可能是128位或256位!)
https://stackoverflow.com/questions/10381842
复制相似问题