Using String[] selectionArgs in SQLiteDatabase.query()

BenjiWiebe picture BenjiWiebe · May 8, 2012 · Viewed 47.2k times · Source

How do I use the String[] selectionArgs in SQLiteDatabase.query()? I wish I could just set it to null, as I have no use for it. I am just trying to load an entire unsorted table from a database into a Cursor. Any suggestions on how to achieve this?

Answer

Gal Ben-Haim picture Gal Ben-Haim · May 9, 2012

selectionArgs replace any question marks in the selection string.

for example:

String[] args = { "first string", "[email protected]" };
Cursor cursor = db.query("TABLE_NAME", null, "name=? AND email=?", args, null);

as for your question - you can use null