public int update(DBData dbData) { ContentValues values = new ContentValues(); values.put(COLUMN_ID, dbData.getId()); values.put(COLUMN_MEMO, dbData.getMemo()); values.put(COLUMN_PRIORITY, dbData.getPriority()); String whereClause = "id = " + dbData.getId(); return db.update(TABLE_NAME, values, whereClause, null); }
public DBData findById(int id) { String selection = "id = " + id; Cursor cursor = db.query(TABLE_NAME, COLUMNS, selection, null, null, null, null); while (cursor.moveToNext()) { DBData dbData = new DBData(); dbData.setId(cursor.getInt(0)); dbData.setMemo(cursor.getString(1)); dbData.setPriority(cursor.getInt(2)); return dbData; } return null; }
public List<DBData> findAll() { List<DBData> dbDataList = new ArrayList<DBData>(); Cursor cursor = db.query(TABLE_NAME, COLUMNS, null, null, null, null, COLUMN_ID); while (cursor.moveToNext()) { DBData dbData = new DBData(); dbData.setId(cursor.getInt(0)); dbData.setMemo(cursor.getString(1)); dbData.setPriority(cursor.getInt(2)); dbDataList.add(dbData); } return dbDataList; }
public long insert(DBData dbData) { ContentValues values = new ContentValues(); values.put(COLUMN_MEMO, dbData.getMemo()); values.put(COLUMN_PRIORITY, dbData.getPriority()); return db.insert(TABLE_NAME, null, values); }