private Cursor getWeatherByLocationSettingAndDate( Uri uri, String[] projection, String sortOrder) { String locationSetting = WeatherEntry.getLocationSettingFromUri(uri); long date = WeatherEntry.getDateFromUri(uri); return sWeatherByLocationSettingQueryBuilder.query( mOpenHelper.getReadableDatabase(), projection, sLocationSettingAndDaySelection, new String[] {locationSetting, Long.toString(date)}, 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 WEATHER: { normalizeDate(values); long _id = db.insert(WeatherEntry.TABLE_NAME, null, values); if (_id > 0) returnUri = WeatherEntry.buildWeatherUri(_id); else throw new android.database.SQLException("Failed to insert row into " + uri); break; } case LOCATION: long insert = db.insert(LocationEntry.TABLE_NAME, null, values); if (insert > 0) returnUri = LocationEntry.buildLocationUri(insert); 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 getWeatherByLocationSetting(Uri uri, String[] projection, String sortOrder) { String locationSetting = WeatherEntry.getLocationSettingFromUri(uri); long startDate = WeatherEntry.getStartDateFromUri(uri); String[] selectionArgs; String selection; if (startDate == 0) { selection = sLocationSettingSelection; selectionArgs = new String[] {locationSetting}; } else { selectionArgs = new String[] {locationSetting, Long.toString(startDate)}; selection = sLocationSettingWithStartDateSelection; } return sWeatherByLocationSettingQueryBuilder.query( mOpenHelper.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder); }