Rick
Rick

Reputation: 11

Android Cursor _id field

I have a query I am running using SQLiteDatabase.rawQuery which is grouped and doesn't necessarily have a field I can alias as the required _id field needed by the Cursor. Seeing that MySQL doesn't support the rowid function, is there another way around this to avoid the following exception java.lang.IllegalArgumentException: column '_id' does not exist. Also I am using a custom adapter to display these results in a ListView.

Upvotes: 1

Views: 1705

Answers (1)

pawelzieba
pawelzieba

Reputation: 16082

You must be extending CursorAdapter which demand _id column.

  • Add alias in database query to id

Example:

SELECT id _id, name, address FROM user
  • Or if you don't need to distinct rows by id, put in query fake _id.

Example:

SELECT 1 _id, name, address FROM user
  • Or extend other Adapter.

Upvotes: 6

Related Questions