79359667

Date: 2025-01-15 20:58:04
Score: 1
Natty:
Report link

The problem is that update is always called, but the database is empty at that moment and nothing happens:

val existingId = saveStateRepo.getSavedId(cardId) 

if (existingId == null) {
    saveStateRepo.saveState(newSave)
    Log.d(TAG, "ID was not yet included, included it now")
} else {
    saveStateRepo.updateState(newSave)
    Log.d(TAG, "ID was already included, updated it now")
}

A function is called to retrieve existingId:

@Query("SELECT * FROM saveStateDex WHERE cardID = :id LIMIT 1")
fun getSavedId(id: Int): Flow<SaveStateDex>?

It is necessary to change to the correct type SaveStateDex? or use @Insert(onConflict = OnConflictStrategy.REPLACE), then there is no need for such a function getSavedId() and @Update.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @Update
  • Low reputation (0.5):
Posted by: dmortal