Android的SQLite的更新不工作 [英] Android SQLite Update not working

查看:162
本文介绍了Android的SQLite的更新不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新一列任意数量的行。

I am trying to update one column for any number of rows.

下面是函数:

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();
    }
}

什么是奇怪的是,的RowsAffected返回正确的(即的RowsAffected> 0),但列值保持的的。

我俯瞰这里的东西很简单?

Am I overlooking something very simple here?

感谢。

推荐答案

当你使用事务,需要调用db.setTransactionSuccessful();在try子句的结束。没有这一点,该更新被回滚。

As you're using transactions, you need to call db.setTransactionSuccessful(); at the end of the try clause. Without this, the update gets rolled back.

请参阅<一href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction%28%29">SQLiteDatabase.beginTransaction

希望这有助于

菲尔Lello

这篇关于Android的SQLite的更新不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆