コード例 #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 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;
  }