示例#1
0
  public int updateEvent(String table, IGame game) {
    ContentValues cv = new ContentValues();
    cv.put("evented", game.getIsEvent());
    cv.put("eventid", game.getEventId());

    return db.update(
        table,
        cv,
        "dt = ? AND guest = ?",
        new String[] {DateUtils.getDateTimeString(game.getDate()), game.getGuest()});
  }
示例#2
0
  public void addList(String table, List<IGame> games) {
    db.beginTransaction();
    try {
      Date minDate = new Date();
      minDate.setDate(minDate.getDate() - 1);

      for (IGame game : games) {
        if (game.getDate().after(minDate)) {
          // UPDATE (+ INSERT if UPDATE fails). Less code = fewer bugs.
          ContentValues cv = new ContentValues();
          cv.put("chanls", game.getChanls());
          int row =
              db.update(
                  table,
                  cv,
                  "dt = ? AND guest = ?",
                  new String[] {DateUtils.getDateTimeString(game.getDate()), game.getGuest()});
          if (row == 0) {
            db.execSQL(
                "INSERT INTO " + table + " VALUES(null, ?, ?, ?, ?, ?, ?, ?)",
                new Object[] {
                  game.getGuest(),
                  game.getHost(),
                  DateUtils.getDateTimeString(game.getDate()),
                  game.getType(),
                  game.getChanls(),
                  game.getIsEvent(),
                  game.getEventId()
                });
          }
        }
      }
      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
    }
  }