0

複数の行を更新したい。make status=false where status=true および make status=true where id=x のように

try {
    String where = "id=?";
    String[] whereArgs = new String[] { Id };

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues initialValues = new ContentValues();
    initialValues.put("status", "true");
    db.update(TABLE_PROJECT, initialValues, where, whereArgs);
    db.close();
} catch (Exception e) {
    Log.e("Exception in update query", e.toString());
}

現在、最初にステータスを更新できますが、次回になると、以前のステータスを false に変更してから、新しいステータスを true に更新する必要があります。検索したところ、スイッチケースで実行できることがわかりましたが、これをどのように適用できますか?

4

2 に答える 2

-3
try {

    String where = "id=? or status=?";
    String[] whereArgs = new String[] { Id,"false" };

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues initialValues = new ContentValues();
    initialValues.put("status", "true");
    db.update(TABLE_PROJECT, initialValues, where, whereArgs);
    db.close();
} catch (Exception e) {
    Log.e("Exception in update query", e.toString());
}
于 2013-05-20T14:00:24.800 に答える