Reputation: 154
I need some help regarding the SQL raqQuery() method.
Can I pass a string array directly to it like I am doing in the below code?
I want to pass multiple ids to the DB and return a list of matching products to load the adapter from it.
public datatype foo(String[] ids){
Cursor cursor = dataBase.rawQuery("SELECT * FROM tbl_product" + " WHERE productId" + "=?", ids);
}
Upvotes: 1
Views: 53
Reputation: 38098
No. The correct syntax is indeed something like
"SELECT * FROM tbl_product WHERE productId IN (?, ?, ?, ?)"
Simply put those ids you want to search among in your ids string array.
Depending on how many ids you put in the array, put the corresponding number of placeholders (?) in the query I suggested.
Done
Upvotes: 1