Esempio n. 1
1
 @Override
 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
   SQLiteDatabase db = helper.getWritableDatabase();
   int count = 0;
   switch (uriMatcher.match(uri)) {
     case MEDIAS:
       count = db.update(MediaSchema.TABLE_NAME, values, selection, selectionArgs);
       break;
     case MEDIA_ID:
       count =
           db.update( //
               MediaSchema.TABLE_NAME, //
               values, //
               MediaSchema._ID
                   + " = "
                   + uri.getPathSegments().get(1)
                   + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), //
               selectionArgs //
               );
       break;
     default:
       throw new IllegalArgumentException("Unknown URI " + uri);
   }
   getContext().getContentResolver().notifyChange(uri, null);
   return count;
 }
Esempio n. 2
0
  /** Update the percentages of our workouts. */
  public void updatePercentages(int[] weekOne, int[] weekTwo, int[] weekThree, int[] weekFour) {
    ContentValues cv = new ContentValues();

    cv.put(KEY_WEEK_ONE, weekOne[0]);
    cv.put(KEY_WEEK_TWO, weekTwo[0]);
    cv.put(KEY_WEEK_THREE, weekThree[0]);
    cv.put(KEY_WEEK_FOUR, weekFour[0]);

    mDatabase.update(DATABASE_TABLE_PERCENT, cv, KEY_ROW_ID + "=?", new String[] {"1"});

    cv.clear();
    cv.put(KEY_WEEK_ONE, weekOne[1]);
    cv.put(KEY_WEEK_TWO, weekTwo[1]);
    cv.put(KEY_WEEK_THREE, weekThree[1]);
    cv.put(KEY_WEEK_FOUR, weekFour[1]);

    mDatabase.update(DATABASE_TABLE_PERCENT, cv, KEY_ROW_ID + "=?", new String[] {"2"});

    cv.clear();
    cv.put(KEY_WEEK_ONE, weekOne[2]);
    cv.put(KEY_WEEK_TWO, weekTwo[2]);
    cv.put(KEY_WEEK_THREE, weekThree[2]);
    cv.put(KEY_WEEK_FOUR, weekFour[2]);

    mDatabase.update(DATABASE_TABLE_PERCENT, cv, KEY_ROW_ID + "=?", new String[] {"3"});
  }
 /**
  * Update the database content use content values with current settings and add information
  *
  * @param uri The database uri
  * @param values The values need to update
  * @param selection The where clause
  * @param selectionArgs The where value
  * @return The row numbers have changed
  */
 @Override
 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
   int rows = 0;
   mSqlDb = mDbHelper.getWritableDatabase();
   switch (URI_MATCHER.match(uri)) {
     case STATION_FREQ:
       rows = mSqlDb.update(TABLE_NAME, values, selection, selectionArgs);
       getContext().getContentResolver().notifyChange(uri, null);
       break;
     case STATION_FREQ_ID:
       String stationID = uri.getPathSegments().get(1);
       rows =
           mSqlDb.update(
               TABLE_NAME,
               values,
               FmStation.Station._ID
                   + "="
                   + stationID
                   + (TextUtils.isEmpty(selection) ? "" : " AND (" + selection + ")"),
               selectionArgs);
       getContext().getContentResolver().notifyChange(uri, null);
       break;
     default:
       Log.e(TAG, "update, unkown URI to update: " + uri);
       break;
   }
   return rows;
 }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mDbHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int rowsUpdated;

    switch (match) {
      case VERTRETUNGEN:
        rowsUpdated = db.update(Vertretungen.TABLE_NAME, values, selection, selectionArgs);
        break;
      case DAYS:
        rowsUpdated = db.update(Days.TABLE_NAME, values, selection, selectionArgs);
        break;
      case ABSENT_CLASSES:
        rowsUpdated = db.update(AbsentClasses.TABLE_NAME, values, selection, selectionArgs);
        break;
      case GENERAL_INFO:
        rowsUpdated = db.update(GeneralInfo.TABLE_NAME, values, selection, selectionArgs);
        break;
      case PERSONAL_DATA:
        rowsUpdated = db.update(PersonalData.TABLE_NAME, values, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    if (rowsUpdated != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsUpdated;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int affected_rows;

    switch (uriMatcher.match(uri)) {
      case SINGLE_ROW_IP:
        affected_rows =
            db.update(
                TABLE_NAMEIP,
                values,
                _ID
                    + " = "
                    + uri.getPathSegments().get(1)
                    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
                selectionArgs);
        break;
      case ALL_ROWS_IP:
        affected_rows = db.update(TABLE_NAMEIP, values, selection, selectionArgs);
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return affected_rows;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int count = 0;
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    switch (uriMatcher.match(uri)) {
      case MOVIES:
        count =
            db.update(MoviesCPConstants.FAVOURITES_TABLE_NAME, values, selection, selectionArgs);
        break;

      case MOVIES_ID:
        count =
            db.update(
                MoviesCPConstants.FAVOURITES_TABLE_NAME,
                values,
                MoviesParser.TAG_ID
                    + " = "
                    + uri.getPathSegments().get(1)
                    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
                selectionArgs);
        break;

      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
Esempio n. 7
0
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;
    String finalWhere;

    switch (mUriMatcher.match(uri)) {
      case MAIN:
        // If URI is main table, update uses incoming where clause and
        // args.
        count = db.update("main", values, where, whereArgs);
        break;

      case MAIN_ID:
        // If URI is for a particular row ID, update is based on
        // incoming
        // data but modified to restrict to the given ID.
        finalWhere =
            DatabaseUtils.concatenateWhere(MainTable._ID + " = " + ContentUris.parseId(uri), where);
        count = db.update("main", values, finalWhere, whereArgs);
        break;

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

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    // Student: This is a lot like the delete function.  We return the number of rows impacted
    // by the update.
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int match = sUriMatcher.match(uri);
    int rowUpdated;

    switch (match) {
      case WEATHER:
        rowUpdated = db.update(WeatherEntry.TABLE_NAME, values, selection, selectionArgs);
        break;
      case LOCATION:
        rowUpdated = db.update(LocationEntry.TABLE_NAME, values, selection, selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException();
    }

    Context context = getContext();
    if (rowUpdated != 0 && context != null) {
      context.getContentResolver().notifyChange(uri, null);
    }

    return rowUpdated;
  }
 @Override
 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
   final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
   int rowsUpdated;
   if (selection == null) {
     selection = "1";
   }
   switch (sUriMatcher.match(uri)) {
     case MOVIES_LIST:
       rowsUpdated =
           db.update(MoviesContract.MoviesEntry.TABLE_NAME, values, selection, selectionArgs);
       break;
     case TRAILERS:
       rowsUpdated =
           db.update(MoviesContract.TrailersEntry.TABLE_NAME, values, selection, selectionArgs);
       break;
     case REVIEWS:
       rowsUpdated =
           db.update(MoviesContract.ReviewsEntry.TABLE_NAME, values, selection, selectionArgs);
       break;
     default:
       throw new UnsupportedOperationException("Unknown uri: " + uri);
   }
   if (rowsUpdated != 0) {
     getContext().getContentResolver().notifyChange(uri, null);
   }
   return rowsUpdated;
 }
Esempio n. 10
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    int count;
    switch (sUriMatcher.match(uri)) {
      case INCOMING_CONTACT_COLLECTION_URI_INDICATOR:
        count = db.update(ContactTableMetaData.TABLE_NAME, values, selection, selectionArgs);
        break;
      case INCOMING_SIGNLE_CONTACT_URI_INDICATOR:
        String rowId = uri.getPathSegments().get(1);
        count =
            db.update(
                ContactTableMetaData.TABLE_NAME,
                values,
                ContactTableMetaData._ID
                    + "="
                    + rowId
                    + ((!TextUtils.isEmpty(selection)) ? " AND (" + selection + ')' : ""),
                selectionArgs);
        break;
      default:
        throw new IllegalArgumentException("Unknow URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase database = dbHelper.getWritableDatabase();

    int count;
    switch (uriMatcher.match(uri)) {
      case QUAKES:
        count =
            database.update(EarthquakeDatabaseHelper.EARTHQUAKE_TABLE, values, where, whereArgs);
        break;
      case QUAKE_ID:
        String segment = uri.getPathSegments().get(1);
        count =
            database.update(
                EarthquakeDatabaseHelper.EARTHQUAKE_TABLE,
                values,
                KEY_ID + "=" + segment + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""),
                whereArgs);
        break;
      default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
Esempio n. 12
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = moviesDbHelper.getWritableDatabase();
    final int match = sUriMatcher.match(uri);
    int count;

    switch (match) {
      case MOVIE:
        {
          count = db.update(MoviesContract.MovieEntry.TABLE_NAME, values, selection, selectionArgs);
          break;
        }
      case REVIEW:
        {
          count =
              db.update(MoviesContract.ReviewEntry.TABLE_NAME, values, selection, selectionArgs);
          break;
        }
      case TRAILER:
        {
          count =
              db.update(MoviesContract.TrailerEntry.TABLE_NAME, values, selection, selectionArgs);
          break;
        }
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    if (count != 0) getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
Esempio n. 13
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase writableDatabase = mDbHelper.getWritableDatabase();

    int count;
    switch (sUriMatcher.match(uri)) {
      case MESSAGE_ALLROWS:
      case PROFILE_ALLROWS:
      case TASK_ALLROWS:
        count = writableDatabase.update(getTableName(uri), values, selection, selectionArgs);
        break;

      case MESSAGE_SINGLE_ROW:
      case PROFILE_SINGLE_ROW:
      case TASK_SINGLE_ROW:
        count =
            writableDatabase.update(
                getTableName(uri), values, "_id = ?", new String[] {uri.getLastPathSegment()});
        break;

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

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int count;

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

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

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

    return count;
  }
Esempio n. 15
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    // 记录被修改记录条数
    int count = 0;
    String tmpId;
    switch (mUriMatcher.match(uri)) {
      case NOTEITEMS:
        count = db.update(TABLE_NOTEITEMS, values, selection, selectionArgs);
        break;
      case NOTEITEMS_ITEM:
        tmpId = uri.getPathSegments().get(1);
        count =
            db.update(
                TABLE_NOTEITEMS,
                values,
                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==>update()");
    return count;
  }
Esempio n. 16
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = dbHelper.getWritableDatabase();
    final int match = uriMatcher.match(uri);
    int rowsUpdated;
    switch (match) {
      case BOOK:
        rowsUpdated =
            db.update(AlexandriaContract.BookEntry.TABLE_NAME, values, selection, selectionArgs);
        break;
      case AUTHOR:
        rowsUpdated =
            db.update(AlexandriaContract.AuthorEntry.TABLE_NAME, values, selection, selectionArgs);
        break;
      case CATEGORY:
        rowsUpdated =
            db.update(
                AlexandriaContract.CategoryEntry.TABLE_NAME, values, selection, selectionArgs);
        break;

      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    if (rowsUpdated != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsUpdated;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    // TODO Auto-generated method stub
    int count = 0;

    switch (uriMatcher.match(uri)) {
      case LOGIN:
        count = database.update(TABLE_NAME, values, selection, selectionArgs);
        break;
      case LOGIN_ID:
        count =
            database.update(
                TABLE_NAME,
                values,
                ID
                    + " = "
                    + uri.getLastPathSegment()
                    + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""),
                selectionArgs);
        break;
      default:
        throw new IllegalArgumentException("Unsupported URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

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

    switch (match) {
      case MOVIES:
        rowsUpdated =
            db.update(
                MoviesContract.MoviesEntry.TABLE_NAME, contentValues, selection, selectionArgs);
        break;
      case MOVIE_WITH_ID:
        selectionArgs =
            new String[] {Long.toString(MoviesContract.MoviesEntry.getMovieIDFromUri(uri))};
        rowsUpdated =
            db.update(
                MoviesContract.MoviesEntry.TABLE_NAME,
                contentValues,
                sItemMovieIDSelection,
                selectionArgs);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    if (rowsUpdated != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }
    return rowsUpdated;
  }
Esempio n. 20
0
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;
    switch (sUriMatcher.match(uri)) {
      case RECIPES:
        count = db.update(RECIPES_TABLE_NAME, values, where, whereArgs);
        break;

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

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

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
  // Atualiza uma nota
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    int uriTipo = sURIMatcher.match(uri);
    SQLiteDatabase sqlDB = notasDB.getWritableDatabase();

    int totalEditadas = 0;
    switch (uriTipo) {
      case NOTAS:
        totalEditadas = sqlDB.update(Nota.TABELA, values, selection, selectionArgs);
        break;
      case NOTAS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          totalEditadas = sqlDB.update(Nota.TABELA, values, "_id=" + id, selectionArgs);
        } else {
          totalEditadas =
              sqlDB.update(Nota.TABELA, values, "_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 editadas
    return totalEditadas;
  }
 @Override
 public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
   SQLiteDatabase db = mOpenHelper.getWritableDatabase();
   int count;
   String finalWhere;
   switch (sUriMatcher.match(uri)) {
     case NOTES:
       count = db.update(NotePad.Notes.TABLE_NAME, values, where, whereArgs);
       break;
     case NOTE_ID:
       String noteId = uri.getPathSegments().get(NotePad.Notes.NOTE_ID_PATH_POSITION);
       finalWhere =
           NotePad.Notes._ID
               + " = "
               + uri.getPathSegments().get(NotePad.Notes.NOTE_ID_PATH_POSITION);
       if (where != null) {
         finalWhere = finalWhere + " AND " + where;
       }
       count = db.update(NotePad.Notes.TABLE_NAME, values, finalWhere, whereArgs);
       break;
     default:
       throw new IllegalArgumentException("Unknown URI " + uri);
   }
   getContext().getContentResolver().notifyChange(uri, null);
   return count;
 }
Esempio n. 23
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    // Student: This is a lot like the delete function.  We return the number of rows impacted
    // by the update.
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int rows;

    switch (sUriMatcher.match(uri)) {
      case WEATHER:
        {
          rows =
              db.update(WeatherContract.WeatherEntry.TABLE_NAME, values, selection, selectionArgs);
          break;
        }
      case LOCATION:
        {
          rows =
              db.update(WeatherContract.LocationEntry.TABLE_NAME, values, selection, selectionArgs);
          break;
        }
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    if (selection == null || rows != 0) {
      getContext().getContentResolver().notifyChange(uri, null);
    }

    return rows;
  }
Esempio n. 24
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    final int match = uriMatcher.match(uri);
    int rowsUpdated;

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

    db.close();
    return rowsUpdated;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = helper.getWritableDatabase();
    int updateCount = 0;

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

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

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

    return updateCount;
  }
Esempio n. 26
0
  static boolean update(
      SQLiteDatabase db, String music_id, int rank, RivalInfo rival, ScoreRecord score) {
    if (score == null) return false;
    ContentValues values = new ContentValues(7);
    values.put(DIFFICULTY, score.difficulty);
    values.put(RIVAL_NAME, rival == null ? null : rival.rival_name);
    values.put(CLEAR_STATUS, score.clear_status);
    values.put(TRIAL_STATUS, score.trial_status);
    values.put(HIGH_SCORE, score.high_score);
    values.put(ACHIEVEMENT, score.achievement);
    values.put(RANKING, score.ranking);

    if (rival == null) {
      return db.update(
              NAME, values, WHERE_IDENTITY_MYSCORE, new String[] {music_id, String.valueOf(rank)})
          == 1;
    } else {
      return db.update(
              NAME,
              values,
              WHERE_IDENTITY,
              new String[] {music_id, String.valueOf(rank), rival.rival_code})
          == 1;
    }
  }
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    int count = 0;
    SQLiteDatabase db = openHelper.getWritableDatabase();

    int match = uriMatcher.match(uri);
    switch (match) {
      case CHATS:
        count = db.update(TABLE_CHAT, values, where, whereArgs);
        break;
      case MESSAGES:
        count = db.update(TABLE_MESSAGE, values, where, whereArgs);
        break;
      case CHAT_ID:
        count =
            db.update(
                TABLE_CHAT,
                values,
                ChatData.KEY_ID + "=" + Integer.parseInt(uri.getPathSegments().get(1)),
                null);
        break;
      case MESSAGE_ID:
        count =
            db.update(
                TABLE_MESSAGE,
                values,
                MessageData.KEY_ID + "=" + Integer.parseInt(uri.getPathSegments().get(1)),
                null);
        break;
      default:
        throw new UnsupportedOperationException("Cannot update URI " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }
Esempio n. 28
0
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = database.getWritableDatabase();
    int uriType = myUriMatcher.match(uri);
    int rowsUpdated;
    switch (uriType) {
      case STOCKS:
        rowsUpdated = db.update(StocksTable.TABLE_STOCKS, values, selection, selectionArgs);
        break;
      case STOCKS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          // No selection criteria.
          rowsUpdated =
              db.update(StocksTable.TABLE_STOCKS, values, StocksTable.COLUMN_ID + "=" + id, null);
        } else {
          rowsUpdated =
              db.update(
                  StocksTable.TABLE_STOCKS,
                  values,
                  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 rowsUpdated;
  }
  @Override
  public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int rowUpdated = 0;
    switch (sUriMatcher.match(uri)) {
      case 1:
        rowUpdated =
            db.update(
                SmartKidContract.HomeSameCityList.TABLE_NAME, values, selection, selectionArgs);
        break;

      case 2:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
          rowUpdated =
              db.update(
                  SmartKidContract.HomeSameCityList.TABLE_NAME,
                  values,
                  SmartKidContract.HomeSameCityList.ROW_ID + " = " + id,
                  null);
        } else {
          rowUpdated =
              db.update(
                  SmartKidContract.HomeSameCityList.TABLE_NAME,
                  values,
                  SmartKidContract.HomeSameCityList.ROW_ID + " = " + id + " and " + selection,
                  null);
        }
        break;
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return rowUpdated;
  }
  @Override
  public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase db = getDbHelper().getWritableDatabase();

    Long now = Long.valueOf(System.currentTimeMillis());

    // Make sure that the fields are all set
    if (values.containsKey(InstanceColumns.LAST_STATUS_CHANGE_DATE) == false) {
      values.put(InstanceColumns.LAST_STATUS_CHANGE_DATE, now);
    }

    int count;
    String status = null;
    switch (sUriMatcher.match(uri)) {
      case INSTANCES:
        if (values.containsKey(InstanceColumns.STATUS)) {
          status = values.getAsString(InstanceColumns.STATUS);

          if (values.containsKey(InstanceColumns.DISPLAY_SUBTEXT) == false) {
            Date today = new Date();
            String text = getDisplaySubtext(status, today);
            values.put(InstanceColumns.DISPLAY_SUBTEXT, text);
          }
        }

        count = db.update(INSTANCES_TABLE_NAME, values, where, whereArgs);
        break;

      case INSTANCE_ID:
        String instanceId = uri.getPathSegments().get(1);

        if (values.containsKey(InstanceColumns.STATUS)) {
          status = values.getAsString(InstanceColumns.STATUS);

          if (values.containsKey(InstanceColumns.DISPLAY_SUBTEXT) == false) {
            Date today = new Date();
            String text = getDisplaySubtext(status, today);
            values.put(InstanceColumns.DISPLAY_SUBTEXT, text);
          }
        }

        count =
            db.update(
                INSTANCES_TABLE_NAME,
                values,
                InstanceColumns._ID
                    + "="
                    + instanceId
                    + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""),
                whereArgs);
        break;

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

    getContext().getContentResolver().notifyChange(uri, null);
    return count;
  }