Select the first n lines in contentProvider

I have this choice:

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 the cursor data and iterate in it also with a closed cursor (I need to improve performance).

Now I want the Corsor selection to extract only the first fifty rows. The loop solution is 50 times in mQueryMap.getRows().entrySet() is wrong: I don't want mQueryMap to get all cursor lines, but only the first fifty.

Any idea? Is there a where clause to get only the first n lines?

+6
source share
2 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.

Greetings

+12
source

SELECT * FROM Table_Name LIMIT 5;

This is true for sqlite. Try adding "LIMIT 5" to your where clause. (I have not tried)

0
source

Source: https://habr.com/ru/post/885489/


All Articles