Search code examples
androidsqlitejoinandroid-contentproviderandroid-cursor

How to join ContentProvider tables through rawQuery?


I want to make sql join through rawQuery.

For example the uri's are as follow:

Uri mmsPartUri = Uri.parse("content://mms/part"); 
Uri mmsInboxUri = Uri.parse("content://mms/inbox");


SQLiteDatabase db = //how to get it?

I imagine the query would look like similar to this:

Cursor cursor = db.rawQuery("SELECT mms.part.mid, mms.part.text, mms.inbox.m_id, mms.inbox.date FROM mms.part JOIN mms.inbox
             ON mms.part.mid = mms.inbox.m_id", null);

Is it possible? Then how? If not is there any other option to join tables, or do I have to use two Cursors and CursorJoiner to get similar result?

If join is not possible across different content providers, I'm curious if I can do any rawQueris like this:

Uri mmsPartUri = Uri.parse("content://mms/part");
SQLiteDatabase db = //how to get it?
Cursor cursor = db.rawQuery("SELECT mms.part.mid, mms.part.text,  FROM mms.part", null);

I saw this and this.


Solution

  • How to join ContentProvider tables through rawQuery?

    There is no rawQuery() available to clients of a ContentProvider.

    You do not have access to the SQLiteDatabase, in part because there is no requirement that there be a SQLite database. A ContentProvider is a facade. Just as a Web service could be backed by any number of database technologies, so can a ContentProvider.

    Is it possible?

    No.

    do I have to use two Cursors and CursorJoiner to get similar result?

    Whether CursorJoiner will meet your needs, I cannot say. However, you will have to do the join on the client side, in your app. This is similar to a Web service, where any joins not already supported by the Web service need to be manually assembled on the client side.