Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Rooms - Search in String

In the Android Rooms persistence library, how would I write the following SQL statement as a @Query?

SELECT * FROM table WHERE field LIKE %:value%

This syntax is invalid, and I can't find anything about it in the documentation.

like image 492
Roi Divon Avatar asked May 29 '17 04:05

Roi Divon


2 Answers

You can just concatenate using SQLite string concatenation.

@Query("SELECT * FROM table WHERE field LIKE '%' || :value  || '%'")
like image 158
yigit Avatar answered Nov 16 '22 17:11

yigit


The answer by yigit works great for me:

@Query("SELECT * FROM stores " +
        "WHERE name LIKE '%' || :search  || '%' " +
        "OR description LIKE '%' || :search  || '%'")
like image 29
Ufere Peace Avatar answered Nov 16 '22 18:11

Ufere Peace