@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor result = null; if (URI_ITEMS.equals(uri)) { result = DatabaseHandler.getInstance(getContext()) .getReadableDatabase() .query(Item.TABLE_NAME, Item.FIELDS, null, null, null, null, null, null); result.setNotificationUri(getContext().getContentResolver(), URI_ITEMS); } else if (uri.toString().startsWith(ITEM_BASE)) { final long id = Long.parseLong(uri.getLastPathSegment()); result = DatabaseHandler.getInstance(getContext()) .getReadableDatabase() .query( Item.TABLE_NAME, Item.FIELDS, Item._ID + " IS ?", new String[] {String.valueOf(id)}, null, null, null, null); result.setNotificationUri(getContext().getContentResolver(), URI_ITEMS); } else { throw new UnsupportedOperationException("Not yet implemented"); } return result; }
public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) { SQLiteQueryBuilder sQLiteQueryBuilder = new SQLiteQueryBuilder(); if (m4768a(strArr)) { Cursor rawQuery; sQLiteQueryBuilder.setTables("phone_contact_table"); switch (f2366c.match(uri)) { case C1128R.styleable.StickyListHeadersListView_android_padding /*1*/: break; case C1128R.styleable.StickyListHeadersListView_android_paddingLeft /*2*/: sQLiteQueryBuilder.appendWhere("_id=" + uri.getLastPathSegment()); break; case C1128R.styleable.StickyListHeadersListView_android_paddingTop /*3*/: String str3; String[] strArr3 = new String[2]; if (str == null) { str3 = null; } else { str3 = " AND " + str; } strArr3[0] = "SELECT * FROM (" + sQLiteQueryBuilder.buildQuery( strArr, "recently_joined!='0'" + str3, null, null, str2, null) + ")"; strArr3[1] = "SELECT * FROM (" + sQLiteQueryBuilder.buildQuery(strArr, str, null, null, str2, null) + ")"; String[] strArr4 = null; if (strArr2 != null) { strArr4 = new String[(strArr2.length * 2)]; System.arraycopy(strArr2, 0, strArr4, 0, strArr2.length); System.arraycopy(strArr2, 0, strArr4, strArr2.length, strArr2.length); } rawQuery = this.f2367d .getReadableDatabase() .rawQuery(sQLiteQueryBuilder.buildUnionQuery(strArr3, null, null), strArr4); rawQuery.setNotificationUri(getContext().getContentResolver(), f2364a); return rawQuery; default: throw new IllegalArgumentException("Invalid Uri: " + uri); } rawQuery = sQLiteQueryBuilder.query( this.f2367d.getReadableDatabase(), strArr, str, strArr2, null, null, str2); rawQuery.setNotificationUri(getContext().getContentResolver(), uri); return rawQuery; } throw new IllegalArgumentException("Contact Provider Query, Invalid Projection"); }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // TODO Auto-generated method stub try { if (URI_MATCHER.match(uri) == BT_PROFILES || URI_MATCHER.match(uri) == BT_PROFILES_ID) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(Table_BlueTooth); if (URI_MATCHER.match(uri) == BT_PROFILES_ID) { qb.appendWhere("_id=" + uri.getLastPathSegment()); } Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); if (null != c) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; } if (URI_MATCHER.match(uri) == WLAN_PROFILES || URI_MATCHER.match(uri) == WLAN_PROFILES_ID) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(Table_Wlan); if (URI_MATCHER.match(uri) == WLAN_PROFILES_ID) { qb.appendWhere("_id=" + uri.getLastPathSegment()); } Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); if (null != c) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; } if (URI_MATCHER.match(uri) == USER_PROFILES || URI_MATCHER.match(uri) == USER_PROFILES_ID) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(Table_User); if (URI_MATCHER.match(uri) == USER_PROFILES_ID) { qb.appendWhere("_id=" + uri.getLastPathSegment()); } Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); if (null != c) { c.setNotificationUri(getContext().getContentResolver(), uri); } return c; } else { throw new IllegalArgumentException(); } } catch (SQLiteException e) { return null; } catch (Exception e) { return null; } }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Uisng SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // Check if the caller has requested a column which does not exists checkColumns(projection); // Set the table queryBuilder.setTables(DontForgetMomDbInformation.Trip.CONTENT_PROVIDER_TABLE_NAME); int uriType = sURIMatcher.match(uri); switch (uriType) { case TRIPS: break; case TRIP_ID: // Adding the ID to the original query queryBuilder.appendWhere( DontForgetMomDbInformation.Trip._ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = dbHelper.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); // Make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Uisng SQLiteQueryBuilder instead of query() method SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // check if the caller has requested a column which does not exists checkColumns(projection); // Set the table queryBuilder.setTables(RescueTable.RESCUE_TABLE); int uriType = sURIMatcher.match(uri); switch (uriType) { case URI_MATCHER: break; case URI_MATCHER_ID: // adding the ID to the original query queryBuilder.appendWhere(RescueTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); // make sure that potential listeners are getting notified cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
/** Query entries from the database */ @Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (database == null || !database.isOpen()) database = databaseHelper.getWritableDatabase(); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case SENSOR_DEV: qb.setTables(DATABASE_TABLES[0]); qb.setProjectionMap(sensorDeviceMap); break; case SENSOR_DATA: qb.setTables(DATABASE_TABLES[1]); qb.setProjectionMap(sensorDataMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } try { Cursor c = qb.query(database, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; } catch (IllegalStateException e) { if (Aware.DEBUG) Log.e(Aware.TAG, e.getMessage()); return null; } }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder(); sqlBuilder.setTables(EVENTS_TABLE); if (uriMatcher.match(uri) == 1) { sqlBuilder.setProjectionMap(mMap); } else if (uriMatcher.match(uri) == 2) { sqlBuilder.setProjectionMap(mMap); sqlBuilder.appendWhere(ID + "=?"); selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs, new String[] {uri.getLastPathSegment()}); } else if (uriMatcher.match(uri) == 3) { sqlBuilder.setProjectionMap(mMap); sqlBuilder.appendWhere(START + ">=? OR "); sqlBuilder.appendWhere(END + "<=?"); List<String> list = uri.getPathSegments(); String start = list.get(1); String end = list.get(2); selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs, new String[] {start, end}); } if (sortOrder == null || sortOrder == "") sortOrder = START + " COLLATE LOCALIZED ASC"; Cursor c = sqlBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // TODO Auto-generated method stub db = dBlite.getReadableDatabase(); Cursor c; Log.d("-------", String.valueOf(sMatcher.match(uri))); switch (sMatcher.match(uri)) { case Consts.ITEM: c = db.query(Consts.TNAME, projection, selection, selectionArgs, null, null, sortOrder); break; case Consts.ITEM_ID: String id = uri.getPathSegments().get(1); c = db.query( Consts.TNAME, projection, Consts.TID + "=" + id + (!TextUtils.isEmpty(selection) ? "AND(" + selection + ')' : ""), selectionArgs, null, null, sortOrder); break; default: Log.d("!!!!!!", "Unknown URI" + uri); throw new IllegalArgumentException("Unknown URI" + uri); } c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { int match = sURIMatcher.match(uri); SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c; switch (match) { case GRAVES: return handleQuery(uri, projection, db); case GRAVE_URI_ID: long departedId = ContentUris.parseId(uri); c = db.query( DepartedTableHelper.TABLE_NAME, projection, Columns._ID + " = " + departedId + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), CONTENT_URI); return c; default: throw new IllegalArgumentException("unsupported uri: " + uri); } }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (uriMatcher.match(uri)) { case TEMP_MATTERS: qb.setTables(TempMatterTable.TABLE_NAME); qb.setProjectionMap(tempMatterProjectionMap); break; case TEMP_MATTER_ID: qb.setTables(TempMatterTable.TABLE_NAME); qb.setProjectionMap(tempMatterProjectionMap); qb.appendWhere(TempMatterTable._ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } String orderBy; if (TextUtils.isEmpty(sortOrder)) { orderBy = TempMatterTable.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); // 为Cursor对象注册一个观察数据变化的URI c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(DatabaseHelper.TABLE_ITEM); int uriType = mURImatcher.match(uri); switch (uriType) { case ITEMS_ID: queryBuilder.appendWhere(DatabaseHelper.KEY_ITEM_ID + "=" + uri.getLastPathSegment()); break; case ITEMS: break; default: throw new IllegalArgumentException("Unknown URI"); } Cursor cursor = queryBuilder.query( mDatabaseHelper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); int token = ContentDescriptor.URI_MATCHER.match(uri); switch (token) { case ContentDescriptor.ProjectOrderDesc.TOKEN: qb.setTables(ContentDescriptor.ProjectOrderDesc.NAME); break; case ContentDescriptor.ProjectDesc.TOKEN: qb.setTables(ContentDescriptor.ProjectDesc.NAME); break; case ContentDescriptor.ProjectCheckpointDesc.TOKEN: qb.setTables(ContentDescriptor.ProjectCheckpointDesc.NAME); break; case ContentDescriptor.UpdateDesc.TOKEN: qb.setTables(ContentDescriptor.UpdateDesc.NAME); break; case ContentDescriptor.AuguraLog.TOKEN: qb.setTables(ContentDescriptor.AuguraLog.NAME); break; } SQLiteDatabase db = auguraHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // here's the switch statement that, given a URI, will determine what kind of request it is, // and query the database accordingly. Cursor retCursor; switch (sUriMatcher.match(uri)) { // "user/*/*" case USER_WITH_MOVIEID_AND_FAVORITE: { retCursor = getUserByMovieIDAndFavorite(uri, projection, sortOrder); break; } // "user/*" case USER_WITH_MOVIEID: { retCursor = getUserByMovieID(uri, projection, sortOrder); break; } // "user" case USER: retCursor = sSuperUserBuilder.query( mOpenHelper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); /* retCursor = mOpenHelper.getReadableDatabase().query( //MovieContract.UserEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder );*/ break; case MOVIEID: retCursor = mOpenHelper .getReadableDatabase() .query( MovieContract.MovieEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; default: throw new UnsupportedOperationException("Unknown uri: " + uri); } retCursor.setNotificationUri(getContext().getContentResolver(), uri); return retCursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (mUriMatcher.match(uri) == TWEET_CORRECT_URI_CODE) { mLock.lock(); try { SQLiteDatabase db = mDBHelper.getReadableDatabase(); Cursor c = db.query( WLTwitterDatabaseContract.TABLE_TWEETS, projection, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; } catch (Exception e) { return null; } finally { mLock.unlock(); } } return null; }
@Override public Cursor loadCursor() { final ContentResolver cr = getContext().getContentResolver(); final String selection; final String[] selectionArgs; // Null represents the root filter if (mRequest.getFilter() == null) { selection = DBUtils.concatenateWhere(HomeItems.DATASET_ID + " = ?", HomeItems.FILTER + " IS NULL"); selectionArgs = new String[] {mRequest.getDatasetId()}; } else { selection = DBUtils.concatenateWhere(HomeItems.DATASET_ID + " = ?", HomeItems.FILTER + " = ?"); selectionArgs = new String[] {mRequest.getDatasetId(), mRequest.getFilter()}; } // XXX: You can use CONTENT_FAKE_URI for development to pull items from fake_home_items.json. final Cursor c = cr.query(HomeItems.CONTENT_URI, null, selection, selectionArgs, null); // SQLiteBridgeContentProvider may return a null Cursor if the database hasn't been created // yet. if (c != null) { final Uri notificationUri = getDatasetNotificationUri(mRequest.getDatasetId()); c.setNotificationUri(cr, notificationUri); } return c; }
@Override public Cursor query( final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, String sortOrder) { final SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(VietIDProvider.VIETID_TABLE_NAME); switch (VietIDProvider.uriMatcher.match(uri)) { case VIETIDS: qb.setProjectionMap(VietIDProvider.VIETID_PROJECTION_MAP); break; // case STUDENT_ID: // qb.appendWhere( _ID + "=" + uri.getPathSegments().get(1)); // break; default: throw new IllegalArgumentException("Unknown URI " + uri); } if ((sortOrder == null) || (sortOrder == "")) { /** By default sort on student names */ sortOrder = VietIDProvider.NAME; } final Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); /** register to watch a content URI for changes */ c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Verify columns requested in projection exist. checkColumns(projection); // Build the sql query. SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setTables(StocksTable.TABLE_STOCKS); int uriType = myUriMatcher.match(uri); switch (uriType) { case STOCKS: break; case STOCKS_ID: queryBuilder.appendWhere(StocksTable.COLUMN_ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } // Query the database. SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); // Watches for changes to the data in the database for the query. cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // SQL查询构造器 SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // If no sort order is specified use the default String orderBy = ""; switch (mUriMatcher.match(uri)) { case NOTEITEMS_ITEM: // 注意:没有使用break,我们让它使用后面一条case语句的break // 组建SQL的where queryBuilder.appendWhere(NoteItems._ID + " = " + uri.getPathSegments().get(1)); case NOTEITEMS: // 设置待查询的表 queryBuilder.setTables(TABLE_NOTEITEMS); // 设置要查询的列 queryBuilder.setProjectionMap(mProjectionMap_NoteItems); // 设置排序 if (TextUtils.isEmpty(sortOrder)) { orderBy = NoteItems.DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } break; default: throw new IllegalArgumentException("Unknown URI " + uri); } SQLiteDatabase db = mOpenHelper.getReadableDatabase(); Cursor c = queryBuilder.query(db, projection, selection, selectionArgs, null, null, orderBy); // Tell the cursor what uri to watch, so it knows when its source data // changes c.setNotificationUri(getContext().getContentResolver(), uri); ILog.d(MainActivity.TAG, "ContentProvider==>query()"); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor retCursor; if (sUriMatcher.match(uri) == USERS) { retCursor = mOpenHelper .getReadableDatabase() .query( UserContract.UserEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); } else { throw new UnsupportedOperationException("Unknown Uri: " + uri); } retCursor.setNotificationUri(getContext().getContentResolver(), uri); return retCursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (sUriMatcher.match(uri)) { case DEVICES: qb.setTables(DEVICES_TABLE_NAME); qb.setProjectionMap(devicesProjectionMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor c = db.query( DEVICES_TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); // qb.query(db, projection, selection, selectionArgs, null, null, // sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(FORMS_TABLE_NAME); switch (sUriMatcher.match(uri)) { case FORMS: qb.setProjectionMap(sFormsProjectionMap); break; case FORM_ID: qb.setProjectionMap(sFormsProjectionMap); qb.appendWhere(FormsColumns._ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // Get the database and run the query SQLiteDatabase db = getDbHelper().getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); // Tell the cursor what uri to watch, so it knows when its source data // changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(StatusContract.TABLE); switch (sURIMatcher.match(uri)) { case StatusContract.STATUS_DIR: break; case StatusContract.STATUS_ITEM: qb.appendWhere(StatusContract.Column.ID + "=" + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("ILegal uri: " + uri); } String orderBy = (TextUtils.isEmpty(sortOrder)) ? StatusContract.DEFAULT_SORT : sortOrder; SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); cursor.setNotificationUri(getContext().getContentResolver(), uri); Log.d(TAG, "queried records:" + cursor.getCount()); return cursor; }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (loader != null && data != null) { data.setNotificationUri(getActivity().getContentResolver(), ((CursorLoader) loader).getUri()); } if (data == null || data.getCount() == 0) { if (m_object != null) { Log.w(TAG, "No rows returned for object query? " + m_id); } } else { data.moveToFirst(); m_intId = data.getInt(0); String objJSON = data.getString(1); JSONObject obj = null; try { obj = new JSONObject(objJSON); } catch (JSONException e) { throw new RuntimeException("Database contained invalid JSON", e); } m_object = obj; } onObjectUpdated(); }
@Override public Cursor query( Uri uri, String[] projections, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder(); switch (uriMatcher.match(uri)) { case FINDS_BY_PROJECT: sqlBuilder.setTables(PositDbHelper.FINDS_TABLE); sqlBuilder.appendWhere( PositDbHelper.FINDS_PROJECT_ID + " = " + uri.getPathSegments().get(1)); break; case FIND_ID: sqlBuilder.setTables(PositDbHelper.FINDS_TABLE); sqlBuilder.appendWhere(PositDbHelper.FINDS_ID + " = " + uri.getPathSegments().get(1)); break; case PHOTO_FINDID: sqlBuilder.setTables(PositDbHelper.PHOTOS_TABLE); sqlBuilder.appendWhere(PositDbHelper.FINDS_ID + " = " + uri.getPathSegments().get(1)); break; case PHOTOS_BY_PROJECT: sqlBuilder.setTables(PositDbHelper.PHOTOS_TABLE); sqlBuilder.appendWhere( PositDbHelper.FINDS_PROJECT_ID + " = " + uri.getPathSegments().get(1)); break; } Cursor c = sqlBuilder.query(db, projections, selection, selectionArgs, null, null, sortOrder); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteDatabase db = helper.getReadableDatabase(); SQLiteQueryBuilder builder = new SQLiteQueryBuilder(); switch (sURIMatcher.match(uri)) { case PRODUCTS_LIST: builder.setTables(ProductsTable.TABLE_PRODUCTS); if (TextUtils.isEmpty(sortOrder)) { sortOrder = ProductsTable.SORT_ORDER_DEFAULT; } break; case PRODUCTS_ID: builder.setTables(ProductsTable.TABLE_PRODUCTS); builder.appendWhere(ProductsTable.COLUMN_ID + " = " + uri.getLastPathSegment()); break; default: throw new IllegalArgumentException("Unsupported URI: " + uri); } Cursor cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Using SQLiteQueryBuilder to create a query SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); // Check if the caller has requested a column which does not exist checkColumns(projection); // Set the table queryBuilder.setTables(NOTE_TABLE); int uriType = sURIMatcher.match(uri); switch (uriType) { case ALL_NOTES: break; default: throw new IllegalArgumentException("Unknown URI: " + uri); } SQLiteDatabase db = database.getWritableDatabase(); Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // Resolve the URI. int match = mUriMatcher.match(uri); if (match == UriMatcher.NO_MATCH) { throw new IllegalArgumentException("Invalid URI: " + uri); } // Add the ID predicate if needed. Mapping mapping = mMappings.get(match); if (mapping.hasId) { selection = whereWithId(uri, selection); } // System.out.println("QUERY " + uri + " WHERE (" + selection + ")"); // Run the query. String tableName = mapping.table.getTableName(); Cursor cursor = mDatabase .getReadableDatabase() .query(tableName, projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); switch (uriMatcher.match(uri)) { case ITEM: qb.setTables(CONTACTS_TABLE); break; case ITEM_ID: qb.setTables(CONTACTS_TABLE); qb.appendWhere(AlarmColumn.TASKID + "=" + uri.getPathSegments().get(1)); break; default: break; } String orderBy; if (TextUtils.isEmpty(sortOrder)) { orderBy = AlarmColumn.TASKID; } else { orderBy = sortOrder; } Cursor c = qb.query(pvrDB, projection, selection, selectionArgs, null, null, orderBy); c.setNotificationUri(getContext().getContentResolver(), uri); return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { // TODO Auto-generated method stub // check uri // first 通过SQLiteQueryBuilder,设置数据库查询的信息.Uri有两种情况,一种是collect, // 一种已经指定某个item,两者需要区别对待,item将获取_ID,并在where中增加一个匹配条件. SQLiteQueryBuilder dbQuery = new SQLiteQueryBuilder(); final int match = sUriMatch.match(uri); switch (match) { case HISTORY_COLLECTION_URI_INDICATOR: dbQuery.setTables(ChatHistoryTable.TABLE_NAME); dbQuery.setProjectionMap(sHistoryProjectionMap); break; case HISTORY_ITEM_URI_INDICATION: dbQuery.setTables(ChatHistoryTable.TABLE_NAME); dbQuery.setProjectionMap(sHistoryProjectionMap); dbQuery.appendWhere(ChatHistoryTable._ID + "=" + uri.getPathSegments().get(1)); break; default: throw new IllegalArgumentException("Unknow uri=" + uri); } // second v 对排序进行缺省设置 // String order = TextUtils.isEmpty(sortOrder) ? HistoryTable.DEFAULE_SORT_ORDER : sortOrder; SQLiteDatabase db = mOpenHelper.getReadableDatabase(); // third start query final Cursor c = dbQuery.query(db, projection, selection, selectionArgs, null, null, sortOrder); // fourth 向系统注册通知:观察所要查询的数据,即Uri对应的数据是否发生变化 // 开发者通过provider接口获取数据,可通过通知获知数据已经发生变更 if (c != null) { c.setNotificationUri(mContentResolver, ChatHistoryTable.CONTENT_URI); } return c; }
@Override public Cursor query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (!accept()) { return null; } SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.setTables(SHARING_TABLE_NAME); switch (uriMatcher.match(uri)) { case SHARING_ALL: qb.setProjectionMap(sharingProjectionMap); break; default: throw new IllegalArgumentException("Unknown URI " + uri); } // Get the database and run the query SQLiteDatabase db = databaseHelper.getReadableDatabase(); Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, null); // Tell the cursor what uri to watch, so it knows when its source data // changes c.setNotificationUri(getContext().getContentResolver(), uri); return c; }