我正在使用房间数据库来实现持久性,但是当我尝试检索“金额”时,其中“类型”列的值为正值,它会给出以下错误
[SQLITE_ERROR] SQL error or missing database (no such column: negative)
这是我的 ObjectDAO 查询:
@Query("SELECT amount FROM `Transaction` WHERE transactionType = `positive`")
int getAmountPositive();
任何帮助将不胜感激!
最佳答案
您应该使用 '
来括起字符串文字,而不是“`”(反引号):
@Query("SELECT amount FROM `Transaction` WHERE transactionType = 'positive'")
否则将被视为 identifier :
'keyword' A keyword in single quotes is a string literal.
"keyword" A keyword in double-quotes is an identifier.
[keyword] A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.
`keyword`
A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.
关于android - "SQLite Error: No Such Column "即使它是一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48251077/