クエリがカーソルを返すという非常に奇妙な問題がありますが、データはデータベースにありますが、カウントは0です。
Cursor cursor = context.getContentResolver().query(VueConstants.CONTENT_URI,
new String[] {"aisleId"}, null, null, null);
Cursor cursor = context.getContentResolver().query(VueConstants.CONTENT_URI,
null, null, null, null);
以下は、URI マッチャーを使用してカスタム コンテンツ プロバイダーでオーバーライドした ContentProvider クラスのクエリ メソッドです。
private static final UriMatcher URIMATCHER;
/** uri matchers for articles table and articles fts3 table query method. */
static {
URIMATCHER = new UriMatcher(UriMatcher.NO_MATCH);
URIMATCHER.addURI(VueConstants.AUTHORITY, VueConstants.AISLES,
AISLES_MATCH);
URIMATCHER.addURI(VueConstants.AUTHORITY, VueConstants.AISLES
+ "/#", AISLE_MATCH);
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteDatabase aislesDB = dbHelper.getWritableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
Cursor cursor = null;
String id;
switch (URIMATCHER.match(uri)) {
case AISLES_MATCH:
qb.setTables(VueConstants.AISLES);
cursor = qb.query(aislesDB, projection, selection, selectionArgs,
null, null, sortOrder);
Log.e("provider", "Total Aisles marked to Content Provider cursor.getCount()" + cursor.getCount());
break;
case AISLE_MATCH:
qb.setTables(VueConstants.AISLES);
id = uri.getLastPathSegment();
cursor = qb.query(aislesDB, projection,
VueConstants.AISLE_ID+ "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')'
: ""), selectionArgs, null, null, null);
break;
case AISLE_IMAGES_MATCH:
qb.setTables(VueConstants.AISLE_IMAGES);
cursor = qb.query(aislesDB, projection, selection, selectionArgs,
null, null, sortOrder);
break;
case IMAGE_MATCH:
qb.setTables(VueConstants.AISLE_IMAGES);
id = uri.getLastPathSegment();
cursor = qb.query(aislesDB, projection,
VueConstants.IMAGE_ID+ "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')'
: ""), selectionArgs, null, null, null);
break;
case LOOKING_FOR_TABLE_MATCH:
qb.setTables(VueConstants.LOOKING_FOR_TABLE);
cursor = qb.query(aislesDB, projection, selection, selectionArgs,
null, null, sortOrder);
break;
case LOOKING_FOR_ROW_MATCH:
qb.setTables(VueConstants.LOOKING_FOR_TABLE);
id = uri.getLastPathSegment();
cursor = qb.query(aislesDB, projection,
VueConstants.ID+ "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')'
: ""), selectionArgs, null, null, null);
break;
case OCCATION_TABLE_MATCH:
qb.setTables(VueConstants.OCCASION_TABLE);
cursor = qb.query(aislesDB, projection, selection, selectionArgs,
null, null, sortOrder);
break;
case OCCATION_ROW_MATCH:
qb.setTables(VueConstants.OCCASION_TABLE);
id = uri.getLastPathSegment();
cursor = qb.query(aislesDB, projection,
VueConstants.ID+ "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')'
: ""), selectionArgs, null, null, null);
break;
case CATEGORY_TABLE_MATCH:
qb.setTables(VueConstants.CATEGORY_TABLE);
cursor = qb.query(aislesDB, projection, selection, selectionArgs,
null, null, sortOrder);
break;
case CATEGORY_ROW_MATCH:
qb.setTables(VueConstants.CATEGORY_TABLE);
id = uri.getLastPathSegment();
cursor = qb.query(aislesDB, projection,
VueConstants.ID+ "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')'
: ""), selectionArgs, null, null, null);
break;
case COMMENTS_TABLE_MATCH:
qb.setTables(VueConstants.COMMENTS_ON_IMAGES_TABLE);
cursor = qb.query(aislesDB, projection, selection, selectionArgs,
null, null, sortOrder);
break;
case COMMENTS_ROW_MATCH:
qb.setTables(VueConstants.COMMENTS_ON_IMAGES_TABLE);
id = uri.getLastPathSegment();
cursor = qb.query(aislesDB, projection,
VueConstants.ID+ "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')'
: ""), selectionArgs, null, null, null);
break;
}
cursor.setNotificationUri(getContext().getContentResolver(), uri);
return cursor;
}