SQLite 事务未提交

SQLite transaction not committed

我在我的应用程序中使用 SQLite。
数据库工作正常。
我可以插入 select 并更新行,但在这种情况下,事务未提交。

public int updateTransaction(String oldstatus, String newstatus) {
    int result;
    try {
        mDB.beginTransaction();
        ContentValues values = new ContentValues();
        values.put("trx_status", newstatus);
        result = mDB.update("transaktion", values, "trx_status = ?", new String[] { oldstatus });
        Log.d("DB", "updateTransaction:number of updated rows:" + result);
        mDB.setTransactionSuccessful();
    } catch (SQLiteException e) {
        Log.d("TAGAB", "Error:" + e.getLocalizedMessage());
        result = -1;
    } finally {
        mDB.endTransaction();
    }

    Log.d("TAGAB", "in Transaction? " + mDB.inTransaction());
    return result;
}

在LogCat中:

"TAGAB" in Transaction? true

最初执行更新,如果我 select 行,我会收到具有新状态的行。

应用程序关闭并重新启动后,行再次具有旧状态!
事务回滚了吗?如果是这样,为什么? 数据库定义为单例。

private SQLiteDatabase mDB;
private static DatabaseAdapter INSTANCE;

"inTransaction true" 提示您有一个外部事务,其中嵌套了此内部事务。

在正在进行的事务中查询数据时一切正常。

Android sqlite 仅部分支持嵌套事务。最外层事务发生的情况决定了所有嵌套事务发生的情况。

在您的情况下,最外层事务被回滚,嵌套事务中的任何更改也被回滚。