android - RoomDatabase:找不到符号变量_result
问题描述
我正在尝试使用 @RawQuery 和 SupportSQLiteQuery 对我的 RoomDatabase 进行研究。在 PropertyDao_Impl 中构建时出现此错误:“无法定义符号变量 _result”。我已经尝试过几次 CleanProject 和 Rebuild。
你知道我做错了什么吗?提前致谢 !
import androidx.lifecycle.MutableLiveData
import androidx.room.*
import androidx.sqlite.db.SupportSQLiteQuery
import com.openclassrooms.realestatemanager.add_edit.Property
@Dao
interface PropertyDao {
@Query("SELECT * FROM Property")
fun getAllProperties(): LiveData<List<Property>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun addProperty(property: Property): Long
@Query("SELECT * FROM Property WHERE id_property = :id_property")
suspend fun getPropertyFromId(id_property: String): Property
@RawQuery(observedEntities = [Property::class])
fun searchInDatabase(query: SupportSQLiteQuery): MutableLiveData<List<Property>>
}
PropertyDao_Impl.java(生成):
@Override
public MutableLiveData<List<Property>> searchInDatabase(final SupportSQLiteQuery query) {
final SupportSQLiteQuery _internalQuery = query;
__db.assertNotSuspendingTransaction();
final Cursor _cursor = DBUtil.query(__db, _internalQuery, false, null);
try {
return _result; // error here
} finally {
_cursor.close();
}
}
}
implementation "androidx.room:room-runtime:2.2.4"
kapt "androidx.room:room-compiler:2.2.4"
解决方案
代替
@RawQuery(observedEntities = [Property::class])
fun searchInDatabase(query: SupportSQLiteQuery): MutableLiveData<List<Property>>
和
@RawQuery(observedEntities = [Property::class])
fun searchInDatabase(query: SupportSQLiteQuery): LiveData<List<Property>>
推荐阅读
- javascript - 用于 div 中 ul 元素类的 jQuery 过滤器
- regex - 正则表达式提取首字母缩略词
- python - 来自 JSON 数据的 SQLAlchemy 批量插入
- javascript - 不同页面上的javascript变量
- python - 数据框中的条件新列
- python - 使用 Gmail API 向电子邮件线程发送回复
- visual-studio-code - 有没有办法显示可用于特定语言的片段列表?
- mysql - MySQL RDS 只读副本服务未清除 binlogs
- node.js - NodeJS Sequelize 多对多选择错误(我的错误是什么?)
- postgresql - Postgresql 服务器已启动 .. 但端口(5432)没有监听