开发者

Content Provider URI's hierarchical nature vs. Database's relational nature

开发者 https://www.devze.com 2023-02-12 21:03 出处:网络
Progressing with Android learning, I have been introduced to the concept of data source abstraction via a content provider.

Progressing with Android learning, I have been introduced to the concept of data source abstraction via a content provider.

I noticed that content providers are accessed via URIs, which are hierarchical in nature.

We all know about the limitations of hierarchy, which is one of the reasons relational databases are so much more prevalent.

The "problem" is that hierarchical URIs are aiming to represent relational databases.

Isn't this, in essence, reducing the power and flexibility of relational databases other access methods (e.g. SQL)? Something like "lossy compressio开发者_如何学Pythonn"?

If not, what am I missing?


What you're missing may be that URI's define a piece of data, not all the relationships it has with other data. They aren't representing the relational database, just a piece of data in that database. You can think of the relational database as a bunch of overlapping hierarchies that give you many ways to get to the same piece of data. A Uri just defines one of those paths.

I use a fairly complicated relational database, but I still can access a piece of data with a URI.

Here's my approach:

The Uri path is the data type (or database table for example) I want to retrieve data from.
The Uri Query parameters define the relationships that the data I want must satisfy.

You can use whatever query parameters you want and whatever data type you want to return. It is then up to you how you implement that in your database manager.

0

精彩评论

暂无评论...
验证码 换一张
取 消