Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<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>
 

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