views:

73

answers:

2

Hi Guys,

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,

A: 

What do you mean by "deal with" multiple columns? Will it be OK if you just drop the value from each column into distinct variables and then concatenate or otherwise munge them after parsing the database results?

Jim Kiley
I just want to take each value out of each column and put them each into a specific variable for each row.
Ulkmun
+4  A: 

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++) {
  ...
  var1 = cursor.getString(i);
  ...
}
Matty F
I know this is already accepted, but a `do {}while (cursor.moveToNext());` works better, because if you check .moveToNext first, you skip the first record... Learned from experience...
AndyD273
Are you sure? A cursor typically is sitting at position -1 when returned and calling moveToNext() will move it to the first row.Also, with your logic the code block inside do{} will always execute at least once, even if the Cursor contains no records.
Matty F