1

I am quering to my SQLite data base to get records using IN operator

myDataBase.rawQuery("SELECT * FROM artist WHERE artist_id IN (?)", values);

but i am getting some SQLite exception. i did not understand what the problem is when my database has 1 record which was returned by this query then it was prefect, but when i have 2 or more records in my database to return by this query it is throwing some exception that exception is

SQLiteException: bind or column index out of range

please let me know what i am doing wrong with this query

thanks...

Farrukh
  • 259
  • 2
  • 5
  • 15

1 Answers1

1

I would suggest like this

StringBuilder query = new StringBuilder();
// build "SELECT * FROM artist WHERE artist_id IN "
query.append('(').
for (int i = 0; i < values.length; i++) {
    query.append(values[i]);
    if (i != values.length - 1) {
        query.append(',');
    }
}
query.append(')');

myDataBase.rawQuery(query.toString(), null);
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99