如何将整数文字放入Room查询中?

时间:2018-10-16 18:11:18

标签: android android-sqlite android-room

是否可以将整数文字输入到Room查询中?以下查询导致构建错误:

@Query("UPDATE topics SET unreadCount=0 WHERE id=:chatId")
fun resetUnreadCount(chatId: Long)

我尝试了几个选项(包括RawQuery),并选择了将Int参数传递为默认值的选项:

@Query("UPDATE chats SET unreadCount=:ZERO WHERE id=:chatId")
fun resetUnreadCount(chatId: Long, ZERO: Int = 0) // hacky way to pass int literal into the query

有正常的方法吗?

2 个答案:

答案 0 :(得分:0)

请检查此文档。

https://www.sqlite.org/datatype3.html。参见3.4节,它讨论了列亲和力行为

unreadCount='0'

这也应该起作用

@Query("UPDATE topics SET unreadCount='0' WHERE id=:chatId")

答案 1 :(得分:0)

第一个查询具有不同的实体类“主题”

@Query("UPDATE topics SET unreadCount=0 WHERE id=:chatId")

也应该是聊天吗?由于以下查询正在工作。查询中的整数就可以了。

@Query("UPDATE chats SET unreadCount=:ZERO WHERE id=:chatId")