I am inserting rows into Room database and I want to check if the row is inserted successfully.
This is my Dao
@Insert()
suspend fun insertOfflineData(offlineData: OfflineData): Long
@Entity
data class OfflineData(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
@ColumnInfo(name = "request_info_json")
val requestInfoJson: String
)
When I insert a row the response is 1,2,3 and so on..
So it is the id
that it is returning (is that right?)
So to check if the row is inserted correctly.
Can I just check that the inserted rowId is greater that 0 then it is successfully inserted into the DB.
private suspend fun insertOfflineData(offlineDataRequestInfo: String): Long {
var result: Long = 0
result = OfflineDatabaseManager.getInstance(app.applicationContext).insertOfflineData(
OfflineData(
0,
offlineDataRequestInfo
))
if(result > 0 ) {
//SUCCEFFLULLY INSERTED
} else {
//UNSUCCESSFULL
}
return result
}
Note: result I am getting is 1,2,3 etc which should be the rowId.
Please suggest if this approach is right? Basically if the insert is not successful I want to stop the user from proceeding further
Thank you for your suggestions and input R