Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get count with cursor.getCount() or to execute a rawQuery with a COUNT on a SQL clause?

What would be better in terms of memory efficiency or would have the best overall performance on Android and SQLite, getting a record count with cursor.getCount() or to execute a rawQuery with a COUNT on a normal SQL clause (and use cursor.getInt(0) later to get the count returned)?

Note: I'm not using the results, I just want the count.

like image 607
Oscar Salguero Avatar asked Dec 21 '11 16:12

Oscar Salguero


1 Answers

If you are using the result of the query afterwards, then of course the best way would be to do cursor.getCount() This is faster than doing 2 queries one to get the count and one for the result

EDIT :

If you are not using the results, then a rawQuery is faster because you are gettting only one column from the database instead of many. Plus why would you waste resources to execute a query and not use its result?

like image 91
Adel Boutros Avatar answered Nov 17 '22 08:11

Adel Boutros