Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>How do I write a single ContentProvider that handles multiple tables</p> </blockquote> <p>Step #1: Design a REST interface for your schema, limiting yourself to a simple JSON object as the data structure (i.e., no nested arrays or objects, just a map of keys to simple values)</p> <p>Step #2: Convert that design to a <code>ContentProvider</code>, replacing the <code>http://sooperapp.jp36.com/</code> with <code>content://com.jp36.sooperapp</code> and replacing the JSON with <code>Cursors</code> and <code>ContentValues</code></p> <p>So, for example, you might support <code>content://com.jp36.sooperapp/folder</code> and <code>content://com.jp36.sooperapp/item</code> and <code>content://com.jp36.sooperapp/subitem</code> as the basis of retrieving/modifying information about one or more of each of those types.</p> <blockquote> <p>doesn't depend on _id as the unique identifier</p> </blockquote> <p>If you plan on using <code>CursorAdapter</code>, and assuming that by <code>uuid</code> you really do mean a UUID (which is typically a string), then you have no choice but to also have <code>_id</code>. If, however, you do not plan on using <code>CursorAdapter</code>, you have no particular need for <code>_id</code>.</p> <blockquote> <p>and handles joins along with selects that may have inner-selects/queries (such as select count(*))</p> </blockquote> <p>That's all a matter of your REST interface/<code>ContentProvider</code> design. If you want to have <code>content://com.jp36.sooperapp/folder/count</code> be something you query upon that, behind the scenes, does <code>SELECT COUNT(*) FROM Folder</code>, knock yourself out.</p> <p>(note: do not literally knock yourself out)</p> <p>If you want <code>content://com.jp36.sooperapp/omg/omg/omg/this/is/a/long/path</code> to <code>INSERT</code> an <code>Item</code> and 17 <code>Subitems</code> based upon some <code>insert()</code> call to the provider, go right ahead. <code>ContentProvider</code> is merely a facade; it is up to you to define what the <code>Uri</code> means, what the <code>ContentValues</code> mean, what the <code>query()</code> parameters mean, etc.</p> <p>Personally, I would recommend that you step back and ask yourself why you are bothering with a <code>ContentProvider</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COOk, so lots of questions. ----- 1. When I am creating the `ContentProvider`, do I have a class for each table, with each class defining `CONTENT_URI` as `content://com.jp36.sooperapp/{tablename}/*` and then have separate content_uri's in the individual table classes such as `CONTENT_FROM_PARENT_URI` which would be something like `content://com.jp36.sooperapp/{tablename}/fromparent/*` defined within those objects? ----- 2. If I did query upon `content://com.jp36.sooperapp/folder/count`how would I handle the `String[] projection` parameter that is passed in along with my prebuilt sql statement?
      singulars
    2. COBasically, I'm pretty sure I could figure out some way to use `ContentProvider` to do what I am after, my problems come from trying to figure out the ***right/best practice*** way to do it so that the next person who uses this library will be able to use it similarly to other Android provided `ContentProviders`. ------- Also, I want to use a `ContentProvider` because of nice integration with CursorLoaders and possible SyncAdapter use in the future. ------- Thanks so much for your help so far
      singulars
    3. CO@jp36: "do I have a class for each table" -- well, you could have the `ContentProvider` delegate logic to separate classes if you want, that's up to you. You would only have one `ContentProvider`, though, as those are tied to the "authority" (`com.jp36.sooperapp` in my examples). Basically, everything to the right of the authority is up for you to interpret, with the exception of the instance ID for `Uri` values pointing to a specific record (it's the integer segment on the far right).
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload