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)
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With