9

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?

MByD
  • 135,866
  • 28
  • 264
  • 277
Geltrude
  • 1,093
  • 3
  • 17
  • 35

2 Answers2

17

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

Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61
  • Thank you so much! @Chris please do think you could help me here :http://goo.gl/MAjgTh – eddy Sep 20 '14 at 04:28
0

SELECT * FROM Table_Name LIMIT 5;

That's valid for sqlite. Try adding "LIMIT 5" to your where clause. (I have not tried)

Bill Mote
  • 12,644
  • 7
  • 58
  • 82
  • Won't go. And if I put in in the "sort clause parameter" ddms throws an exception: "sortOrder MUST be empty"... (why??) – Geltrude Apr 08 '11 at 13:26