user4301818
user4301818

Reputation: 17

renaming a column in a SQLiteDatabase query

I currently have the query which selects the corresponding row with the given id

Cursor cursor = db.query(TABLE_MEMOS, new String[] { KEY_ID, KEY_TITLE,
                         KEY_BODY, KEY_IMPOR, KEY_ALERT }, KEY_ID + "=?",
                         new String[] { String.valueOf(id) }, null, null, null, null);

I need to cast the column KEY_ID name to _id for it to work with cursors but can't figure out where to add the AS command into the query.

Upvotes: 0

Views: 34

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522626

You can specify column aliases in the string array containing column names, e.g.

String[] cols = new String { KEY_ID + "AS _id", KEY_TITLE,
                             KEY_BODY, KEY_IMPOR, KEY_ALERT };

Upvotes: 1

Related Questions