简体   繁体   English

动态查询房间数据库不支持LiveData吗?

[英]Doesn't the dynamically query the room database support LiveData?

I have read the artical .我已阅读ARTICAL

Room supports @RawQuery annotation to construct queries at run-time, such as Code A. Room 支持@RawQuery注解在运行时构造查询,例如 Code A。

If I use Code B, I get Error B when I complie it.如果我使用代码 B,当我编译它时我会得到错误 B。

It seems that @RawQuery doesn't support to return LiveData , right? @RawQuery似乎不支持返回LiveData ,对吗?

Code A代码 A

interface DBVoiceDao{ 

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

Code B代码 B

interface DBVoiceDao{ 

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

Error B错误 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:它确实支持它,但您必须指定观察到的实体,如下所述https://developer.android.com/reference/androidx/room/RawQuery示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 房间数据库查询后 LiveData 不更新观察者 - LiveData not updating observer after Room database query Android 不使用 Flow 或 LiveData 的房间数据库查询(无观察) - Android Room Database Query without using Flow or LiveData (no observing) 如何使用 android 中的房间数据库更改 LiveData 可观察查询参数? - how to change LiveData observable query parameter with room database in android? 如何在 Room 数据库中查询 LiveData<string> 传递变量时</string> - How to query Room database for LiveData<String> while passing a variable 如果记录不存在于 LiveData 和 Room 会怎样? - What happened if a record doesn't exist with LiveData and Room? 如何使用 LiveData 更新 Room 数据库行<t>目的?</t> - How to update Room database row using a LiveData<T> object? 与 Livedata 不同,使用 Flow in Room 查询在更新表条目时不会触发刷新,但在我删除或插入条目时有效 - Unlike Livedata, using Flow in Room query doesn't trigger a refresh when updating a table entry but works if I delete or insert an entry Room 数据库中的事务返回 LiveData - Transaction in Room Database returning LiveData Room getItemById查询不适用于LiveData - Room getItemById query not working with LiveData Android Room查询不返回LiveData - Android Room query not returning the LiveData
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM