i had a problem about LIKE statement in sqlite android . i used one hours to figure out but i cannot get the error part . Anyone know where is my mistake ?
public Cursor getSearch(String id) {
String[] args = { id };
return (database.rawQuery("SELECT " + SQLiteHelper.product_id
+ " as _id,"
+ SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
+ "," + SQLiteHelper.productQtty + ","
+SQLiteHelper.product_CategoryF+" FROM "
+ SQLiteHelper.productTable+" WHERE "
+ SQLiteHelper.productName +" LIKE 'id%'",null));
}
Error message
bind or column index out of range: handle 0x5e3ec0
anyone know where is my mistake ?
Solution
return (database.rawQuery("SELECT " + SQLiteHelper.product_id
+ " as _id,"
+ SQLiteHelper.productName + " ," +SQLiteHelper.productDesp
+ "," + SQLiteHelper.productQtty + ","
+SQLiteHelper.product_CategoryF+" FROM "
+ SQLiteHelper.productTable+" WHERE "
+ SQLiteHelper.productName +" LIKE '"+id+"%'",null));
You don’t need to form your SQL like that.
rawQuerymakes it very easy to bind arguments.As far as your code is concerned, notice
,"+on your CategoryF line should be+",