public void delete(FunctionButton btn) { if (btn.getId() < 0) return; SQLiteDatabase db = getWritableDatabase(); db.delete(TABLE_FUNCBTNS, "_id = ?", new String[] {String.valueOf(btn.getId())}); db.close(); }
public FunctionButton insert(FunctionButton btn) { SQLiteDatabase db = getWritableDatabase(); long id = db.insert(TABLE_FUNCBTNS, null, btn.getValues()); db.close(); btn.setId(id); return btn; }
public void update(FunctionButton btn) { SQLiteDatabase db = getReadableDatabase(); ContentValues values = btn.getValues(); db.update(TABLE_FUNCBTNS, values, "_id =?", new String[] {String.valueOf(btn.getId())}); db.close(); }
public List<FunctionButton> get() { List<FunctionButton> btns = new LinkedList<FunctionButton>(); SQLiteDatabase db = getReadableDatabase(); Cursor c = db.query( TABLE_FUNCBTNS, null, null, null, null, null, FIELD_FUNCBTNS_SORTNUMBER + " ASC"); while (c.moveToNext()) { FunctionButton btn = new FunctionButton(); btn.setId(c.getLong(c.getColumnIndexOrThrow(FIELD_FUNCBTNS_ID))); btn.setName(c.getString(c.getColumnIndexOrThrow(FIELD_FUNCBTNS_NAME))); btn.setKeys(c.getString(c.getColumnIndexOrThrow(FIELD_FUNCBTNS_KEYS))); btn.setSortNumber(c.getInt(c.getColumnIndexOrThrow(FIELD_FUNCBTNS_SORTNUMBER))); btns.add(btn); } c.close(); db.close(); return btns; }