Android SQLite更新无法正常工作

pja*_*ama 3 sqlite android

我正在尝试为任意数量的行更新一列.

这是功能:

public void setAwardsSyncComplete(String[] ids) {

    String inArray = StringUtils.separateCommas(ids);
    db.beginTransaction();

    try {
        ContentValues contentValues = new ContentValues();
        contentValues.put(COL_SYNCED, true);

        int rowsAffected = db.update(TABLE, contentValues, COL_ID + " IN (" + inArray + ")", null);

    } catch (Exception e) {

        DebugLog.e("Error in transaction", e.toString());
    } finally {

        db.endTransaction();
    }
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是rowsAffected正确返回(即rowsAffected> 0),但列值保持为null.

我在这里忽略了一些非常简单的事情

谢谢.

Phi*_*llo 8

在使用事务时,需要调用db.setTransactionSuccessful(); 在try子句的末尾.如果没有这个,更新将回滚.

请参见SQLiteDatabase.beginTransaction

希望这可以帮助,

Phil Lello