繁体   English   中英

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

[英]How to put integer literals into Room query?

是否可以将整数文字输入到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

有正常的方法吗?

请检查此文档。

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

unreadCount='0'

这也应该工作

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

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

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

也应该聊天吗? 由于以下查询正在工作。 查询中的整数很好。

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM