Frage

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?

War es hilfreich?

Lösung

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).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top