Why do Android cursors start before the first row of results and end after the last row?

I am trying to understand why they will start the cursor before the first position in the line and why it will end after the last position. Is there an advantage to inheritance for this?

For instance:

public abstract int getPosition () 

C: API Level 1 Returns the current cursor position in a rowset. The value is zero. When the rowset is first returned, the cursor will be at -1, which is before the first row. After the last line another call is returned, the next () will leave the cursor behind the last record in the position col- ().

returns the current cursor position.

Thanks,

+4
source share
3 answers

Since Cursor not guaranteed to be filled with strings. If you got Cursor back from a database with 0 rows, starting at 0 does not make sense, since at position 0 there is no row.

+8
source

So you can do this:

 Cursor c = db.rawQuery(...); while (c.moveToNext()) { // deal with one row at a time } 

This is the easiest way to iterate over the Cursor results (see What is the best way to repeat the Android cursor? ), And it won’t work if it did not start before the first line.

+5
source

Android SQLiteCursor is a wrapper object for the built-in SQLite database cursor, which is a management structure that allows you to track records in the database.
I assume that before calling setPosition or moveToFirst native cursor does not even load the query results into memory to save space.

0
source

All Articles