コード例 #1
0
  public Destination getDestinationByID(int id) {
    String[] COLUMNS_DEST = {
      SurvivalappContract.SurvivalEntry.CULUMN_NAME_SURVIVALID,
      SurvivalappContract.SurvivalEntry.CULUMN_NAME_DESTINATION
    };
    SQLiteDatabase db = helper.getReadableDatabase();

    Cursor cursor =
        db.query(
            SurvivalappContract.SurvivalEntry.TABLE_NAME,
            COLUMNS_DEST,
            " survivalid = ?",
            new String[] {String.valueOf(id)},
            null,
            null,
            null,
            null);

    if (cursor != null) {
      cursor.moveToFirst();
    } else {
      Log.d("Database", "Destination not found");
      return null;
    }

    Destination dest = null;

    if (cursor != null) {
      dest = new Destination();
      dest.setMyID(Integer.parseInt(cursor.getString(0)));
      dest.setDestination(cursor.getString(1));
    }

    return dest;
  }
コード例 #2
0
  public List<Item> getAllItemsById(int id) {
    List<Item> items = new LinkedList<>();

    SQLiteDatabase db = helper.getReadableDatabase();

    String[] COLUMNS_ITEM = {
      SurvivalappItemContract.SurvivalItemEntry.CULUMN_NAME_SURVIVALITEMID,
      SurvivalappItemContract.SurvivalItemEntry.CULUMN_NAME_ITEM,
      SurvivalappItemContract.SurvivalItemEntry.CULUMN_NAME_SURVIVALID
    };

    Cursor cursor =
        db.query(
            SurvivalappItemContract.SurvivalItemEntry.TABLE_NAME,
            COLUMNS_ITEM,
            " survivalid = ?",
            new String[] {String.valueOf(id)},
            null,
            null,
            null,
            null);

    Item item = null;
    if (cursor.moveToFirst()) {
      do {
        item = new Item();
        item.setMyID(Integer.parseInt(cursor.getString(0)));
        item.setItem(cursor.getString(1));

        items.add(item);
      } while (cursor.moveToNext());
    }

    return items;
  }
コード例 #3
0
  public void saveDestination(Destination d) {
    SQLiteDatabase db = helper.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(SurvivalappContract.SurvivalEntry.CULUMN_NAME_DESTINATION, d.getDestination());

    db.insert(SurvivalappContract.SurvivalEntry.TABLE_NAME, null, values);

    db.close();
  }
コード例 #4
0
  public void saveItem(Item t) {
    SQLiteDatabase db = helper.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(SurvivalappItemContract.SurvivalItemEntry.CULUMN_NAME_ITEM, t.getItem());
    values.put(SurvivalappItemContract.SurvivalItemEntry.CULUMN_NAME_SURVIVALID, t.getDestID());

    db.insert(SurvivalappItemContract.SurvivalItemEntry.TABLE_NAME, null, values);

    db.close();
  }
コード例 #5
0
  public List<Destination> getAllDestinations() {
    List<Destination> destinations = new LinkedList<Destination>();

    String query = "SELECT  * FROM " + SurvivalappContract.SurvivalEntry.TABLE_NAME;

    SQLiteDatabase db = helper.getWritableDatabase();
    Cursor cursor = db.rawQuery(query, null);

    Destination dest = null;
    if (cursor.moveToFirst()) {
      do {
        dest = new Destination();
        dest.setMyID(Integer.parseInt(cursor.getString(0)));
        dest.setDestination(cursor.getString(1));

        destinations.add(dest);
      } while (cursor.moveToNext());
    }

    return destinations;
  }