Android:带日期查询
我必须执行查询,但我对日期有问题,因为结构是 27/08/2011 这是代码:
dt="27/08/2011";
db.query(TABLE,null,mydata + "=" + dt,null,null,null,null);
问题是光标始终为 0。我认为这是数据结构,因为如果我查询其他它工作正常
I must to do a query but I have a problem with date becase the structure is 27/08/2011 this is the code :
dt="27/08/2011";
db.query(TABLE,null,mydata + "=" + dt,null,null,null,null);
the problem is that the cursor is always 0. I think that is the data structure because if I query other it work fine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的日期未加引号,因此 SQLite 会将
27/08/2011
解释为数学表达式,并将其替换为0
(整数值 27 除以 8 除以 2011 )。你可以自己引用它:或者更好,使用占位符:
切换到 ISO 8601 日期格式也是一个避免使用的好主意日期中可能存在基于区域设置的歧义:
Your date isn't quoted so SQLite will interpret
27/08/2011
as a mathematical expression and replace it with0
(the integer value of 27 divided by 8 divided by 2011). You could quote it yourself:Or better, use a placeholder:
Switching to an ISO 8601 date format would also be a good idea to avoid possible locale-based ambiguity in the date: