Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite rawquery returns only first record

Tags:

android

sqlite

My SQLite query returning only one record, However, the table has multiple rows

cursor=mydb.rawQuery("Select category from items;", null);

I have even tried GROUP BY but still wont work.

I am new to SQLite, would appreciate any help. Thanks.

like image 316
Shafi Avatar asked Feb 10 '26 22:02

Shafi


1 Answers

First of all your string query must not be terminated so instead of passing it as:

"Select category from items;"

you should try passing it as:

"Select category from items"

as mentioned on this page.

Also, are you looping over the cursor? Here is an example of how to get data out of a cursor with a while loop:

ArrayList<String> results = new ArrayList<String>()
while (cursor.moveNext()) {
    results.add(cursor.getString(0)); // 0 is the first column 
}
like image 72
Tom Miller Avatar answered Feb 13 '26 14:02

Tom Miller