Index: src/vdbeaux.c ================================================================== --- src/vdbeaux.c +++ src/vdbeaux.c @@ -2141,14 +2141,21 @@ ** must be SAVEPOINT_RELEASE. Hence the NEVER(p->rc==SQLITE_OK) in ** the following code. */ if( eStatementOp ){ rc = sqlite3VdbeCloseStatement(p, eStatementOp); - if( rc && (NEVER(p->rc==SQLITE_OK) || p->rc==SQLITE_CONSTRAINT) ){ - p->rc = rc; - sqlite3DbFree(db, p->zErrMsg); - p->zErrMsg = 0; + if( rc ){ + assert( eStatementOp==SAVEPOINT_ROLLBACK ); + if( NEVER(p->rc==SQLITE_OK) || p->rc==SQLITE_CONSTRAINT ){ + p->rc = rc; + sqlite3DbFree(db, p->zErrMsg); + p->zErrMsg = 0; + } + invalidateCursorsOnModifiedBtrees(db); + sqlite3RollbackAll(db); + sqlite3CloseSavepoints(db); + db->autoCommit = 1; } } /* If this was an INSERT, UPDATE or DELETE and no statement transaction ** has been rolled back, update the database connection change-counter.