Search code examples
androidandroid-sqliteandroid-room

Get Result From Room Update Query


How can I get a result of when my data has been updated successfully in my Room database.

My Query Sample:

@Query("UPDATE Cohort SET isSelectedCTypeCoh = 'false'")
fun clearAllSelectedHoldingTypeDB()

Solution

  • You can modify your update function to return an int indicating the number of rows updated in the database.

    Kotlin:

    @Update
    fun updateUser(user: User):Int
    

    Java:

    @Update
    public int updateUser(User user);