GreenDAO groupby offer

I am currently using greenDAO as an ORM for my Android app. I encountered a problem while trying to execute a GROUPBY clause. GreenDAO has no API / helper methods to execute groupby clauses, so I decided to use the query() or queryRaw() methods available for the AbstractDAO class, where I can pass a valid SQL query. BUT, both of these methods return java.util.List, so what confuses me is that how can I get the column alias values ​​as a result? For instance,

 SELECT COUNT(ID) AS NUMOFRECORDS, NAME FROM PERSONS GROUP BY AGE 

My object will have the NAME and AGE fields, but I created an alias for the NUMOFRECORDS column, which is not part of Entity.

Appreciate your help!

+6
source share
2 answers

This is an alternative solution for your question: Turn on the ORDER BY Where option.

Example:

List<Taxi> list = daoSession.getDaoTaxi().queryBuilder().where(new WhereCondition.StringCondition("1 GROUP BY cant_aciento")).list();

+5
source

I ran into a similar problem. It seems that greenDao does not support GROUP BY queries, and that will not change in the future, according to what they said here :

GROUP BY is SQL-ish, so stick with SQL. greenDAO are objects where GROUP BY is not supported.

+1
source

Source: https://habr.com/ru/post/980876/


All Articles