user4790312
user4790312

Reputation:

Android use OrderBy in ORMLite

i'm trying to use chaining orderBy for this code:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).query();

i can not find good document for how to use orderBy() chain for this code befor using .query() for example this code:

GenericRawResults<String[]> raw_result =G.messagesListsDao.queryRaw("SELECT * FROM messageslist WHERE group_id = " + group_id + " ORDER BY received_date");

to:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).orderby("id",false).query();

Upvotes: 2

Views: 4304

Answers (1)

Clayton Oliveira
Clayton Oliveira

Reputation: 643

You can call orderBy() more than once, like this:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).orderBy("id",false).orderBy("received_date",false).query();

This is covered by the documentation. To quote:

Add "ORDER BY" clause to the SQL query statement to order the results by the specified column name. Use the ascending boolean to get a ascending or descending order. This can be called multiple times to group by multiple columns.

Hope it works !

Upvotes: 2

Related Questions