Roi Divon
Roi Divon

Reputation: 1147

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.

Upvotes: 9

Views: 5701

Answers (2)

yigit
yigit

Reputation: 38253

You can just concatenate using SQLite string concatenation.

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

Upvotes: 34

Ufere Peace
Ufere Peace

Reputation: 79

The answer by yigit works great for me:

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

Upvotes: 4

Related Questions