简体   繁体   English

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

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

Is it possible to put integer literals into Room query? 是否可以将整数文字输入到Room查询中? Following query leads to build error: 以下查询导致构建错误:

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

I have tried several options (including RawQuery ) and came to an option of passing Int argument with default value: 我尝试了几个选项(包括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

Is there a normal way to do that? 有正常的方法吗?

Please check this documentation. 请检查此文档。

https://www.sqlite.org/datatype3.html . https://www.sqlite.org/datatype3.html Look in section 3.4, it talks about coumn affinity behviour 参见第3.4节,它讨论了列亲和力行为

unreadCount='0'

This should also work 这也应该工作

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

First query has a different Entity class 'topics' 第一个查询具有不同的实体类“主题”

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

Should it be chats too? 也应该聊天吗? as the below query is working. 由于以下查询正在工作。 integer in the query is fine. 查询中的整数很好。

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

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

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