Search code examples
androidkotlinandroid-roomkotlin-coroutines

Using a result class with database operations


Recently I came across a project where a function to add a row into a Room database was wrapped in a Result class. I want to know if this is really necessary and why. When would a database insert method for some unknown reason fail at run time.


Solution

  • When would a database insert method for some unknown reason at run time.

    Never.

    However, the un-weary could be fooled by a Trigger.

    Of course it could simply be that the result of the insert is being collected. That is that the Convenience @Insert will return the rowid of the inserted row or -1 if the row could not be inserted (depends upon the conflict handling strategy).