Exemple #1
0
  /**
   * Update a Tag
   *
   * @param tagID id of tag to update
   * @param newName new name of tag
   * @param color new color of tag
   * @return true if update succeeded, false if failed and transaction rolled back
   */
  public boolean updateTag(int tagID, String newName, String color)
      throws IllegalArgumentException, SQLiteConstraintException {

    if (LOG_ON) Log.v("DB.updateTag", "update tagId=" + tagID);

    if (hasNoChars(newName) || hasNoChars(color) || tagID < 1) {
      if (LOG_ON) Log.e("db.updateTag", "Invalid argument");
      throw new IllegalArgumentException();
    }
    int affected = 0;
    ContentValues updateValue = new ContentValues();
    updateValue.put(TagConst.NAME, newName);
    updateValue.put(TagConst.COLOR, color);
    String whereClause = TagConst.ID + "=" + tagID;
    db.beginTransaction();
    affected =
        db.updateWithOnConflict(
            TagConst.TBL_NAME, updateValue, whereClause, null, SQLiteDatabase.CONFLICT_ROLLBACK);
    if (affected > 0) {
      db.setTransactionSuccessful();
      db.endTransaction();
      return true;
    } else {
      db.endTransaction();
      throw new SQLiteConstraintException();
    }
  }
  // Add Favourites
  public void addFavouriteVerse(MorningWatchBO verse, String param) {

    ContentValues values = new ContentValues();

    values.put("BibleVerse", verse.getTitle());
    values.put("Description", verse.getDescription());
    values.put("Url", verse.getLink());
    values.put("Entry_Date", verse.getDate());
    values.put("Favourites", param);

    if (doesVerseExists(getTodayDate())) {
      // Inserting Records
      db.updateWithOnConflict(
          tableName,
          values,
          " Entry_Date" + " = '" + verse.getDate() + "'",
          null,
          SQLiteDatabase.CONFLICT_REPLACE);
    } else {
      db.insert(tableName, null, values);
    }
    /*
    if(doesVerseExists(getTodayDate())){
    	db.delete(tableName, "Entry_Date = '"+verse.getDate()+"'", null);
    	db.insert(tableName, null, values);
    }*/

    db.close(); // Closing database connection
  }
  public void updateItem(String id, ContentValues cv) {

    SQLiteDatabase db = this.getWritableDatabase();
    db.updateWithOnConflict(
        ITEMS_TABLE_NAME, cv, ID + " = ?", new String[] {id}, SQLiteDatabase.CONFLICT_REPLACE);

    db.close();
  }
Exemple #4
0
  /**
   * update all category fields other than key id to given values
   *
   * @param catID id of category to update
   * @param name string name of category - maximum length of 32 characters
   * @param colorID id of new color of category
   * @param schema JSON string defining category fields
   * @return true if update is successful, false or exception otherwise
   * @exception SQLiteConstraintException if insert violates constraints
   * @exception IllegalArgumentException if argument format invalid
   * @return true if update succeeded, false if failed and transaction rolled back
   */
  public boolean updateCategory(int catID, String name, String color, String schema)
      throws IllegalArgumentException, SQLiteConstraintException {

    if (LOG_ON) Log.v("DB.updateCategory", "update category categoryID=" + catID);

    // check arguments for valid format
    if (hasNoChars(name) || hasNoChars(color) || hasNoChars(schema)) {
      if (LOG_ON) Log.e("db.updateCategory", "Invalid Argument format");
      throw new IllegalArgumentException();
    }

    ContentValues updateValue = new ContentValues();
    updateValue.put(CategoryConst.NAME, name);
    updateValue.put(CategoryConst.COLOR, color);
    updateValue.put(CategoryConst.SCHEMA, schema);
    String whereClause = CategoryConst.ID + "=" + catID;

    db.beginTransaction();
    int affected = 0;
    affected =
        db.updateWithOnConflict(
            CategoryConst.TBL_NAME,
            updateValue,
            whereClause,
            null,
            SQLiteDatabase.CONFLICT_ROLLBACK);

    if (affected > 0) {
      db.setTransactionSuccessful();
      db.endTransaction();
      return true;
    } else {
      if (LOG_ON)
        Log.e("db.updateCategory", "update failed & rolled back, " + "check constraint exception");
      db.endTransaction();
      return false;
    }
  }
Exemple #5
0
  /**
   * Update all fields of an item other than the key id
   *
   * @param itemID id of item to update
   * @param name new name of item
   * @param catId id of category item belongs to
   * @param data string of JSON field data
   * @return true if update succeeded, false if failed and transaction rolled back
   */
  public boolean updateItem(int itemID, String name, int catId, String data)
      throws IllegalArgumentException, SQLiteConstraintException {

    if (LOG_ON) Log.v("DB.updateItem", "updating item itemId=" + itemID);

    if (hasNoChars(name) || itemID < 1) {
      if (LOG_ON) Log.e("db.updateItem", "Invalid argument");
      throw new IllegalArgumentException();
    }
    int affected = 0;

    ContentValues updateValue = new ContentValues();
    updateValue.put(ItemConst.NAME, name);
    updateValue.put(ItemConst.CAT_ID, catId);
    updateValue.put(ItemConst.DATA, data);

    String whereClause = ItemConst.ID + "=" + itemID;
    affected =
        db.updateWithOnConflict(
            ItemConst.TBL_NAME, updateValue, whereClause, null, SQLiteDatabase.CONFLICT_ROLLBACK);
    if (affected > 0) return true;
    else return false;
  }