당신은 단지에이 명령을 발사하여
SQL
는) 새로운 총을 추가 안드로이드 프로그래밍에서
SQLite
데이터베이스
B의 값)을 얻거나) 그 (것)들에게
Update
를
C를 뺄
Select
를 사용 할 수
에 database
public void updateExpense(decimal Expense,String Condition) {
double current = 0;
db = this.getReadableDatabase();
String selectQuery = "select id, total from " + TABLE_YourTable ;
Cursor cursor = db.rawQuery(selectQuery, null);
int RowID=0;
if (cursor.moveToFirst()) {
current= Double.parseDouble(cursor.getString(1));
RowID= Integer.parseInt(cursor.getString(0));
}
/// Now we use condition --> if condition is positive it mean add ... if condition is negative it means
////subtract
if(Condition.equals("positive"){
current += Expense;
}else {
current =current - Expense;
}
cursor.close();
db.close();
//Your Update to SQLite
db = this.getReadableDatabase();
ContentValues values = new ContentValues();
values.put(total , current);
db.update(TABLE_YourTable , values, KEY_ID + " = ?", new String[] { String.valueOf(RowID) });
db.close();
}
"데이터베이스 내부"값을 변경하지 마십시오. 값을 읽고 변경 한 다음 데이터베이스를 업데이트합니다. 웹에는 수천 개의 SQLite 튜토리얼이 있습니다. 예를 들어, 매번 업데이트하는 누적 합계를 유지하거나 더 나은 쿼리를 사용하여 합계를 얻을 수 있습니다. – Simon