android - "SQLite Error: No Such Column "即使它是一个值

标签 android sqlite android-room

我正在使用房间数据库来实现持久性,但是当我尝试检索“金额”时,其中“类型”列的值为正值,它会给出以下错误

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

相关文章:

objective-c - 在 Objective-C 中获取指针变量的地址

android - Jetpack Compose 和 Android Room 兼容性

android - 如何为使用 Room Auto-Migrations 创建的新列设置现有行的默认值?

android - 哪个跨移动平台应用程序和 UI 框架?

Android Studio Gradle 构建非常慢

android - 检测连接的 watch 版本

sql - 如果根据 EXPLAIN QUERY PLAN 它应该是相反的,为什么一个 SQL 查询比另一个慢?

sqlite - 如何在sqlite中获取连接表的前10条记录?

Android,在恢复时动态创建的 editTexts 的 id 和 View 的清晰文本值

android - 使用 Itemtouchhelper 更改房间数据库的顺序