Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public Uri insert(@NonNull Uri uri, ContentValues values) {
- final SQLiteDatabase db = mMovieDbHelper.getWritableDatabase();
- int match = sUriMatcher.match(uri);
- Uri returnUri; // URI to be returned
- switch (match) {
- case MOVIES:
- long id = db.insertWithOnConflict(MovieContract.MovieEntry.TABLE_NAME, null, values,SQLiteDatabase.CONFLICT_IGNORE);
- if ( id > 0 ) {
- returnUri = ContentUris.withAppendedId(MovieContract.MovieEntry.CONTENT_URI, id);
- } else {
- throw new android.database.SQLException("Failed to insert row into " + uri);
- }
- break;
- default:
- throw new UnsupportedOperationException("Unknown uri: " + uri);
- }
- // Notify the resolver if the uri has been changed, and return the newly inserted URI
- getContext().getContentResolver().notifyChange(uri, null);
- return returnUri;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement