How to join/compare query using content provider in android. Is this possible?
1 Answers
Depending on the relation between the two tables, I usually apply any of the following solutions, which I document in the library project through which you would normally expose all your projects externally available interfaces (like a content provider):
If table A contains information that is hardly ever interesting without joining it with table B I simply always return the JOIN of A and B whenever querying A. You can document it in your library, at the place you will define the URI to "table A".
If table A and B contain data that should be query-able in isolation (what I mean is: without a JOIN) then I would normally provide an additional URI, for instance named A_JOIN_B_URI in my library, that, when queried, returns the JOIN of the two tables. Again, you document this in your lib.
There may be more options than this, but I think these adhere best to the notion of what a ContentProvider is: an interface that is agnostic about what data store is implemented behind it. Everywhere you explicitly use capabilities of the underlying data store, this is now made clear by the weird-looking "helper URI".
Any comments on this are welcome, maybe I could learn a thing or two..

- 1,316
- 9
- 16
-
Have you tried using query parameters instead of defining a new URI? – Barum Rho Apr 11 '13 at 18:38
-
I would think that query parameters are normally used to perform stuff like sub-selection? That would, in database land (and actually also in ContentProvider land, probably not totally by coincidence) be covered by implementing a WHERE clause. In this case a JOIN is mentioned, which defines the total set of data that will be queried (so in the SELECT). Of course you could use parameters to distinguish between a JOINED or not-JOINED version of the dataset (it is just another way to package this decision), but I feel that putting in in a different uri-path better describes what is happening.. – baske Apr 12 '13 at 08:48
-
@Barum Rho: As an addition to my previous comment: If what you are suggesting is actually a 'de facto' standard way of dealing with this problem in some other domain like for instance HTML (where uri's are frequently used to point to data), please let me know. I don't know anything about that, so I wouldn't know ;-) I would always try to follow existing standards (even if they are only 'de facto') whenever possible. – baske Apr 12 '13 at 08:51
-
I am not sure what the best way to implement it is. I am considering using query parameters, some tables have more than one relationship, and it would be hard to enumerate all of the cases, and A_JOIN_B_JOIN_C_..._URI would be ugly. – Barum Rho Apr 12 '13 at 14:39