Search code examples
androidsqlitesql-delete

Syntax error near "#5018" in android sqlite database


In Android application, I have a database to store contacts. In that, I have a "Number" column of "Text" type.
I get syntax error near: "#5018" (code 1) error while executing below query:

string passedNumber = "#5018"; db.delete("Contact_Table, "Number=" + passedNumber, null);


But If I use quotte aroung number like:
db.delete("Contact_Table, "Number='" + passedNumber + "'", null);
then it is working properly.

My concern is why it is giving error although I have Number column of Text type.


Solution

  • Because #5018 is syntactically not a number or any other valid construct. When you enclose it in single quotes as '#5018' it becomes a string literal and that is syntactically correct. 5018 would be a syntactically valid numeric literal.

    Column type affinities have nothing to do with literal syntax.