Search code examples
androidkotlinandroid-roomandroidxandroid-livedata

RoomDatabase: cannot find symbole variable _result


I'm trying to make a research on my RoomDatabase with @RawQuery and SupportSQLiteQuery. I have this error : "cannot fin symbole variable _result" when building in PropertyDao_Impl. I already try to CleanProject and Rebuild several times.

Do you have an idea of what I'm doing wrong ? Thanks in advance !

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 (generated) :

@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"

Solution

  • Replace

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

    with

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