问题
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