如何使用连接查询的CursorLoader当它的构造不支持 [英] how to use join query in CursorLoader when its constructor does not support it

查看:110
本文介绍了如何使用连接查询的CursorLoader当它的构造不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表1:N的关系,我使用的内容提供商和cursorloader

I am having two tables with 1:n relationship, I am using content provider and cursorloader.

我将如何做一个连接查询光标装载机工作?我可以rawSql某种程度上破解它的内容提供商内,但如何做到这一点的游标加载器的构造是超越我。

How would I make a join query to work with cursor loader? I could hack it up somehow with rawSql inside content provider but how to do it in cursor loader constructor is beyond me.

非常感谢!

CursorLoader(上下文的背景下,开放的URI,字符串[]投影,选择字符串,字符串[] selectionArgs两个,字符串排序顺序)

如何查询加入开放的时候只能指向一个表

How will query for join when Uri could only point to one table

推荐答案

乌里不指向任何表。它指出,无论你觉得它指向。

The Uri does not point to any table. It points to whatever you feel like pointing it to.

让我们pretend你的两个表是客户订单。一个客户可以有多个订单。你想执行一个查询来获取所有未完成订单...但你想加入一些客户相关的列,你将需要,如客户的名字。

Let's pretend that your two tables are Customer and Order. One customer may have many orders. You want to execute a query to get all outstanding orders... but you want to join in some customer-related columns that you will need, such as the customer's name.

让我们进一步pretend你已经有了内容://your.authority.goes.here/customer 内容:// your.authority.goes.here/order 定义为纯粹的查询这些表。

Let's further pretend that you already have content://your.authority.goes.here/customer and content://your.authority.goes.here/order defined to purely query those tables.

您有两个选择:

  1. 添加用户的显示名称你的 /顺序加入 乌里。有了另一个可用的列可能不会打破供应商的任何现有的消费者(尽管测试始终是一个好主意)。这就是 ContactsContract 做 - 它加入一些基本列,如联系人的姓名,在pretty的所有表的多所有查询

  1. Add the join of the customer's display name on your /order Uri. Having another available column probably will not break any existing consumers of the provider (though testing is always a good idea). This is what ContactsContract does -- it joins in some base columns, like the contact's name, on pretty much all queries of all tables.

创建内容://your.authority.goes.here/orderWithCust 做同样的基本查询为 /订单的做法,但包含您的加入。在这种情况下,你可以有插入()更新()删除( )抛出某种的RuntimeException ,提醒你,使用你不应该修改数据 / orderWithCust 乌里

Create content://your.authority.goes.here/orderWithCust that does the same basic query as /order does, but contains your join. In this case, you could have insert(), update(), and delete() throw some sort of RuntimeException, to remind you that you should not be modifying data using /orderWithCust as a Uri.

在最后,设计一个的ContentProvider 乌里系统类似于设计一个REST Web服务的URL体系。在这两种情况下,连接已经要在供应商/服务器端完成,所以你可能需要打破一个表到一个URL基线提供了一些有用的连接。

In the end, designing a ContentProvider Uri system is similar to designing a REST Web service's URL system. In both cases, the join has to be done on the provider/server side, and so you may need to break the one-table-to-one-URL baseline to offer up some useful joins.

这篇关于如何使用连接查询的CursorLoader当它的构造不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆