How can one inject the sqlite3 keyword DISTINCT into an Android ContentProvider's query?
I have an SQL statement that I can use to return distinct rows from my Android sqlite3 database and I would like to pass it through a ContentProvider
's query.
For example:
select lastName from peopleTable where upper(lastName) like upper("%smith%");
needs to be
select DISTINCT lastName from peopleTable where upper(lastName) like upper("%smith%");
开发者_运维问答Is there a clean way to pass the extra keywords to the select statement?
This isn't what I would call a "Good Idea", but depending on the CP, you can modify your projection such that the first entry in the projection is "DISTINCT Column" instead of just "Column". This seems to work as long as the ContentProvider
is backed by a database and no modifications are made to your projection. I will re-iterate though, that this may not be the best future-proof idea as this "feature" isn't documented and more a matter of how queries are put together with the SQLiteDatabase
class. If you know how the ContentProvider
was built, then you can tell up-front whether or not this will work.
精彩评论