Zero-dev Zero-dev - 4 months ago 10
SQL Question

Why like operator doesn't work - Sqlite

I have this query that would return a search from base with the operation Like '%srch'

srch=search.getText().toString();
...
db.rawQuery("SELECT * FROM MyTable WHERE Name LIKE 'srch%' or Name LIKE '%srch' ",null);


but it doesn't work.

Can you explain why it doesn't work, and how I can fix it ?

thanks a lot

CL. CL.
Answer

You can fix the query by changing it as below:

db.rawQuery("SELECT * FROM MyTable WHERE Name LIKE ?",
            new String[] { "%" + srch + "%" });
Comments