簡體   English   中英

SQLite 事務未提交

[英]SQLite transaction not committed

我在我的應用程序中使用 SQLite。
數據庫工作正常。
我可以插入、選擇和更新行,但在這種情況下,事務未提交。

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

更新最初是執行的,如果我選擇行,我會收到具有新狀態的行。

應用程序關閉並再次啟動后,行再次具有舊狀態!
事務是否回滾? 如果是這樣,為什么? 數據庫被定義為單例。

private SQLiteDatabase mDB;
private static DatabaseAdapter INSTANCE;

“inTransaction true”提示您有一個外部事務,該內部事務嵌套在其中。

在正在進行的事務中查詢數據時,一切正常。

Android sqlite 僅部分支持嵌套事務。 最外層事務的情況決定了所有嵌套事務的情況。

在您的情況下,最外層事務會回滾,嵌套事務中的任何更改也會回滾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM