savepoint和rollback命令在sqlite android中不起作用

时间:2016-06-02 15:01:35

标签: android database sqlite

在Android中使用Savepoint SQL命令:

 final SQLiteDatabase db = dbHelper.getWritableDatabase();
    db.beginTransaction();
    try{

        String savePointStr = "SAVEPOINT latestFilterConfig";
       db.execSQL(savePointStr);

        db.setTransactionSuccessful();
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        db.endTransaction();

    }

使用Rollback命令:

final SQLiteDatabase db = dbHelper.getWritableDatabase();

        try{
           db.beginTransaction();

            String rollbackStr = ";rollback to savepoint latestFilterConfig";
            db.execSQL(rollbackStr);

            db.setTransactionSuccessful();

    }catch (Exception e){
        e.printStackTrace();
    }finally {
        db.endTransaction();
    }

执行我的rollback命令时,会导致以下异常

android.database.sqlite.SQLiteException: no such savepoint: latestFilterConfig (code 1)

请帮我解决这个问题。我需要回滚到保存点。

1 个答案:

答案 0 :(得分:0)

documentation说:

  

COMMIT命令提交所有未完成的事务,并将事务堆栈留空。

保存点&真实'事务必须正确嵌套。