Android - SQLite Cursor getColumnIndex() is case sensitive?

Yaqub Ahmad picture Yaqub Ahmad · Jan 27, 2012 · Viewed 8.3k times · Source

While working with SQLiteCursor in Android i came to know that the getColumnIndex() is behaving case sensitive for example:

Example:

Column Name in DB was: Rules
cursor.getColumnIndex("Rules")  //workes fine
cursor.getColumnIndex("rules")  //throws error, see the error detail

The documentation says nothing about that, for detail please see this.

LogCat says:

java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it

I am confused by this behavior of SQLiteCursor, can someone help me that this is true OR i am doing something wrong? I can provide the code if required.

Thanks.

Answer

Yaqub Ahmad picture Yaqub Ahmad · Mar 7, 2012

getColumnIndex() is case sensitive:

Column Name in DB was: Rules

cursor.getColumnIndex("Rules") //workes fine

cursor.getColumnIndex("rules") //throws error, see the error detail