Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public Uri insert(Uri uri, ContentValues contentValues) {
- if (mBookOpenHelper == null)
- mBookOpenHelper = new BookOpenHelper(this.getContext());
- SQLiteDatabase sqLiteDatabase = mBookOpenHelper.getWritableDatabase();
- try {
- long newID = sqLiteDatabase.insertOrThrow(BookOpenHelper.BOOK_TABLE, null, contentValues);
- if (newID > 0) {
- Uri newUri = ContentUris.withAppendedId(uri, newID);
- getContext().getContentResolver().notifyChange(uri, null);
- sqLiteDatabase.close();
- return newUri;
- } else {
- throw new SQLException("Failed to insert row into " + uri);
- }
- } catch (SQLiteConstraintException e) {
- Log.i(this.getClass().getName(), "Ignoring constraint failure.");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement