首页 > 解决方案 > 在放入数据之前尝试删除时没有此类表

问题描述

在实际放入数据之前尝试从表中删除时,我遇到了SQLiteException - no such table问题。我正在使用房间。

我的猜测是只有在插入第一个数据后才会创建该表。但是,我有一个操作需要用每个请求替换数据库中的数据:

 override fun refreshList(filter: ApplyFilterRequest, page: Int, pageSize: Int, replace: Boolean): Single<FilterResponse> {

        var pagedResponseData: ResponseData = ResponseData.list(page, pageSize)
        var pagedFilter = filter.copy(responseData = pagedResponseData)

        return from(placesApi.applyFilter(pagedFilter))
                .doOnSuccess {

                    var list = it.list?.places
                    appDatabase.beginTransaction()
                    list?.let {
                        var listResult = list.map { ListResult(it.placeId) }
                        if(replace) {
                            listResultDao.replace(listResult)//We save each place on the database to be able to reference it by experienceId
                        }
                        else{
                            listResultDao.saveResults(listResult)
                        }
                        placesDao.savePlaces(it)
                    }
                    appDatabase.setTransactionSuccessful();
                    appDatabase.endTransaction()
                }
                .doOnError {
                    appDatabase.endTransaction()
                }
    }

和替换操作:

 @Transaction
    open fun replace(ids: List<ListResult>) {
        deleteAll()
        saveResults(ids)
    }
@Query("DELETE from list_results")
abstract fun deleteAll()

这会引发以下错误:

Handling Error android.database.sqlite.SQLiteException: no such table: room_table_modification_log (code 1): , while compiling: DELETE from list_results
        #################################################################
        Error Code : 1 (SQLITE_ERROR)
        Caused By : SQL(query) error or missing database.
            (no such table: room_table_modification_log (code 1): , while compiling: DELETE from list_results)
        ################################################################# with text We couldn't get your places. Please try again.
        android.database.sqlite.SQLiteException: no such table: room_table_modification_log (code 1): , while compiling: DELETE from list_results
        #################################################################
        Error Code : 1 (SQLITE_ERROR)
        Caused By : SQL(query) error or missing database.
            (no such table: room_table_modification_log (code 1): , while compiling: DELETE from list_results)

如果数据已经到位,那么我不会出错。

标签: androidandroid-room

解决方案


该问题的解决方案是将您的房间版本更新为高于 1.1.0 的版本,因为此版本中有一个已知错误,您可以使用 1.1.1 或更高版本。这是错误https://issuetracker.google.com/issues/79362399


推荐阅读