Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom ContentProvider for complex sql database with multiple tables
    text
    copied!<p>I am trying to create a library that includes functionality in an already written app. The old app uses a complex sqlite database. I am trying to reuse the old database as the backend for a content provider and can't figure out what would be "best practice" for what I am trying to do and how to adapt the various examples (<a href="http://mobile.tutsplus.com/tutorials/android/android-sdk_content-providers/" rel="nofollow">this</a>, <a href="https://github.com/vladimirvivien/workbench/tree/master/android-tutorials/ContentProviderSample/src/demo/contentprovider" rel="nofollow">this</a>, and others) I have found to my situation.</p> <p>Supoose you have this database structure</p> <pre><code>+------+-------------+-------------+-------------+ | Root | Folder | Item | Subitem | +------+-------------+-------------+-------------+ | _id | _id | _id | _id | | uuid | parent_uuid | parent_uuid | parent_uuid | | | uuid | uuid | uuid | | | name | name | name | | | data | data | data | +------+-------------+-------------+-------------+ Root-&gt;Folder-&gt;Item-&gt;Subitem </code></pre> <p>Before, I used a DbAdapter class where I provided function calls that took parameters such as parent_uuid, handled all the sql query stuff inside the function, then returned a cursor with the results </p> <p>example function stubs:</p> <ul> <li>get_items_by_parent_uuid(folder_uuid)</li> <li>get_item_by_uuid(uuid)</li> <li>same for Subitem also</li> </ul> <p>Complex queries</p> <ul> <li>get_items_for_root(root_uuid) <ul> <li>returns cursor with item uuid, item name, item data, folder name</li> </ul></li> <li>get_items_with_subitem_count(folder_uuid) <ul> <li>returns cursor with item uuid, item name, item data, count of subitems where subitem.parent_uuid == item.uuid</li> </ul></li> </ul> <p>I can't figure out the best way to provide the functionality above with 1 <code>ContentProvider</code>. I don't need someone to write me tons of code (but if you do I'm ok with that too), I just want someone to help me understand how to modify the above linked examples to do these things, because I do mostly understand the examples, just not enough to translate them to my current needs.</p> <p><strong>TL;DR;</strong> - How do I write a single <code>ContentProvider</code> that handles multiple tables, doesn't depend on _id as the unique identifier, and handles joins along with selects that may have inner-selects/queries (such as <code>select count(*)</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