Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using String[] selectionArgs in SQLiteDatabase.query()

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?

like image 332
BenjiWiebe Avatar asked May 08 '12 21:05

BenjiWiebe


People also ask

What is selectionArgs?

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.

What is the function of RawQuery () in android?

On the other hand, RawQuery serves as an escape hatch where you can build your own SQL query at runtime but still use Room to convert it into objects. RawQuery methods must return a non-void type. If you want to execute a raw query that does not return any value, use RoomDatabase#query methods.


2 Answers

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

like image 53
Gal Ben-Haim Avatar answered Sep 28 '22 20:09

Gal Ben-Haim


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); 
like image 28
waqaslam Avatar answered Sep 28 '22 21:09

waqaslam