Reputation: 2967
I am trying to check if a query is found in one of three columns.
However, the query is searched for only in the first column mentioned:
string[] a = new string[1];
a[0] = '%' + query + '%';
var sqldb_query = "SELECT * FROM MYTABLE WHERE Col_1 LIKE ? OR Col_2 LIKE ? OR Col_3 LIKE ?";
var sqldb_cursor = myDb.RawQuery(sqldb_query, a);
It finds only queries that are in Col_1, not in the others.
What is wrong with my code?
Upvotes: 0
Views: 810
Reputation: 521053
You never bind parameters for the second and third LIKE
expressions in your query. Edit: If you want to use the same LIKE
expression several times, you still need to bind however many times you have placeholders.
string[] a = new string[3];
string likeString = '%' + query + '%';
a[0] = '%' + query + '%';
a[1] = '%' + query + '%';
a[2] = '%' + query + '%';
var sqldb_query = "SELECT * FROM MYTABLE WHERE Col_1 LIKE ? OR Col_2 LIKE ? OR Col_3 LIKE ?";
var sqldb_cursor = myDb.RawQuery(sqldb_query, a);
Upvotes: 2