使用与Content Provider的连接从多个表

时间:2017-04-07 10:56:05

标签: android sqlite join android-sqlite android-contentprovider

我正在尝试从7个表中检索数据并需要加入它们来检索数据,我正在尝试为此项目实现Content Provider。我使用内容提供程序为单个表执行提供了大量示例,但无法为连接案例提供强大的示例。并且事先我需要传递一个字符串参数来查询在该字符串参数的基础上连接表。

对于样本我尝试使用两个没有太多运气的表来传递参数

     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:

dbHelper对于join

看起来像这样
/**
 * 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");
    }

我在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;

所以,我正在等待一个强大的示例继续在Content Provider中加入案例。并提前感谢那里的所有好人。

0 个答案:

没有答案