将值从1转换为0 sqlite

时间:2014-02-08 09:28:47

标签: android android-sqlite

我想将所有其他行的default_option值设置为0,将一个特定行设置为1.

public int updateDefaultPayOptions(String id) {
        String whereValues[] = new String[]{id};
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues newValues = new ContentValues();
        newValues.put(Constants.DEFAULT_OPTION, 1);     
        return db.update(Constants.MY_TABLE, newValues, Constants.OPTION_ID + "=?", whereValues);
    }

只有Option_ID为id的行应将DEFAULT_OPTION设为1,其余行应将DEFAULT_OPTION设置为0。

如何有效地实现目标?

1 个答案:

答案 0 :(得分:1)

将表的所有行设置为0:

 SQLiteDatabase db = this.getWritableDatabase();
 ContentValues newValues = new ContentValues();
 newValues.put(Constants.DEFAULT_OPTION, 0);     
 return db.update(Constants.MY_TABLE, newValues, null, null);

然后使用您的函数将一行ID更改为1。