コード例 #1
0
  // USING query() method
  public ArrayList<UnitOfMeasure> getUnitOfMeasures() {
    ArrayList<UnitOfMeasure> unitOfMeasures = new ArrayList<UnitOfMeasure>();

    Cursor cursor =
        database.query(
            UnitsOfMeasureTable.TABLE_NAME,
            new String[] {
              UnitsOfMeasureTable.COLUMN_ID,
              UnitsOfMeasureTable.COLUMN_WEB_ID,
              UnitsOfMeasureTable.COLUMN_NAME
            },
            null,
            null,
            null,
            null,
            null);

    while (cursor.moveToNext()) {
      UnitOfMeasure unitOfMeasure = new UnitOfMeasure();
      unitOfMeasure.setId(cursor.getInt(0));
      unitOfMeasure.setWeb_id(cursor.getInt(1));
      unitOfMeasure.setName(cursor.getString(2));
      unitOfMeasures.add(unitOfMeasure);
    }
    return unitOfMeasures;
  }
コード例 #2
0
  public long update(UnitOfMeasure unitOfMeasure) {
    ContentValues values = new ContentValues();
    values.put(UnitsOfMeasureTable.COLUMN_NAME, unitOfMeasure.getName());

    long result =
        database.update(
            UnitsOfMeasureTable.TABLE_NAME,
            values,
            WHERE_WEB_ID_EQUALS,
            new String[] {String.valueOf(unitOfMeasure.getWeb_id())});
    Log.d("Update Result:", "=" + result);
    return result;
  }
コード例 #3
0
  public long save(UnitOfMeasure unitOfMeasure) {

    if (!unitExist(unitOfMeasure.getName())) {

      ContentValues values = new ContentValues();
      values.put(UnitsOfMeasureTable.COLUMN_ID, unitOfMeasure.getWeb_id());
      values.put(UnitsOfMeasureTable.COLUMN_WEB_ID, unitOfMeasure.getWeb_id());
      values.put(UnitsOfMeasureTable.COLUMN_NAME, unitOfMeasure.getName());
      return database.insert(UnitsOfMeasureTable.TABLE_NAME, null, values);

    } else {
      return update(unitOfMeasure);
    }
  }
コード例 #4
0
  public long saveMultipleData(ArrayList<UnitOfMeasure> unitOfMeasures) {

    for (int i = 0; i < unitOfMeasures.size(); i++) {

      UnitOfMeasure unitOfMeasure = unitOfMeasures.get(i);

      if (!unitExist(unitOfMeasure.getName())) {
        ContentValues values = new ContentValues();
        values.put(UnitsOfMeasureTable.COLUMN_ID, unitOfMeasure.getWeb_id());
        values.put(UnitsOfMeasureTable.COLUMN_WEB_ID, unitOfMeasure.getWeb_id());
        values.put(UnitsOfMeasureTable.COLUMN_NAME, unitOfMeasure.getName());

        database.insert(UnitsOfMeasureTable.TABLE_NAME, null, values);
      } else {

        return update(unitOfMeasure);
      }
    }
    return 1;
  }
コード例 #5
0
  public UnitOfMeasure getUnitOfMeasureByWebID(int web_id) {
    UnitOfMeasure unitOfMeasure = null;

    String sql =
        "SELECT * FROM "
            + UnitsOfMeasureTable.TABLE_NAME
            + " WHERE "
            + UnitsOfMeasureTable.COLUMN_WEB_ID
            + " = ?";

    Cursor cursor = database.rawQuery(sql, new String[] {web_id + ""});

    if (cursor.moveToNext()) {
      unitOfMeasure = new UnitOfMeasure();
      unitOfMeasure.setId(cursor.getInt(0));
      unitOfMeasure.setWeb_id(cursor.getInt(1));
      unitOfMeasure.setName(cursor.getString(2));
    }

    return unitOfMeasure;
  }
コード例 #6
0
 public int delete(UnitOfMeasure unitOfMeasure) {
   return database.delete(
       UnitsOfMeasureTable.TABLE_NAME, WHERE_ID_EQUALS, new String[] {unitOfMeasure.getId() + ""});
 }