I am using the following lines for looping on rows of a Sqlite query.
this.open(); // opening db
Cursor cursor = db.rawQuery(strQuery, null);
cursor.moveToFirst();
do {
// do something
} while (cursor.moveToNext());
cursor.close();
When the number of rows is about 15000 it takes long time. It takes about 4 seconds for empty while
block and about 6 second for while
block that has some codes. It shows that iterating on rows in this way is time consuming.
Is there any faster way for looping on rows in android and Sqlite?
Thanks,
7.2.SQLite provides the ability for advanced programmers to exercise control over the query plan chosen by the optimizer.
In FULL sync mode the SQLite database engine will use the xSync method of the VFS to ensure that all content is safely written to the disk surface prior to continuing.
Optimizing what you do inside the loop is the only way of improving the speed of the whole operation. For instance if you're doing getColumnIndex
calls on every iteration, you will be loosing precious time. Do it once, store the value.
Use traceView
to locate where you're loosing time and improve it there. Sadly I can't give a concrete answer, since I don't know what you're doing inside the loop.
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