Velliane
Velliane

Reputation: 89

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"

Upvotes: 0

Views: 491

Answers (2)

Akhha8
Akhha8

Reputation: 490

For short, if you are using Jetpack Paging library v3.0.0+, you have to update your version of Room too, v2.3.0-rc01 worked for me.

Long answer. This happened to me when I was trying to use Paging librar v3.0.0-beta03 & Room v2.2.6.

RoomEntityDAO

@RawQuery(observedEntities = [RoomEntity::class])
fun getOrdersDataSource(query: SupportSQLiteQuery): DataSource.Factory<Int, RoomEntity>

Generates in RoomEntityDAO_Impl

@Override
  public PagingSource<Integer, RoomEntity> getOrdersDataSource(
      final SupportSQLiteQuery query) {
    final SupportSQLiteQuery _internalQuery = query;
    __db.assertNotSuspendingTransaction();
    final Cursor _cursor = DBUtil.query(__db, _internalQuery, false, null);
    try {
      return _result;
    } finally {
      _cursor.close();
    }
  }

This question have already an accepted answer, but it might help some else having the same issue.

Upvotes: 0

EpicPandaForce
EpicPandaForce

Reputation: 81539

Replace

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

with

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

Upvotes: 1

Related Questions