Using a Content Provider Connection to Query from Multiple Tables

I am trying to get data from 7 tables and need to join them to fetch data and I am trying to implement Content Provider for this project. I got a lot of examples to do a single table using a content provider, but can't get a strong sample for the connection example. And in advance, I need to pass a string parameter to query the join of the table based on that string parameter.

for the sample i tried with two tables, not much luck for parameter passing

     case JOIN_FOR_ALL_EVENT_TABLE:

       //it is used to get Id but I need a string parameter to pass 
       //it here, and I don't know how can I achieve that. 
       //This works for only case of id not the String.    
       // And the event_id in my case is a string needs to have - symbol                      
       //on it.  

     _id = ContentUris.parseId(uri);
            Log.e("************* args ",_id + "");
            retCursor = db.rawQuery(
                    "SELECT * " +
                            "from " +
                            "event_info" + " LEFT JOIN "
                            + "wild_animal_info" + " ON "
                            + "event_info.event_id"
                            + " = " + "wild_animal_info.event_id"+" WHERE "+"event_info.event_id"+" ="+ args[0] ,null);
            break;

        default:

      

And dbHelper looks like this for the connection

/**
 * Method to get all data using join
 */

public void getAllDataFromEventId(String eventId){

    Cursor cursor = myCR.query(ContentUris.withAppendedId(
            TigerContract.CONTENT_URI_RELATIONSHIP_JOIN, id),null,null,null,null);

    if(cursor.moveToFirst()){
        Log.v("***********","size of crsor "+cursor.getCount());
        cursor.moveToFirst();
        Log.v("********NEW ",cursor.getString(1));
        Log.v("********NEW ",cursor.getString(2));
        Log.v("********NEW ",cursor.getString(4));
        Log.v("********NEW ",cursor.getString(5));

    }else{
        cursor.close();

        Log.v("*********New ","Didn't got anything there");
    }

      

And everything I did in the contract class for Join,

   public static final String PATH_JOIN_FOR_ALL_EVENT_TALBE = "join_for_all_event_table";
   public static final Uri CONTENT_URI_RELATIONSHIP_JOIN= BASE_CONTENT_URI.buildUpon().appendPath(PATH_JOIN_FOR_ALL_EVENT_TALBE).build();
   public static final String CONTENT_TYPE_JOIN = "vnd.android.cursor.item/" + CONTENT_AUTHORITY +"/"+ PATH_JOIN_FOR_ALL_EVENT_TALBE;

      

So, I'm waiting for a strong sample to participate in the Content Provider joining business. And thanks in advance to all the good people.

+3


source to share





All Articles