0

I have an Android app that uses Room. I have the following query:

@Query("SELECT * FROM model WHERE (:someInt is null)")
List<Model> myQuery(Integer someInt);

However, when I call it with a null value, it returns an empty List. The following test fails.

    List<Model> models = myDao.myQuery(null);
    assertFalse(models.isEmpty());

In the other hand when I try it using the following query it returns items.

@Query("SELECT * FROM model WHERE (:someInt is not null)")

Is there something that I'm missing?

I'm using Room 2.2.5.

Thanks,

Mateu
  • 2,636
  • 6
  • 36
  • 54
  • You probably would need direct access to the prepared statement API here, and I'm not sure if SQLite prepared statements would even support this. – Tim Biegeleisen Apr 15 '20 at 16:30
  • @TimBiegeleisen I've seen some posts where this seems possible: https://stackoverflow.com/questions/52079052/room-could-i-check-passing-value-to-query-for-null and https://stackoverflow.com/questions/52029435/optional-query-parameters-for-android-room – Mateu Apr 15 '20 at 16:48

0 Answers0