Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming rows from Android Cursor

I have a SQLite table (with more than 100000 rows) that I want its rows streamed.

I do:

Cursor cursor = db.rawQuery("SELECT _id FROM hugetable", new String[] {});

The problem is that just getting the first row as:

cursor.moveToFirst()

seems to load the whole table, being quite slow.

Is there a way to stream a query without having wait to load all the rows when fetching the first row?

(like I can do with the plain C SQLite API outside Android)

like image 360
jcarlos Avatar asked Dec 07 '25 10:12

jcarlos


1 Answers

The Android Cursor is designed to load all data for caching.

To work arouns this, you have to manually query the data in steps:

SELECT _id
FROM hugetable
ORDER BY _id
LIMIT 100;

SELECT _id
FROM hugetable
WHERE _id > last_id_from_previous_query
ORDER BY _id
LIMIT 100;
like image 139
CL. Avatar answered Dec 08 '25 23:12

CL.