2012-11-05 21 views
3

我在GreenDAO中遇到問題。和帶日期的聲明會返回所有內容

這是代碼:

QueryBuilder<Thing> qb = this.thingDao.queryBuilder(); 
qb.and(Properties.StartDate.lt(this.cal.getTime()), Properties.EndDate.ge(this.cal.getTime())); 
List<Thing> thingsForToday = qb.list(); 

我預計GreenDAO返回剛纔的事情,其中​​的起始日期是cal.getTime(過去),但不要在那裏結束日期由cal.getTime傳遞的東西()。我看到的是,GreenDAO只是返回任何給定日期的每個數據集(東西)。無論是在StartDate之前還是在EndDate之後。我做錯了什麼或者這是一個錯誤?

回答

3

不要使用和(),使用where()。

「和」/「或」方法旨在以不同的方式使用。引用「and」的JavaDoc:

通過使用AND組合給定條件來創建WhereCondition。 返回WhereCondition必須在Where Where(WhereCondition, WhereCondition)或WhereOr(WhereCondition,WhereCondition, WhereCondition)中使用。

+0

好的,這實際上有點令人尷尬。我只是將責任歸咎於深夜。奇蹟般有效!謝謝! :) 正確的代碼看起來是這樣的: '的QueryBuilder QB = this.thingDao.queryBuilder(); (qb.and(Properties.StartDate.lt(this.cal.getTime()),Properties.EndDate.ge(this.cal.getTime()))); List thingsForToday = qb.list();' – brejoc

+1

還有一個提示:你不需要內部的「和」,給出的「where」的條件使用AND來完成。 「和」和「或」方法用於構建涉及至少一個OR的複雜條件。 –