Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite Get x rows, then next x rows

Tags:

android

sql

Im developing android app, which use SQLite database.

I have ListView which uses data from Database to show a list (see picture).

The picture is decoded in Base64 String and stored in Database. My problem is this Log:

10-19 16:51:36.612: W/CursorWindow(15151): Window is full: 
requested allocation 136877 bytes, free space 78836 bytes, window size 2097152 bytes

It skypes a lot of Frames, because the read time grows. This is because i read always x+10 rows. 1st, it reads 10 rows, then 20, then 30 and go on...

The solution, what i want to use is, get rows from 0-10, 11 - 20, 21 - 30 and so on. How to achieve this? I just need the Sql query.

EDIT: my query

String columns[] = {KEY_ID, KEY_NAME, KEY_RATING, KEY_CUISINE, KEY_IMAGE};
Cursor cursor = db.query(TABLE_RECIPES, columns, null, null, null, null, KEY_NAME, lim);

ListView

like image 981
Vojtěch Pešek Avatar asked Dec 15 '22 19:12

Vojtěch Pešek


1 Answers

Use the rawQuery method, and specify the limit keyword.

e.g.:

"SELECT * FROM myTable limit 10" <-- get the 1st 10 rows
"SELECT * FROM myTable limit 10, 20" <-- get the 2nd 10 rows between 10 and 20, etc

This should get you started.

like image 97
Gil Moshayof Avatar answered Jan 03 '23 12:01

Gil Moshayof