Kotlin - Inject Android Room SQL language on multiple line queries

拥有回忆 提交于 2020-05-14 14:39:25

问题


How can I get multi-line queries to be injected? It works on Room with Java classes, but does Kotlin support this as well?

E.g. I have 2 queries here, and only the top SQL query (1 line) gets injected.

I tried to follow the steps in this guide but could not find the required settings.

There is an issue at https://youtrack.jetbrains.com/issue/KT-13636 which suggests this is fixed, but I'm not sure how to implement the fix.


回答1:


You can use a raw string which is more readable anyway:

@Dao
interface ItemDao {
    @Query("""
        SELECT * FROM Item
        WHERE Item.id = :id
        """)
    fun loadItemById(id: Long): LiveData<Item>
}


来源:https://stackoverflow.com/questions/50892856/kotlin-inject-android-room-sql-language-on-multiple-line-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!