title: How to dynamically query the room database at runtime?
body: <h1>The problem</h1>
  
  <p>Is it possible construct a query at runtime?</p>
  
  <p><br/></p>
  
  <h1>Use case</h1>
  
  <pre><code>@Query("SELECT * FROM playlist " +
          "WHERE playlist_title LIKE '% :playlistTitle %' " +
          "GROUP BY playlist_title " +
          "ORDER BY playlist_title " +
          "LIMIT :limit")
   List&lt;IPlaylist&gt; searchPlaylists(String playlistTitle, int limit);
  </code></pre>
  
  <p>The <code>limit</code> part is optional. That is, it should be able to perform the same query with or without limit.</p>
  
  <p><br/></p>
  
  <h1>A more complicated use case</h1>
  
  <p>In the previous case, it is possible to make two static queries with and without limit part and appropriate one can be used each time. But sometimes we may have to deal with more complex situations like building a filter.</p>
  
  <p>In that case, unlike the previous example, there will be multiple number of optional parts. For a table of books, we may need to do filtering according to the category the book belongs to, author name, price range, publication date etc. It is almost impossible to make static queries with all combinations of these parts.</p>