Hey, While testing my room queries, I found a weir...
# android-architecture
k
Hey, While testing my room queries, I found a weird behavior. In my Dao, based on those two queries:
Copy code
@Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insert(entries: List<Entry>): List<Long>
    @Update
    fun update(entries: List<Entry>)
I have created an “upsert” transaction:
Copy code
@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?