Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. @Override
  2. public Uri insert(@NonNull Uri uri, ContentValues values) {
  3. final SQLiteDatabase db = mMovieDbHelper.getWritableDatabase();
  4. int match = sUriMatcher.match(uri);
  5. Uri returnUri; // URI to be returned
  6.  
  7. switch (match) {
  8. case MOVIES:
  9.  
  10. long id = db.insertWithOnConflict(MovieContract.MovieEntry.TABLE_NAME, null, values,SQLiteDatabase.CONFLICT_IGNORE);
  11. if ( id > 0 ) {
  12. returnUri = ContentUris.withAppendedId(MovieContract.MovieEntry.CONTENT_URI, id);
  13. } else {
  14. throw new android.database.SQLException("Failed to insert row into " + uri);
  15. }
  16. break;
  17.  
  18. default:
  19. throw new UnsupportedOperationException("Unknown uri: " + uri);
  20. }
  21.  
  22. // Notify the resolver if the uri has been changed, and return the newly inserted URI
  23. getContext().getContentResolver().notifyChange(uri, null);
  24.  
  25. return returnUri;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement