如何将 sqlite3 关键字 DISTINCT 注入 Android ContentProvider 的查询中?
我有一个 SQL 语句,可用于从 Android sqlite3 数据库返回不同的行,并且我想通过 ContentProvider
的查询传递它。
例如:
select lastName from peopleTable where upper(lastName) like upper("%smith%");
需要 有
select DISTINCT lastName from peopleTable where upper(lastName) like upper("%smith%");
一种干净的方法将额外的关键字传递给 select 语句吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是我所说的“好主意”,但根据 CP,您可以修改投影,使投影中的第一个条目是“DISTINCT Column”而不仅仅是“Column”。只要
ContentProvider
由数据库支持并且不对您的投影进行任何修改,这似乎就可以工作。不过,我会重申,这可能不是最好的面向未来的想法,因为这个“功能”没有记录在案,更多的是如何将查询与 SQLiteDatabase 类放在一起的问题。如果您知道ContentProvider
是如何构建的,那么您可以预先判断这是否有效。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 theSQLiteDatabase
class. If you know how theContentProvider
was built, then you can tell up-front whether or not this will work.