在房间持久库中无法使用 like 子句

Anu*_*are 1 android android-sqlite android-room android-architecture-components

我在我的项目中使用房间持久库。我试图在查询中使用“like”子句,但我无法使用。我已经尝试过编译时 (Query) 和运行时查询 (Raw Query)。它既没有给出任何异常,也没有给出任何输出。

我尝试了以下方法,但都没有奏效:-

  1. 编译时间查询 -

    @Query("select * from recipe where type_of_diet like '%vegetarian%' ")
    public abstract DataSource.Factory<Integer, RecipeListPojo> 
    getRecipeListVeg();
    
    Run Code Online (Sandbox Code Playgroud)
  2. 原始查询 -

    @RawQuery(observedEntities = RecipeListPojo.class)
    public abstract DataSource.Factory<Integer,RecipeListPojo> 
    getAllRecipesList(SupportSQLiteQuery sqLiteQuery);
    
    String query="select * from recipe  where type_of_diet like '%vegetarian%' ";
    SimpleSQLiteQuery simpleSQLiteQuery = new SimpleSQLiteQuery(query);
    recipeDao.getAllRecipesList(simpleSQLiteQuery);
    
    Run Code Online (Sandbox Code Playgroud)

compileSdkVersion 27

使用的库 - 实现 "android.arch.persistence.room:runtime:1.1.0-beta3" annotationProcessor "android.arch.persistence.room:compiler:1.1.0-beta3"

请让我知道如何运行这些类型的查询。

nor*_*DEV 5

Room 1.1.1 + RxJava2 + Kotlin 工作正常:

@Query("SELECT * FROM user WHERE name LIKE '%Tom%' ")
fun getUsers(): Single<List<UserEntity>>
Run Code Online (Sandbox Code Playgroud)

带参数:

@Query("SELECT * FROM user WHERE name LIKE '%' || :name || '%' ")
fun getUsers(name: String): Single<List<UserEntity>>
Run Code Online (Sandbox Code Playgroud)