SQLiteException"不能提交 - 没有事务处于活动"同时与CONFLICT_REPLACE插入事务、SQLiteException、QUOT、CONFLICT_REPL

2023-09-06 02:18:00 作者:肩并肩一起走

我有一些麻烦来更新我的资料库。

I have some trouble updating my database.

这是日志:

12-02 16:18:57.502: D/Data Update(21218): Start updating databases
12-02 16:18:57.502: D/Data Update(21218): update size: 5
12-02 16:18:57.502: D/Data Update(21218): updating table cemeteries
12-02 14:28:51.877: I/SqliteDatabaseCpp(18826): sqlite returned: error code = 1802, msg = statement aborts at 13: [INSERT OR REPLACE  INTO cemeteries(id,name) VALUES (?,?)] , db=/data/data/de.l_one.app.shaufelv14/databases/poidatabase
12-02 14:28:51.877: E/SQLiteStatementCpp(18826): native_execute (step): errno = 2, error message = No such file or directory, handle = 0xdc0b70
12-02 14:28:51.877: I/SqliteDatabaseCpp(18826): sqlite returned: error code = 1, msg = statement aborts at 2: [COMMIT;] cannot commit - no transaction is active, db=/data/data/de.l_one.app.shaufelv14/databases/poidatabase
12-02 14:28:51.887: E/Data Update(18826): Update failed
12-02 14:28:51.887: E/Data Update(18826): android.database.sqlite.SQLiteException: cannot commit - no transaction is active
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteStatement.native_executeSql(Native Method)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:90)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2006)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1946)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:764)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:273)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:115)
12-02 14:28:51.887: E/Data Update(18826):   at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1807)
12-02 14:28:51.887: E/Data Update(18826):   at de.l_one.app.shaufelv14.DataUpdater.update(DataUpdater.java:102)
12-02 14:28:51.887: E/Data Update(18826):   at de.l_one.app.shaufelv14.MainActivity$5.run(MainActivity.java:104)

这是在code我用插入新的数据:

This is the code I use to insert new Data:

int updateSize = 0;

// cvs is an ArrayList<ContentValues> array with each entry holding 
// the new values for a certain table
// I know I could use a Map but let's change one thing after another

for(ArrayList<ContentValues> list : cvs)
    updateSize += list.size();

Log.d(DEBUG_TAG, "Start updating databases");
Log.d(DEBUG_TAG, "update size: "+updateSize);

if(updateSize > 0) {

    dbHelper = ShaufelDatabaseHelper.getInstance(context);
    connection = dbHelper.getWritableDatabase();

    for(int i=0; i<cvs.length; i++) {
        String table;
        switch(i) {
            case 0: table = "cemeteries"; break;
            case 1: table = "customers"; break;
            case 2: table = "graves"; break;
            case 3: table = "orders"; break;
            case 4: table = "plants"; break;
            case 5: table = "plantevents"; break;
            case 6: table = "services"; break;
            case 7: table = "serviceevents"; break;
            default: throw new RuntimeException("wtf");
        }
        Log.d(DEBUG_TAG, "updating table "+table);

        for(ContentValues cv: cvs[i]) {
            // replace updated values, insert new ones
            connection.insertWithOnConflict(table, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
        }
    }
}

奇怪的约,这是该异常没有抛出每次。它更像是这样的:

The strange thing about this is that the Exception is not thrown everytime. It's more like this:

如果你启动应用程序并登录,更新工作。如果再注销并重新登录的(不关闭应用程序)的更新再次发生,但这次例外。 如果您关闭该应用程序(不只是pressing家,但迫使密切配合Android系统),它会再次合作,直到注销并重新。照片 这些更新都包含相同的数据(我们正在测试这个东西),它是由同一个code,但它仅一半的时间。

If you start the App and log in, the Update works. If you then log out and back in (without closing the app) the update happens again but this time with the Exception. If you close the app (not just pressing home but forcing a close with the android system) it will work again until you log out and back in. The updates all contain the same data (we are currently testing this stuff) and it's run by the same code and yet it works only half the time.

这是在HTC感觉运行在Android上4.0.3。

This is run on Android 4.0.3 on a HTC Sensation.

推荐答案

我觉得我有同样的问题,我解决了它,因为我在编辑II解释:

I think I had the same problem and I solved it as I explain at the EDIT II:

android.database.sqlite.SQLiteDiskIOException:磁盘I / O错误(code 1802)/打开的游标?