Pasha Oliv
Pasha Oliv

Reputation: 3

android E/SQLiteLog: (1) near "?": syntax error

I'am trying to get the data from SQLite database. In the begining code was like the next one and it's work just fine:

cursor = db.query("ADDITIVES",
                        new String[] {"ADDITIVE_ID", "ADDITIVE_NAME", "DANGER_LEVEL"},
                        "ADDITIVE_NAME = LIKE ?",
                        new String[] { "%" + nameAdditives[i] + "%" },
                        null, null, null);

But i need to use lowerkase on data from table before LIKE operator and I have found that this can only be made with rawQuery method. So I rewrote the code and have this one now.

cursor = db.rawQuery("SELECT ADDITIVE_ID, ADDITIVE_NAME, DANGER_LEVEL FROM ADDITIVES WHERE LOWER(ADDITIVE_ID) = LIKE ?", new String[] { "%" + eAdditives[i].toLowerCase() + "%" });

And I start getting the next error: E/SQLiteLog: (1) near "?": syntax error. What I'am doing wrong?

Upvotes: 0

Views: 1432

Answers (1)

AlexTa
AlexTa

Reputation: 5251

You have to remove equal (=) operator:

cursor = db.rawQuery("SELECT ADDITIVE_ID, ADDITIVE_NAME, DANGER_LEVEL FROM ADDITIVES WHERE LOWER(ADDITIVE_ID) LIKE ?", new String[] { "%" + eAdditives[i].toLowerCase() + "%" });

Upvotes: 2

Related Questions