示例#1
1
 private int deleteMessages(SQLiteDatabase db, String selection, String[] selectionArgs) {
   int count = 0;
   String sqlDesc = "";
   db.beginTransaction();
   try {
     // Delete all related records from MyDatabase.MsgOfUser for these messages
     String selectionG =
         " EXISTS ("
             + "SELECT * FROM "
             + Msg.TABLE_NAME
             + " WHERE ("
             + Msg.TABLE_NAME
             + "."
             + BaseColumns._ID
             + "="
             + MsgOfUser.TABLE_NAME
             + "."
             + MyDatabase.MsgOfUser.MSG_ID
             + ") AND ("
             + selection
             + "))";
     String descSuffix = "; args=" + Arrays.toString(selectionArgs);
     sqlDesc = selectionG + descSuffix;
     count = db.delete(MsgOfUser.TABLE_NAME, selectionG, selectionArgs);
     // Now delete messages themselves
     sqlDesc = selection + descSuffix;
     count = db.delete(Msg.TABLE_NAME, selection, selectionArgs);
     db.setTransactionSuccessful();
   } catch (Exception e) {
     MyLog.d(TAG, "; SQL='" + sqlDesc + "'", e);
   } finally {
     db.endTransaction();
   }
   return count;
 }
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   int uriType = sURIMatcher.match(uri);
   SQLiteDatabase sqlDB = database.getWritableDatabase();
   int rowsDeleted = 0;
   switch (uriType) {
     case TOTAL_ELEMENTS:
       rowsDeleted = sqlDB.delete(Consts.TABLE_TWEETER_INFO, selection, selectionArgs);
       break;
     case ELEMENT_ID:
       String id = uri.getLastPathSegment();
       if (TextUtils.isEmpty(selection)) {
         rowsDeleted = sqlDB.delete(Consts.TABLE_TWEETER_INFO, Consts.COLUMN_ID + "=" + id, null);
       } else {
         rowsDeleted =
             sqlDB.delete(
                 Consts.TABLE_TWEETER_INFO,
                 Consts.COLUMN_ID + "=" + id + " and " + selection,
                 selectionArgs);
       }
       break;
     default:
       throw new IllegalArgumentException("Unknown URI: " + uri);
   }
   /*lets not notify content observers on deletes of less then 1 as each delete would cause a network call.
    * user could delete multiple entries at once. if the deletes are greater then 1 then its probably a
    * request to remove the entire list, this we will allow*/
   // if(rowsDeleted>1)
   getContext().getContentResolver().notifyChange(uri, null);
   return rowsDeleted;
 }
  @Override
  public int delete(Uri url, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;
    switch (URI_MATCHER.match(url)) {
      case CONTACTS:
        count = db.delete(TABLE_ROSTER, where, whereArgs);
        break;

      case CONTACT_ID:
        String segment = url.getPathSegments().get(1);

        if (TextUtils.isEmpty(where)) {
          where = "_id=" + segment;
        } else {
          where = "_id=" + segment + " AND (" + where + ")";
        }

        count = db.delete(TABLE_ROSTER, where, whereArgs);
        break;

      default:
        throw new IllegalArgumentException("Cannot delete from URL: " + url);
    }

    getContext().getContentResolver().notifyChange(GROUPS_URI, null);
    notifyChange();

    return count;
  }
示例#4
0
  @Override
  public int delete(Uri uri, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;
    switch (sUriMatcher.match(uri)) {
      case RECIPES:
        count = db.delete(RECIPES_TABLE_NAME, where, whereArgs);
        break;

      case RECIPE_ID:
        String recipeId = uri.getPathSegments().get(1);
        count =
            db.delete(
                RECIPES_TABLE_NAME,
                Recipes._ID
                    + "="
                    + recipeId
                    + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""),
                whereArgs);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   int uriType = sURIMatcher.match(uri);
   SQLiteDatabase sqlDB = database.getWritableDatabase();
   int rowsDeleted = 0;
   switch (uriType) {
     case URI_MATCHER:
       rowsDeleted = sqlDB.delete(RescueTable.RESCUE_TABLE, selection, selectionArgs);
       break;
     case URI_MATCHER_ID:
       String id = uri.getLastPathSegment();
       if (TextUtils.isEmpty(selection)) {
         rowsDeleted =
             sqlDB.delete(RescueTable.RESCUE_TABLE, RescueTable.COLUMN_ID + "=" + id, null);
       } else {
         rowsDeleted =
             sqlDB.delete(
                 RescueTable.RESCUE_TABLE,
                 RescueTable.COLUMN_ID + "=" + id + " and " + selection,
                 selectionArgs);
       }
       break;
     default:
       throw new IllegalArgumentException("Unknown URI: " + uri);
   }
   getContext().getContentResolver().notifyChange(uri, null);
   return rowsDeleted;
 }
示例#6
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = uriMatcher.match(uri);
    int rowsDeleted;

    // this makes delete all rows return the number of rows deleted
    if (null == selection) selection = "1";
    switch (match) {
      case CONTAINER:
        rowsDeleted = db.delete(RSUContract.ContainerEntry.TABLE_NAME, selection, selectionArgs);
        break;
      case TYPE:
        rowsDeleted = db.delete(RSUContract.TypeEntry.TABLE_NAME, selection, selectionArgs);
        break;
      case LOCATION:
        rowsDeleted = db.delete(RSUContract.LocationEntry.TABLE_NAME, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    // Because a null deletes all rows
    if (rowsDeleted != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }

    db.close();
    return rowsDeleted;
  }
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase db = helper.getWritableDatabase();
    int delCount = 0;

    String idStr = "";
    String where = "";
    switch (sURIMatcher.match(uri)) {
      case PRODUCTS_LIST:
        delCount = db.delete(ProductsTable.TABLE_PRODUCTS, selection, selectionArgs);
        break;
      case PRODUCTS_ID:
        idStr = uri.getLastPathSegment();
        where = ProductsTable.COLUMN_ID + " = " + idStr;
        if (!TextUtils.isEmpty(selection)) {
          where += " AND " + selection;
        }
        delCount = db.delete(ProductsTable.TABLE_PRODUCTS, where, selectionArgs);
        break;

      default:
        throw new IllegalArgumentException("Unsupported URI: " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);

    return delCount;
  }
示例#8
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    Log.d(TAG, "delete() uri " + uri);
    int uriType = sURIMatcher.match(uri);
    int rowsDeleted = 0;
    String id;
    SQLiteDatabase sqlDB = database.getWritableDatabase();

    switch (uriType) {
      case EVENTS:
        rowsDeleted = sqlDB.delete(TABLE_EVENTS, selection, selectionArgs);
        break;
      case RECORDS:
        rowsDeleted = sqlDB.delete(TABLE_RECORDS, selection, selectionArgs);
        break;
      case EMPLOYEES:
        rowsDeleted = sqlDB.delete(TABLE_EMPLOYEES, selection, selectionArgs);
        break;
      case EVENT_ID:
        id = uri.getLastPathSegment();
        rowsDeleted =
            sqlDB.delete(TABLE_EVENTS, EventManager.EventQuery.SELECTION_ID, new String[] {id});
        break;
      case EMPLOYEE_ID:
        id = uri.getLastPathSegment();
        rowsDeleted =
            sqlDB.delete(TABLE_EMPLOYEES, EventManager.EventQuery.SELECTION_ID, new String[] {id});
        break;
      default:
        break;
    }
    getContext().getContentResolver().notifyChange(uri, null);
    Log.d(TAG, "delete() rowsDeleted " + rowsDeleted);
    return rowsDeleted;
  }
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int count;

    switch (uriMatcher.match(uri)) {
      case TEMP_MATTERS:
        count = db.delete(TempMatterTable.TABLE_NAME, selection, selectionArgs);
        break;

      case TEMP_MATTER_ID:
        String profileId = uri.getPathSegments().get(1);
        count =
            db.delete(
                TempMatterTable.TABLE_NAME,
                TempMatterTable._ID
                    + "="
                    + profileId
                    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
                selectionArgs);
        break;

      default:
        throw new IllegalArgumentException("Unknow URI " + uri);
    }

    return count;
  }
  /**
   * Delete database table rows with condition
   *
   * @param uri The uri to delete
   * @param selection The where cause to apply, if null will delete all rows
   * @param selectionArgs The select value
   * @return The rows number has be deleted
   */
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    int rows = 0;
    mSqlDb = mDbHelper.getWritableDatabase();
    switch (URI_MATCHER.match(uri)) {
      case STATION_FREQ:
        rows = mSqlDb.delete(TABLE_NAME, selection, selectionArgs);
        getContext().getContentResolver().notifyChange(uri, null);
        break;

      case STATION_FREQ_ID:
        String stationID = uri.getPathSegments().get(1);
        rows =
            mSqlDb.delete(
                TABLE_NAME,
                FmStation.Station._ID
                    + "="
                    + stationID
                    + (TextUtils.isEmpty(selection) ? "" : " AND (" + selection + ")"),
                selectionArgs);
        getContext().getContentResolver().notifyChange(uri, null);
        break;

      default:
        Log.e(TAG, "delete, unkown URI to delete: " + uri);
        break;
    }
    return rows;
  }
 public void delete(long id) {
   SQLiteDatabase database = getWritableDatabase();
   database.delete(
       FEED_ITEM_BYTECODE_TABLE_NAME, KEY_TABLE_ID + " = ?", new String[] {String.valueOf(id)});
   database.delete(
       COMMON_INFORMATION_TABLE_NAME, KEY_TABLE_ID + " = ?", new String[] {String.valueOf(id)});
 }
  /**
   * Delete a segment and all member waypoints
   *
   * @param sqldb The SQLiteDatabase in question
   * @param trackId The track id of this delete
   * @param segmentId The segment that needs deleting
   * @return
   */
  int deleteSegment(SQLiteDatabase sqldb, long trackId, long segmentId) {
    int affected =
        sqldb.delete(
            Segments.TABLE, Segments._ID + "= ?", new String[] {String.valueOf(segmentId)});

    // Delete all waypoints from segments
    affected +=
        sqldb.delete(
            Waypoints.TABLE, Waypoints.SEGMENT + "= ?", new String[] {String.valueOf(segmentId)});
    // Delete all media from segment
    affected +=
        sqldb.delete(
            Media.TABLE,
            Media.TRACK + "= ? AND " + Media.SEGMENT + "= ?",
            new String[] {String.valueOf(trackId), String.valueOf(segmentId)});
    // Delete meta-data
    affected +=
        sqldb.delete(
            MetaData.TABLE,
            MetaData.TRACK + "= ? AND " + MetaData.SEGMENT + "= ?",
            new String[] {String.valueOf(trackId), String.valueOf(segmentId)});

    ContentResolver resolver = this.mContext.getContentResolver();
    resolver.notifyChange(
        Uri.withAppendedPath(Tracks.CONTENT_URI, trackId + "/segments/" + segmentId), null);
    resolver.notifyChange(Uri.withAppendedPath(Tracks.CONTENT_URI, trackId + "/segments"), null);

    return affected;
  }
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {

    int deleted = 0;

    switch (uriMatcher.match(uri)) {
      case TaskContract.TASKS_LIST:
        db.delete(TaskContract.TABLE, selection, selectionArgs);
        break;

      case TaskContract.TASKS_ITEM:
        String where = TaskContract.Columns._ID + " = " + uri.getLastPathSegment();
        if (!selection.isEmpty()) {
          where += " AND " + selection;
        }

        deleted = db.delete(TaskContract.TABLE, where, selectionArgs);
        break;

      default:
        throw new IllegalArgumentException("Invalid URI: " + uri);
    }

    return deleted;
  }
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int rowsDeleted;
    switch (match) {
      case VERTRETUNGEN:
        rowsDeleted = db.delete(Vertretungen.TABLE_NAME, selection, selectionArgs);
        break;
      case DAYS:
        rowsDeleted = db.delete(Days.TABLE_NAME, selection, selectionArgs);
        break;
      case ABSENT_CLASSES:
        rowsDeleted =
            db.delete(VertretungsplanContract.AbsentClasses.TABLE_NAME, selection, selectionArgs);
        break;
      case GENERAL_INFO:
        rowsDeleted = db.delete(GeneralInfo.TABLE_NAME, selection, selectionArgs);
        break;
      case PERSONAL_DATA:
        rowsDeleted = db.delete(PersonalData.TABLE_NAME, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    // null deletes all rows
    if (selection == null || rowsDeleted != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsDeleted;
  }
示例#15
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase db = database.getWritableDatabase();
    int uriType = myUriMatcher.match(uri);
    int rowsDeleted;
    switch (uriType) {
      case STOCKS:
        // Delete all stocks that match the selection criteria
        rowsDeleted = db.delete(StocksTable.TABLE_STOCKS, selection, selectionArgs);
        break;
      case STOCKS_ID:
        // Delete all stock with the specified id that match the selection criteria
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          // No selection criteria.
          rowsDeleted = db.delete(StocksTable.TABLE_STOCKS, StocksTable.COLUMN_ID + "=" + id, null);
        } else {
          rowsDeleted =
              db.delete(
                  StocksTable.TABLE_STOCKS,
                  StocksTable.COLUMN_ID + "=" + id + " and " + selection,
                  selectionArgs);
        }
        break;
      default:
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    // Notify the observer that a row has changed to allow for updates.
    getContext().getContentResolver().notifyChange(uri, null);
    // Return the number of rows that have been deleted.
    return rowsDeleted;
  }
示例#16
0
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    // 记录被删除记录条数
    int count = 0;
    String tmpId;
    switch (mUriMatcher.match(uri)) {
      case NOTEITEMS:
        count = db.delete(TABLE_NOTEITEMS, selection, selectionArgs);
        break;
      case NOTEITEMS_ITEM:
        tmpId = uri.getPathSegments().get(1);
        count =
            db.delete(
                TABLE_NOTEITEMS,
                NoteItems._ID
                    + "="
                    + tmpId
                    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
                selectionArgs);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    ILog.d(MainActivity.TAG, "ContentProvider==>delete()");
    return count;
  }
示例#17
0
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   // TODO Auto-generated method stub
   db = dBlite.getWritableDatabase();
   int count = 0;
   switch (sMatcher.match(uri)) {
     case Consts.ITEM:
       count = db.delete(Consts.TNAME, selection, selectionArgs);
       break;
     case Consts.ITEM_ID:
       String id = uri.getPathSegments().get(1);
       count =
           db.delete(
               Consts.TNAME,
               Consts.TID
                   + "="
                   + id
                   + (!TextUtils.isEmpty(selection) ? "AND(" + selection + ')' : ""),
               selectionArgs);
       break;
     default:
       throw new IllegalArgumentException("Unknown URI" + uri);
   }
   getContext().getContentResolver().notifyChange(uri, null);
   return count;
 }
  @Override
  public int delete(Uri uri, String where, String[] whereArgs) {

    int count = 0;
    switch (uriMatcher.match(uri)) {
      case ALL_SCHEDULE_ITEMS:
        count = barcampDb.delete(SCHEDULE_TABLE_NAME, where, whereArgs);
        break;
      case DELETE_SCHEDULE_ITEM:
        String scheduleId = uri.getPathSegments().get(2);
        count =
            barcampDb.delete(
                SCHEDULE_TABLE_NAME,
                SCHEDULE_ITEM_ID
                    + "="
                    + scheduleId
                    + (!TextUtils.isEmpty(where) ? "( AND " + where + ")" : ""),
                whereArgs);
        break;
      default:
        throw new IllegalArgumentException("Invalid Uri " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
  /**
   * Removes rows in the smartdial database that matches the contacts that have been deleted by
   * other apps since last update.
   *
   * @param db Database pointer to the dialer database.
   * @param last_update_time Time stamp of last update on the smartdial database
   */
  private void removeDeletedContacts(SQLiteDatabase db, String last_update_time) {
    final Cursor deletedContactCursor =
        mContext
            .getContentResolver()
            .query(
                DeleteContactQuery.URI,
                DeleteContactQuery.PROJECTION,
                DeleteContactQuery.SELECT_UPDATED_CLAUSE,
                new String[] {last_update_time},
                null);

    db.beginTransaction();
    try {
      while (deletedContactCursor.moveToNext()) {
        final Long deleteContactId =
            deletedContactCursor.getLong(DeleteContactQuery.DELETED_CONTACT_ID);
        db.delete(
            Tables.SMARTDIAL_TABLE, SmartDialDbColumns.CONTACT_ID + "=" + deleteContactId, null);
        db.delete(Tables.PREFIX_TABLE, PrefixColumns.CONTACT_ID + "=" + deleteContactId, null);
      }

      db.setTransactionSuccessful();
    } finally {
      deletedContactCursor.close();
      db.endTransaction();
    }
  }
示例#20
0
 public void deleteAllRecordsFromDB() {
   WeatherDbHelper dbHelper = new WeatherDbHelper(mContext);
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   database.delete(WeatherContract.WeatherEntry.TABLE_NAME, null, null);
   database.delete(WeatherContract.LocationEntry.TABLE_NAME, null, null);
   database.close();
 }
  @Override
  public int delete(Uri uri, String where, String[] whereArgs) {

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    String finalWhere;

    int count;
    switch (sUriMatcher.match(uri)) {
      case NOTES:
        count = db.delete(NotePad.Notes.TABLE_NAME, where, whereArgs);
        break;
      case NOTE_ID:
        finalWhere =
            NotePad.Notes._ID
                + " = "
                + uri.getPathSegments().get(NotePad.Notes.NOTE_ID_PATH_POSITION);

        if (where != null) {
          finalWhere = finalWhere + " AND " + where;
        }
        count = db.delete(NotePad.Notes.TABLE_NAME, finalWhere, whereArgs);
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
示例#22
0
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   MyHelper.writeMsg(CLASS_NAME + "-->delete is called");
   final SQLiteDatabase db = mMyDatabase.getWritableDatabase();
   final int match = sUriMatcher.match(uri);
   int rowCount = 0;
   // If selection is null then throw an error
   if (selection == null) {
     throw new UnsupportedOperationException(
         "Cannot perform delete without selection. uri: " + uri);
   }
   switch (match) {
     case STUDENT:
       rowCount = db.delete(MyStudent.TABLE_NAME, selection, selectionArgs);
       break;
     case MARKS:
       rowCount = db.delete(MyMarks.TABLE_NAME, selection, selectionArgs);
       break;
     default:
       throw new UnsupportedOperationException("Unknow uri: " + uri);
   }
   // If all records are not deleted then notify the data change
   if (rowCount != 0) {
     getContext().getContentResolver().notifyChange(uri, null);
   }
   return rowCount;
 }
  // Deleta uma ou mais notas
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    int uriTipo = sURIMatcher.match(uri);
    SQLiteDatabase sqlDB = notasDB.getWritableDatabase();

    int totalDeletadas = 0;
    switch (uriTipo) {
      case NOTAS:
        totalDeletadas = sqlDB.delete(Nota.TABELA, selection, selectionArgs);
        break;
      case NOTAS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          totalDeletadas = sqlDB.delete(Nota.TABELA, "_id=" + id, selectionArgs);
        } else {
          totalDeletadas =
              sqlDB.delete(Nota.TABELA, "_id=" + id + " and " + selection, selectionArgs);
        }
        break;
      default:
        throw new IllegalArgumentException("URI desconhecida: " + uri);
    }
    // Notifica as mudanças
    getContext().getContentResolver().notifyChange(uri, null);

    // Retorna o número de notas que foram apagadas
    return totalDeletadas;
  }
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int rowsDeleted = 0;
    switch (sUriMatcher.match(uri)) {
      case 1:
        rowsDeleted =
            db.delete(SmartKidContract.HomeSameCityList.TABLE_NAME, selection, selectionArgs);
        break;

      case 2:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          rowsDeleted =
              db.delete(
                  SmartKidContract.HomeSameCityList.TABLE_NAME,
                  SmartKidContract.HomeSameCityList.ROW_ID + " = " + id,
                  null);
        } else {
          rowsDeleted =
              db.delete(
                  SmartKidContract.HomeSameCityList.TABLE_NAME,
                  SmartKidContract.HomeSameCityList.ROW_ID + " = " + id + " and " + selection,
                  null);
        }
        break;
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return rowsDeleted;
  }
示例#25
0
 public void delete(TTSQLiteOpenHelper openHelper) {
   SQLiteDatabase db = openHelper.getWritableDatabase();
   db.delete(TABLE_STOPS, COLUMN_MAP_ID + " = " + id, null);
   db.delete(TABLE_WAYPOINTS, COLUMN_MAP_ID + " = " + id, null);
   db.delete(TABLE_LOCATIONS, COLUMN_MAP_ID + " = " + id, null);
   db.delete(TABLE_MAPS, COLUMN_ID + " = " + id, null);
 }
  @Override
  public int delete(Uri uri, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int numDeleted;
    switch (match) {
      case FAVORITE_MOVIE:
        numDeleted =
            db.delete(
                FavoriteMoviesContract.FavoriteMovieEntry.TABLE_FAVORITE_MOVIES,
                selection,
                selectionArgs);
        // reset _ID
        db.execSQL(
            "DELETE FROM SQLITE_SEQUENCE WHERE NAME = '"
                + FavoriteMoviesContract.FavoriteMovieEntry.TABLE_FAVORITE_MOVIES
                + "'");
        break;
      case FAVORITE_MOVIE_WITH_ID:
        numDeleted =
            db.delete(
                FavoriteMoviesContract.FavoriteMovieEntry.TABLE_FAVORITE_MOVIES,
                FavoriteMoviesContract.FavoriteMovieEntry._ID + " = ?",
                new String[] {String.valueOf(ContentUris.parseId(uri))});

        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    return numDeleted;
  }
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
   final int match = sUriMatcher.match(uri);
   int rowsDeleted;
   // this makes delete all rows return the number of rows deleted
   if (null == selection) selection = "1";
   switch (match) {
     case MOVIES:
       rowsDeleted = db.delete(MoviesContract.MoviesEntry.TABLE_NAME, selection, selectionArgs);
       break;
     case MOVIE_WITH_ID:
       selectionArgs =
           new String[] {Long.toString(MoviesContract.MoviesEntry.getMovieIDFromUri(uri))};
       rowsDeleted =
           db.delete(MoviesContract.MoviesEntry.TABLE_NAME, sItemMovieIDSelection, selectionArgs);
       break;
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   // Because a null deletes all rows
   if (rowsDeleted != 0) {
     getContext().getContentResolver().notifyChange(uri, null);
   }
   return rowsDeleted;
 }
示例#28
0
 @Override
 public int delete(Uri uri, String where, String[] selectionArgs) {
   // TODO Auto-generated method stub
   int count;
   switch (uriMatcher.match(uri)) {
     case ITEM:
       count = pvrDB.delete(CONTACTS_TABLE, where, selectionArgs);
       break;
     case ITEM_ID:
       long contactID = ContentUris.parseId(uri); // uri.getPathSegments().get(1);
       count =
           pvrDB.delete(
               CONTACTS_TABLE,
               AlarmColumn.TASKID
                   + "="
                   + contactID
                   + (!TextUtils.isEmpty(where) ? " and (" + where + ")" : ""),
               selectionArgs);
       break;
     default:
       throw new IllegalArgumentException("Unsupported URI: " + uri);
   }
   getContext().getContentResolver().notifyChange(uri, null);
   return count;
 }
示例#29
0
 @Override
 public int delete(Uri uri, String selection, String[] selectionArgs) {
   final SQLiteDatabase db = dbHelper.getWritableDatabase();
   final int match = uriMatcher.match(uri);
   int rowsDeleted;
   switch (match) {
     case BOOK:
       rowsDeleted = db.delete(AlexandriaContract.BookEntry.TABLE_NAME, selection, selectionArgs);
       break;
     case AUTHOR:
       rowsDeleted =
           db.delete(AlexandriaContract.AuthorEntry.TABLE_NAME, selection, selectionArgs);
       break;
     case CATEGORY:
       rowsDeleted =
           db.delete(AlexandriaContract.CategoryEntry.TABLE_NAME, selection, selectionArgs);
       break;
     case BOOK_ID:
       rowsDeleted =
           db.delete(
               AlexandriaContract.BookEntry.TABLE_NAME,
               AlexandriaContract.BookEntry._ID + " = '" + ContentUris.parseId(uri) + "'",
               selectionArgs);
       break;
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   // Because a null deletes all rows
   if (selection == null || rowsDeleted != 0) {
     getContext().getContentResolver().notifyChange(uri, null);
   }
   return rowsDeleted;
 }
  @Override
  public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
    // Student: Start by getting a writable database
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    // Student: Use the uriMatcher to match the WEATHER and LOCATION URI's we are going to
    // handle.  If it doesn't match these, throw an UnsupportedOperationException.
    int match = sUriMatcher.match(uri);
    int rowDeleted;
    if (selection == null) selection = "1";

    switch (match) {
      case WEATHER:
        rowDeleted = db.delete(WeatherEntry.TABLE_NAME, selection, selectionArgs);
        break;
      case LOCATION:
        rowDeleted = db.delete(LocationEntry.TABLE_NAME, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException();
    }
    // Student: A null value deletes all rows.  In my implementation of this, I only notified
    // the uri listeners (using the content resolver) if the rowsDeleted != 0 or the selection
    // is null.
    // Oh, and you should notify the listeners here.
    Context context = getContext();
    if (rowDeleted != 0 && context != null) {
      context.getContentResolver().notifyChange(uri, null);
    }

    // Student: return the actual rows deleted
    return rowDeleted;
  }