Using String[] selectionArgs in SQLiteDatabase.query()

AndroidAndroid SqliteAndroid Cursor

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

Yes, you may set all parameters to null except the table name.

for example:

Cursor cursor = db.query("TABLE_NAME", null, null, null, null, null, null);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBenjiWiebeView Question on Stackoverflow
Solution 1 - AndroidGal Ben-HaimView Answer on Stackoverflow
Solution 2 - AndroidwaqaslamView Answer on Stackoverflow