Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: sqlite: cursor: getColumnIndex

I've got a fairly complicated query (multiple joins) on a normalized sqlite database. The query does a SELECT * to enable some automated attribute selection logic (so I can't eliminate the "*")

The problem I am having is that my result set contains multiple columns with the same attribute name. For example, one attribute common to each table in the query is "_id". When I go to call "cursor.getColumnIndex("_id")" the value returned is always the index of the last "_id" attribute in the result set column list (i.e. not the one I want). I'd love to be able to use my SQL alias prefixes like cursor.getColumnIndex("A._id") but that is not working.

QUESTIONs

  • It appears that cursor.getColumnIndex(AttributeName) returns the index of the last "AttributeName". Can anyone confirm this?
  • Also, any suggestions on how return the index of the 1st attribute with "AttributeName"? or better the Xth attribute having "AttributeName"?
like image 721
celoftis Avatar asked Oct 31 '11 21:10

celoftis


1 Answers

Unfortunately the documentation doesn't mention anything about what you need to do, so I am assuming it cannot be done.

However, you say

The query does a SELECT * to enable some automated attribute selection logic (so I can't eliminate the "*")

What is this 'automated attribute selection logic' you speak of? Why do you require this?

like image 109
Jack Avatar answered Oct 16 '22 07:10

Jack