private Cursor getUserByMovieIDAndFavorite(Uri uri, String[] projection, String sortOrder) { String movieID = MovieContract.UserEntry.getMovieIDFromUri(uri); boolean favorite = MovieContract.UserEntry.getFavoriteFromUri(uri); return sUserByMovieIDQueryBuilder.query( mOpenHelper.getReadableDatabase(), projection, sMovieIDWithFavoriteSelection, new String[] {movieID, Boolean.toString(favorite).toUpperCase()}, null, null, sortOrder); }
/* Student: Add the ability to insert Locations to the implementation of this function. */ @Override public Uri insert(Uri uri, ContentValues values) { final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); final int match = sUriMatcher.match(uri); Uri returnUri; switch (match) { case USER: { long _id = db.insert(MovieContract.UserEntry.TABLE_NAME, null, values); if (_id > 0) returnUri = MovieContract.UserEntry.buildUserUri(_id); else throw new android.database.SQLException("Failed to insert row into " + uri); break; } case MOVIEID: { long _id = db.insert(MovieContract.MovieEntry.TABLE_NAME, null, values); if (_id > 0) returnUri = MovieContract.MovieEntry.buildMovieUri(_id); else throw new android.database.SQLException("Failed to insert row into " + uri); break; } default: throw new UnsupportedOperationException("Unknown uri: " + uri); } getContext().getContentResolver().notifyChange(uri, null); return returnUri; }
private Cursor getUserByMovieID(Uri uri, String[] projection, String sortOrder) { String movieID = MovieContract.UserEntry.getMovieIDFromUri(uri); boolean favorite = MovieContract.UserEntry.getFavoriteFromUri(uri); String[] selectionArgs; String selection; if (favorite == false) { selection = sMovieIDSelection; selectionArgs = new String[] {movieID}; } else { selectionArgs = new String[] {movieID, Boolean.toString(favorite).toUpperCase()}; selection = sMovieIDWithFavoriteSelection; } return sUserByMovieIDQueryBuilder.query( mOpenHelper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); }