android - 在放入数据之前尝试删除时没有此类表
问题描述
在实际放入数据之前尝试从表中删除时,我遇到了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)
如果数据已经到位,那么我不会出错。
解决方案
该问题的解决方案是将您的房间版本更新为高于 1.1.0 的版本,因为此版本中有一个已知错误,您可以使用 1.1.1 或更高版本。这是错误https://issuetracker.google.com/issues/79362399
推荐阅读
- android - GoogleClientApiConnected 异常从何而来?
- expression - 如何获取 Pyomo 命名表达式的 sulution 值?
- azure-devops - 如何在 Azure DevOps Server 中找到许可证信息?
- angular - 有没有办法让 2 个带有角度组件的 html 模板?
- javascript - 从 Firestore 中删除文档不一致
- mongodb - 是否可以通过 gradle (Kotlin-DSL) 为 Kotlin MongoDB 文档生成 Q 类?
- javascript - 反应 DatePicker 切换问题
- python - 使用 if 语句搜索嵌套列表
- java - Gmail API Java 实现错误(未找到凭据)
- apache-kafka - Kafka DSL KStream 转换器之间的 Kafka 共享状态存储