Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite Query and using cursor to deal with multiple rows

I've got a query, (I'm using rawQuery())

  SELECT * FROM <table>

I'm then storing what it returns using a cursor. From their what I want to do is, start at the first row so.. cursor.moveToFirst() then take each column , column by column and store its particular value in a variable. I then want to move onto the next row and do the same. So I guess my question is How would I get cursor to deal with multiple columns?

Thanks,

like image 317
Skizit Avatar asked Dec 06 '22 02:12

Skizit


1 Answers

I might be missing something here, wouldn't you have a nested loop.

The outer loop cycles through each records:

while (cursor.moveToNext()) {
  ...
  // inner loop here
  ...
}

and the inner loop would cycle through each column

for (i=0; i<cursor.getColumnCount(); i++) {
  ...
  String var1 = cursor.getString(i);
  ...
}
like image 117
Matty F Avatar answered Dec 21 '22 09:12

Matty F