简体   繁体   中英

Doesn't the dynamically query the room database support LiveData?

I have read the artical .

Room supports @RawQuery annotation to construct queries at run-time, such as Code A.

If I use Code B, I get Error B when I complie it.

It seems that @RawQuery doesn't support to return LiveData , right?

Code A

interface DBVoiceDao{ 

   @RawQuery
   fun  runtimeQuery(sortQuery: SupportSQLiteQuery): List<MVoice>
    ...
}

Code B

interface DBVoiceDao{ 

   @RawQuery
   fun  runtimeQuery(sortQuery: SupportSQLiteQuery): LiveData<List<MVoice>>
    ...
}

Error B

Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide `room.schemaLocation` annotation processor argument OR set exportSchema to false.
public abstract class DBVoiceDatabase extends androidx.room.RoomDatabase {
                ^[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).                                    

it does support it, but you have to specify the observed entity, as described here https://developer.android.com/reference/androidx/room/RawQuery example:

@Dao
 interface RawDao {
   @RawQuery(observedEntities = Song.class)
   LiveData<List<Song>> getSongs(SupportSQLiteQuery query);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM