krzysztof
02/11/2021, 9:53 AM@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insert(entries: List<Entry>): List<Long>
@Update
fun update(entries: List<Entry>)
I have created an “upsert” transaction:
@Transaction
fun setValues(entries: List<Entry>) {
val insertResult = insert(entries)
val entriesToUpdate = entries.filterIndexed { i, _ -> insertResult[i] == -1L }
if(entriesToUpdate.isNotEmpty()) {
update(entriesToUpdate)
}
}
So this works great on real device - value is property inserted if not existing, and updated if existed. No issue here.
The problem begins where I test this upsert with in-memory database - “inserting” the same Entry, with different value (primary key stays the same) always returns positive row id, instead of expected -1. Did anyone see similar issue?