CursorLoader – 两个表连接查询?

我有两个表1:1的关系,我正在使用内容提供商和光标加载器。

我将如何使join查询使用光标加载器? 我可以用内部提供程序中的rawSql以某种方式破解它,但是如何在游标加载器构造函数中做到这一点是超出我的。

非常感谢 !

private static final String CREATE_TABLE_ARTICLES = "create table " + TABLE_ARTICLES + "(" + COLUMN_ARTICLE_ID + " integer primary key autoincrement, " + COLUMN_URL + " text not null unique, " + COLUMN_TITLE + " text not null, " + COLUMN_PRICE + " text not null, " + COLUMN_ADDED + " text not null, " + COLUMN_IMG_URL + " text);"; private static final String CREATE_TABLE_ARTICLE_DETAIL = "create table " + TABLE_ARTICLE_DETAILS + "(" + COLUMN_ARTICLE_DETAIL_ID + " integer primary key autoincrement, " + COLUMN_DESC + " text not null, " + COLUMN_LOCALITY + " text, " + COLUMN_TYPE + " text not null, " + COLUMN_SELLER + " text not null, " + COLUMN_SELLER_PHONE + " text, " + COLUMN_IMAGE_COUNT + " integer default 0, " + COLUMN_ARTICLE + " integer, foreign key (" + COLUMN_ARTICLE + ") references " + TABLE_ARTICLES + "(" + COLUMN_ARTICLE_ID + "));"; 

Solutions Collecting From Web of "CursorLoader – 两个表连接查询?"

实际上,您不必使用自定义任务加载器。 简而言之,一个解决scheme是创build一个Uri“content:// AUTHORITY / TableArticlesWithDetail”。 然后在您的内容提供者中,检查该Uri并执行一个原始SQL来执行联接。

当CursorLoader的构造函数不支持细节时,请参阅如何在CursorLoader中使用连接查询 。

最简单的解决scheme是创build一个视图,join您的表格,并使用Uri从CursorLoader访问视图。

 Cursor c = db.query( RefuelTable.TABLE_NAME + " , " + ExpenseTable.TABLE_NAME, Utils.concat(RefuelTable.PROJECTION, ExpenseTable.PROJECTION), RefuelTable.EXP_ID + " = " + ExpenseTable.ID + " AND " + RuelTable.ID + " = " + id , null, null, null, null); 

像这样做