Android Question SQL query error

andredamen

Active Member
Licensed User
Longtime User
I've encountered something very strange. My database definitely contains the column "hit2." When I execute this query, SELECT * FROM data WHERE hit2 = aaaa000600166, I get the error:

android.database.sqlite.SQLiteException: no such column: aaaa000600166 (code 1 SQLITE_ERROR[1]): , while compiling: SELECT * FROM data WHERE hit2 = aaaa000600166

When I change the query to: SELECT * FROM data WHERE hit2 = 000600166, no error appears. It seems that adding "aaaa" to the search criteria triggers the error. I don't get an error message with the query SELECT * FROM data WHERE hit2 = +000600166 either, but if I change it to SELECT * FROM data WHERE hit2 = a000600166 or any other letter, the error message appears again.

Does anyone have any idea what's going on here?
 

DonManfred

Expert
Licensed User
Longtime User
Post the code using this SQLs.
Make sure to use parametrized queries.
What is the type of hit2? varchar, int?
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
Like in B4X and most programming languages, a spaceless string of characters beginning with a digit is taken to be a literal number, and a spaceless string of characters beginning with a letter is taken to be an identifier (variable name, or statement, function or operator).

So 000600166 is taken to be a decimal number (or octal in C, Java, etc, because it begins with an otherwise-unnecessary leading 0)

and aaaa000600166 is taken to be an identifier, in this case a column name, resulting in the "no such column" error
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Thank you all. I am going to use the solution with the quotes around the literal. That works good for me.
Thanks emexes! With your explenation I understand why the error became.
 
Upvote 0
Top