Android Rooms - Search in String

大兔子大兔子 提交于 2019-12-12 15:42:34

问题


In Android Rooms persistence library, how would I write the following SQL statement:
SELECT * FROM table WHERE field LIKE %:value%
As a @Query?
This syntax is invalid, and I can't find anything about it in the docs.


回答1:


You can just concat using SQLite string concatenation.

@Query("SELECT * FROM table WHERE field LIKE '%' || :value  || '%'")



回答2:


Annswer by @yigit works great for me:

@Query("SELECT * FROM stores " +
        "WHERE name LIKE '%' || :search  || '%' " +
        "OR description LIKE '%' || :search  || '%'")


来源:https://stackoverflow.com/questions/44234644/android-rooms-search-in-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!