hysabone.com
hysabone.com

Reputation: 3055

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

I am using a room database for my persistance but when I try to retreive "amount" where a I have the column "type" holding a value positive, It gives the following error

 [SQLITE_ERROR] SQL error or missing database (no such column: negative)

Here's my ObjectDAO Query:

@Query("SELECT amount FROM `Transaction` WHERE transactionType = `positive`")
int getAmountPositive();

Any help would be deeply appreciated!

Upvotes: 2

Views: 1475

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 176224

You should use ' to enclose string literal instead of "`" (backtick):

@Query("SELECT amount FROM `Transaction` WHERE transactionType = 'positive'")

Otherwise it is treated as 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.

Upvotes: 2

Related Questions