Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to load 10000 rows from the SQLite database?

What is the fastest way to load 10,000 rows from a SQLite database into memory? Each row has 1 text and 4 integers. Currently, I'm doing this:

while(!cursor.isAfterLast()) {
    cursor.copyStringToBuffer(column_index_1, buffer);
    cursor.copyStringToBuffer(column_index_2, buffer);
    cursor.copyStringToBuffer(column_index_3, buffer);
    cursor.copyStringToBuffer(column_index_4, buffer);
    cursor.copyStringToBuffer(column_index_5, buffer);
    cursor.moveToNext();
}

The above code takes about 750 ms on Galaxy Nexus. On older devices it could be couple of times slower. Can I make it faster?

(At this point, you're probably typing something like "Why do you need to load the rows into memory?" It's a bit complicated but I can try to explain if someone's interested. Edit: here's the explanation: https://gist.github.com/fhucho/af355d56ae3145e3e30f)

like image 567
fhucho Avatar asked Nov 03 '22 20:11

fhucho


1 Answers

First i advice you to load only the first 1000 rows, and then Use AsyncTask to load more.

You can find response here http://www.javasrilankansupport.com/2012/11/asynctask-android-example-asynctask-in.html

Hope this help

like image 179
Adrien Cerdan Avatar answered Nov 14 '22 22:11

Adrien Cerdan