Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with WHERE IN(?) in Android SQLite raw query

Tags:

android

sqlite

How to deal with raw queries in Android DB that contain a lot of arguments? For example SELECT * FROM table WHERE table.column IN (15, 14, 17, 19). Can I use precompiled SQL with ? selections, or is there no other choice than to format each query individually with concatenation?

I'm doing

SQLiteDatabase.rawQuery("... WHERE table.column IN (?)", selectionArgs);

where selectionArgs is String of joined IDs, but the query won't execute.

like image 471
vandut Avatar asked Dec 06 '10 22:12

vandut


1 Answers

No, you can't do that. You have to use ... WHERE table.column IN (?, ?, ?, ?) and add the parameters separately.

like image 156
Mark Byers Avatar answered Sep 28 '22 01:09

Mark Byers