9

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Roi Divon
  • 1,147
  • 1
  • 11
  • 16

2 Answers2

34

You can just concatenate using SQLite string concatenation.

@Query("SELECT * FROM table WHERE field LIKE '%' || :value  || '%'")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yigit
  • 37,683
  • 13
  • 72
  • 58
4

The answer by yigit works great for me:

@Query("SELECT * FROM stores " +
        "WHERE name LIKE '%' || :search  || '%' " +
        "OR description LIKE '%' || :search  || '%'")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131