문제

I'm having trouble with a query in GreenDAO.

This is the code:

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();

I expected GreenDAO to return just the things where the StartDate is in the past of cal.getTime() but not the things where the EndDate is passed by cal.getTime(). What I've seen is that GreenDAO just returns every data set (thing) for any given date. No matter if it is before the StartDate or after the EndDate. Am I doing something wrong or is this a bug?

도움이 되었습니까?

해결책

Don't use and(), use where().

The "and"/"or" methods are meant to be used a different way. To quote the JavaDoc of "and":

Creates a WhereCondition by combining the given conditions using AND. The returned WhereCondition must be used inside where(WhereCondition, WhereCondition) or whereOr(WhereCondition, WhereCondition, WhereCondition).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top