2016-11-29 204 views
0

我在使用自定义适配器的活动中显示一些帖子(由用户创建)。在自定义适配器的构造函数中,我使用以下代码来获取查询结果。与空值比较日期

ParseQuery query = new ParseQuery("Post"); 
query.whereWithinMiles("location_point", my_point, 500); 
query.whereGreaterThan("expire_date", new Date()); 
return query; 

目标是 - 用户可以设置一个到期日期与每个岗位,这样的职位将不再是到期后可见。我试图比较expire_date列与当前时间,以检查帖子是否过期。

query.whereGreaterThan("expire_date", new Date());稍后添加。先前创建的所有行在expire_date列中的值为NULL

所以我每次运行查询时,所有的在EXPIRE_DATE列约会对象行正在根据病情检查。在expire_date列中具有空值的行永远不会返回

注意:expire_date列不是必填字段(用户可以选择在创建帖子时将其留空)。

是的,我可以设置所有空/空字段的默认日期与过期日期进行比较。但我很想知道是否有办法让我可以返回所有具有空值的行,或者将当前时间与具有whereGreaterThan条件的空对象进行比较?

+1

你试过一个OR查询吗? http://stackoverflow.com/questions/28892973/multiple-combined-or-queries-using-android-parse – nasch

+0

谢谢队友。我使用OR查询完成了这项工作。 :) @nasch –

回答

1
ParseQuery notExpiredPosts = new ParseQuery("Post"); 
query.whereGreaterThan("expire_date", new Date()); 

ParseQuery noExpiredDate = new ParseQuery("Post"); 
query.doesNotExist("expire_date"); 

ParseQuery expiredDateQuery = ParseQuery.or(notExpiredPosts, noExpiredDate); 

ParseQuery query = new ParseQuery("Post"); 
query.whereWithinMiles("location_point", my_point, 500); 
query.whereMatchesKeyInQuery("objectId", "objectId", expiredDateQuery); 
return query; 

[(NotExpiredPost || NoExpiredDate)&(500英里范围内location_point)

这是你想要的,不是吗?

希望这会有所帮助:)

+0

我已经提出了一些你的代码的语法修改。非常感谢你的指导方针,它帮助了很多! :) –

+0

我很高兴它帮助。快乐编码:) –