How can get top of records by GreenDAO?
Asked Answered
A

2

8

I wanna to get top some records from my table, but GreenDAO doesn't provide it. Like this:

SELECT TOP 1 * FROM table_name

In LINQ you can get top of records with Take(), is there any solution for GreenDAO?

Could every one offer a suggestion?

Anxiety answered 20/10, 2012 at 5:48 Comment(0)
R
17

You can specify a limit using standard QueryBuilder:

List<YourEntity> entities = yourDao.queryBuilder().limit(1).list();
Runstadler answered 21/10, 2012 at 8:59 Comment(6)
Unfortunately When I run it, doesn't work and show error. please write a complete example(when I want to get a row from a table)Anxiety
Thanks @greenrobot, you was right. I did test it and it worked correctly.Anxiety
sorry for found it too late, please expain what is "limit(1)" , many thanksWarrantable
limit(n) - select top n records from tablePreponderance
@Preponderance top n records mean, first added or last added?Wavelength
@Mani depends on order clausePreponderance
A
0
 var mcc: SearchDao
      
 val list: List<Search?> =mcc.queryBuilder().orderDesc(SearchDao.Properties.Time).limit(8).list()
Accusal answered 16/10, 2020 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.