sqlite: looks like moveToNext works without moveToFirst needed

后端 未结 1 847
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 15:34

After creating a standard SQLite cursor, I\'m iterating thru the entries using:

while (cursor.moveToNext()) {
}

All the rows are being proc

相关标签:
1条回答
  • 2021-01-01 16:09

    No, this is working correctly. Cursors begin at row index -1 (before the first row). If the Cursor references multiple rows, looping through them with the while loop as you have suggested is the preferred method. It will call moveToNext(), which moves you to index 0 (the first row), and go from there.

    If your Cursor only references one row, you may call moveToFirst() on it before reading data to ensure that you are on a valid index. Both moveToFirst() and moveToNext() have the same effect when the Cursor is first created and is at index -1.

    0 讨论(0)
提交回复
热议问题