Android Room Persistence Library-如何查找ID列表中包含ID的实体? [英] Android Room Persistence Library - How to find entities with ids contained in list of ids?

查看:424
本文介绍了Android Room Persistence Library-如何查找ID列表中包含ID的实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的DAO中进行以下查询.

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

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

它给了我这个编译时错误:

It gives me this compile-time error:

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

List<String> idsString... idsSring[] ids均不起作用.但是,由于我不知道在编译时会有多少个id,因此,我需要一个列表/数组而不是varargs.

Both List<String> ids as well as String... ids and Sring[] ids don't work. However, since I don't know how many ids I will have in compile-time and therefore, I need a list/array and not varargs.

如何使此SQL查询正常工作?

How can I make this SQL query work?

推荐答案

您需要括号:

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

(和FWIW,我提出了问题试图在此处获得更好的错误消息)

(and FWIW, I filed an issue to try to get a better error message here)

这篇关于Android Room Persistence Library-如何查找ID列表中包含ID的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆