Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select first n rows in contentProvider

I've this select:

 final Cursor cursorConversations = getContentResolver().query(
        Uri.parse("content://gmail-ls/conversations/" + Uri.encode(mailAddress)),
        null, null, null, BaseColumns._ID + " DESC");

 ContentQueryMap mQueryMap 
        = new ContentQueryMap(cursorConversations, BaseColumns._ID, true, null);

With ContentQueyMap I can cache Cursor data and iterate in it also with the Cursor closed (i need it to boost performance).

Now, I want that the select of the Corsor only retrieve the first fifty rows. The solution of looping for 50 times in mQueryMap.getRows().entrySet() is not right: I don't want that mQueryMap gets all the rows of the Cursor, but only the first fifty.

Any idea? Does exist a where clause to get only first n rows?

like image 860
Geltrude Avatar asked Apr 08 '11 09:04

Geltrude


1 Answers

You could do

final Cursor cursorConversations = getContentResolver().query(
    Uri.parse("content://gmail-ls/conversations/" + Uri.encode(mailAddress)),
    null, null, null, BaseColumns._ID + " DESC " + " LIMIT 5");

"LIMIT x" after your SORT.

Cheers

like image 84
Chris.Jenkins Avatar answered Oct 31 '22 21:10

Chris.Jenkins