this function below
in goes the dictWord if it exists it increases the amount property by one updates in the db and returns out of the uiscope - out of the function and when the getDictWord return a null it goes to creation a newDictWord and adds that into the db and leaves the coroutine scope and then the function no?
because i do get " android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: DictWord.name (code 1555 SQLITE_CONSTRAINT_PRIMARYKEY)" from time to time from that
fun addOrIncreaseDictWordAmount(dictWord: String) {
uiScope.launch {
userDatabaseDao.getDictWord(dictWord)?.let {
it.amount += 1
userDatabaseDao.updateDictWord(it)
return@launch
}
// adds the strain to the AddNew dropDown list
val newDictWord = DictWord(name = dictWord)
userDatabaseDao.insertDictWord(newDictWord)
}