Skizit
Skizit

Reputation: 44842

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,

Upvotes: 4

Views: 12901

Answers (1)

Matty F
Matty F

Reputation: 3783

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);
  ...
}

Upvotes: 16

Related Questions