首页 > 解决方案 > 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"

标签: androidkotlinandroid-roomandroidxandroid-livedata

解决方案


代替

@RawQuery(observedEntities = [Property::class])
fun searchInDatabase(query: SupportSQLiteQuery): MutableLiveData<List<Property>>

@RawQuery(observedEntities = [Property::class])
fun searchInDatabase(query: SupportSQLiteQuery): LiveData<List<Property>>

推荐阅读