Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Room return if a query had no results

Having a difficult time finding this answer and the documentation doesn't seem to answer the question. If I have a basic ROOM query,

@Query("SELECT * FROM geotable WHERE geohash = :geohash")
abstract suspend fun getGeoTable(geohash: String) : GeoTable

and there is no such item that uses this primary key, what happens? Android studio says that the DAO object will never return a null. It seems that EmptyResultSetException only gets thrown when you have Single using RxJava which I am not using. So what does plain old ROOM throw when it finds nothing?

like image 905
chrisdottel Avatar asked Sep 13 '25 19:09

chrisdottel


2 Answers

Based on the documentation a fruitless query's behavior is defined by the declared return type:

  1. fun func(foo: Foo): Bar would throw a EmptyResultSetException
  2. fun func(foo: Foo): Bar? would return null
  3. fun func(foo: Foo): List<Bar> would return an empty list
like image 70
Lucas Kivi Avatar answered Sep 15 '25 09:09

Lucas Kivi


If nothing is found based on your criteria, it will return null.

like image 23
Asim Gasimzade Avatar answered Sep 15 '25 08:09

Asim Gasimzade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!