Reputation: 2325
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).
Upvotes: 1
Views: 282
Reputation: 1724
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);
}
Upvotes: 3