Search code examples
androidsqlitegreendao

greenDAO: compare two properties with each other


I am sure this should be simple but I can't seem to find a solution.

Say I have a table with 5 fields (id, colour, size, scanned, expected)

how do I get all the rows where the expected is greater than then scanned?

I have tried

mydao.Property.Expected.gt(mydao.Property.Scanned).list()

but this returns 0 rows. Using the LOG_SQL boolean I can see that it is looking for a property field, not the value of the field.

D/greenDAO: Values for query: [0, de.greenrobot.dao.Property@33ecce97]

Solution

  • greenDAO's QueryBuilder API does not support that (yet). You have to use a raw query.

    It will look something like this:

    Query myQuery = myDao.queryBuilder().where(new StringCondition(
        Property.Expected.columnName + " > " + Property.Scanned.columnName)).build();
    

    PS.: I also created a feature request if you want to track this for future greenDAO version.