How to dynamically query the room database at runtime?

后端 未结 8 1838
青春惊慌失措
青春惊慌失措 2020-11-30 05:42

The problem

Is it possible construct a query at runtime?


Use case

@Query(\"SELECT * FROM playlist \" +
        \"WHERE play         


        
8条回答
  •  迷失自我
    2020-11-30 06:21

      @Query("select * from task where state = :states and sentdate between :fromdate and :todate")
      List getFilterAll(String states, String fromdate, String todate);
    

    Here we need to use column name state. Whenever need to achieve custom query just pass the value through the parameter from the activity or fragement will get in to the interface we will apply inside the query. like example in the above code (:fromdate, :todate)

    Colon is must. Which parameter you will going to use inside the query we will mention before start with : symbol.

提交回复
热议问题