Android Persistence Library - How to find objects with identifiers contained in the list of identifiers?

I am trying to execute the following query in my DAO.

   @Query("SELECT * FROM objects WHERE obj_id IN :ids")
   List<Object> queryObjects(List<String> ids);

This gives me a compile time error:

Error: no viable alternative at input 'SELECT * FROM objects WHERE obj_id IN :ids'

Both List<String> ids, as well String... ids, and Sring[] idsdo not work. However, since I do not know how many identifiers I will have at compile time, and therefore I need a list / array, not varargs.

How can I make this SQL query work?

+6
source share
2 answers

You need brackets:

@Query("SELECT * FROM objects WHERE obj_id IN (:ids)")
List<Object> queryObjects(List<String> ids);

(and FWIW, I filed a problem to try and get the best error message here)

+20
source

You can set either an input list or an input array.

,

, String [] List ID

Query = @Query (" * , obj_id (: ids)")

+1

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


All Articles