"SQLite Error: No Such Column "even though it's a value

"SQLite Error: No Such Column "even though it's a value

我正在使用一个房间数据库来保持我的持久性,但是当我尝试检索 "amount" 时,我的列 "type" 持有一个正值,它给出了以下错误

 [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.