How to create a GreenDao query that loads all the elements specified in the list of identifiers?

I have a list of strings, each of which is the only identifier of an element that is stored through GreenDao.

How to create a query that allows me to load all of these items from my database?

Is there any way to do this with QueryBuilder or do I need to get back to writing SQL?

+6
source share
2 answers

This is possible with the in clause in the Property class.

This example loads all fields with field values ​​contained in fieldValues . fieldValues is of type List<String>

  List<LocalBox> boxes = getBoxDao(context).queryBuilder() .where(LocalBoxDao.Properties.field.in(fieldValues)).list(); 
+6
source

I would like to add some light to the "request",
There is a limitation in this, we cannot pass more than 100 identifiers inside the request
So what I did to achieve this goal:

 List<Product> productList = new ArrayList<Product>(); DaoSession daoSessionUni = TarneaAndroidApplicationContext.getInstance().getDaoSession(); for (int i = 0; i < rowIds.size(); i = i + 100) { ProductDao productDao = daoSessionUni.getProductDao(); QueryBuilder<Product> queryBuilder = productDao.queryBuilder().where( ProductDao.Properties.Id.in(rowIds.subList(i + 100 < rowIds.size() ? i + 100 : rowIds.size())), ProductDao.Properties.IsDeleted.eq(0)); productList.addAll(queryBuilder.list()); } 

if we want to pass a list of identifiers used in Query, we can use this method.

+2
source

All Articles