如何将 sqlite3 关键字 DISTINCT 注入 Android ContentProvider 的查询中?

发布于 2024-09-26 09:24:03 字数 373 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入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 the SQLiteDatabase class. If you know how the ContentProvider was built, then you can tell up-front whether or not this will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文