Does a cursor in Android reference columns from 0 or 1?

后端 未结 3 1963
粉色の甜心
粉色の甜心 2021-01-18 03:50

I am working with an SQLite Database and I am returning cursors successfully but I was wondering if a cursor references columns starting with 0 like arrays or just 1?

相关标签:
3条回答
  • 2021-01-18 04:32

    The Android documentation states that the getColumnIndex method from a SQLite Cursor returns the zero-based index for the given column name, or -1 if the column doesn't exist.

    If you expect the column to exist use getColumnIndexOrThrow(String) instead, which will make the error more clear.

    In short, they start at 0.

    Source:

    http://developer.android.com/reference/android/database/sqlite/SQLiteCursor.html#getColumnIndex(java.lang.String)

    0 讨论(0)
  • 2021-01-18 04:44

    A cursor from a SQLite database in Android references columns from 0.

    0 讨论(0)
  • 2021-01-18 04:47

    I have no idea how you searched in Google, but from the official documentation of Android Cursor

    public abstract int getColumnIndex (String columnName) Since: API Level 1

    Returns the zero-based index for the given column name, or -1 if the column doesn't exist. If you expect the column to exist use getColumnIndexOrThrow(String) instead, which will make the error more clear. Parameters columnName the name of the target column. Returns

    the zero-based column index for the given column name, or -1 if the column name does not exist.

    And you were really not able to find that, but a bunch of useless stuff?

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