Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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?

like image 321
Sbrown995 Avatar asked Mar 19 '12 21:03

Sbrown995


3 Answers

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

like image 84
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Avatar answered Sep 23 '22 19:09

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz


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?

like image 32
hovanessyan Avatar answered Sep 22 '22 19:09

hovanessyan


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)

like image 34
Oscar Salguero Avatar answered Sep 22 '22 19:09

Oscar Salguero