public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.Tables = DATABASE_TABLE_NAME; switch (uriMatcher.Match(uri)) { case LOCATIONS: qb.SetProjectionMap(mProjectionMap); break; case LOCATION_ID: qb.SetProjectionMap(mProjectionMap); qb.AppendWhere(_ID + "=" + uri.PathSegments.ElementAt(1)); break; default: throw new ArgumentException("Unknown URI " + uri); } // If no sort order is specified use the default string orderBy; if (sortOrder.Length < 1) { orderBy = DEFAULT_SORT_ORDER; } else { orderBy = sortOrder; } // Get the database and run the query SQLiteDatabase db = dbHelper.ReadableDatabase; ICursor c = qb.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(Context.ContentResolver, uri); return(c); }
/** * Handle incoming queries. */ public override ICursor Query(Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { // Constructs a new query builder and sets its table name SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); qb.SetTables(MainTable.TABLE_NAME); switch (mUriMatcher.Match(uri)) { case MAIN: // If the incoming URI is for main table. qb.SetProjectionMap(mNotesProjectionMap); break; case MAIN_ID: // The incoming URI is for a single row. qb.SetProjectionMap(mNotesProjectionMap); qb.AppendWhere(IBaseColumnsConstants._ID + "=?"); selectionArgs = DatabaseUtilsCompat.AppendSelectionArgs(selectionArgs, new string[] { uri.GetLastPathSegment() }); break; default: throw new System.ArgumentException("Unknown URI " + uri); } if (TextUtils.IsEmpty(sortOrder)) { sortOrder = MainTable.DEFAULT_SORT_ORDER; } SQLiteDatabase db = mOpenHelper.GetReadableDatabase(); ICursor c = qb.Query(db, projection, selection, selectionArgs, null /* no group */, null /* no filter */, sortOrder); c.SetNotificationUri(Context.GetContentResolver(), uri); return(c); }