From b4e8898dfaad08c4a802cf74372850fde675a89e Mon Sep 17 00:00:00 2001 From: mgrojo Date: Mon, 30 Dec 2019 20:33:33 +0100 Subject: [PATCH] Revert to savepoint when applicable, also after failed statements The end of the function is unified for failed and successful cases, so the savepoint reversion is always made when it has to be. Reported in issue #2073 --- src/RunSql.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/RunSql.cpp b/src/RunSql.cpp index 2a3c802c..62f22adb 100644 --- a/src/RunSql.cpp +++ b/src/RunSql.cpp @@ -157,6 +157,7 @@ bool RunSql::executeNextStatement() queries_left_to_execute = QByteArray(tail); lk.unlock(); + QString error; if (sql3status == SQLITE_OK) { sql3status = sqlite3_step(vm); @@ -227,18 +228,10 @@ bool RunSql::executeNextStatement() case SQLITE_MISUSE: break; default: - QString error = QString::fromUtf8(sqlite3_errmsg(pDb.get())); - releaseDbAccess(); - emit statementErrored(error, execute_current_position, end_of_current_statement_position); - stopExecution(); - return false; + error = QString::fromUtf8(sqlite3_errmsg(pDb.get())); } } else { - QString error = QString::fromUtf8(sqlite3_errmsg(pDb.get())); - releaseDbAccess(); - emit statementErrored(error, execute_current_position, end_of_current_statement_position); - stopExecution(); - return false; + error = QString::fromUtf8(sqlite3_errmsg(pDb.get())); } // Release the database @@ -256,6 +249,12 @@ bool RunSql::executeNextStatement() savepoint_created = false; } + if(!error.isEmpty()) + { + emit statementErrored(error, execute_current_position, end_of_current_statement_position); + stopExecution(); + return false; + } // Update the start position for the next statement and check if we are at // the end of the part we want to execute. If so, stop the execution now. execute_current_position = end_of_current_statement_position;