aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp b/SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp
index 819d222..b2f46e5 100644
--- a/SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp
+++ b/SQLiteStudio3/coreSQLiteStudio/sqlfileexecutor.cpp
@@ -26,17 +26,22 @@ void SqlFileExecutor::execSqlFromFile(Db* db, const QString& filePath, bool igno
return;
}
- fkWasEnabled = db->exec("PRAGMA foreign_keys")->getSingleCell().toBool();
- if (fkWasEnabled)
- {
- SqlQueryPtr res = db->exec("PRAGMA foreign_keys = 0");
- if (res->isError())
- {
- qDebug() << "Failed to temporarily disable foreign keys enforcement:" << db->getErrorText();
- emit execEnded();
- return;
- }
- }
+ // #4871 is caused by this. On one hand it doesn't make sense to disable FK for script execution
+ // (after all we're trying to execute script just like from SQL Editor, but we do it directly from file),
+ // but on the other hand, it was introduced probably for some reason. It's kept commented for now to see
+ // if good reason for it reappears. It's a subject for removal in future (until end of 2025).
+ //
+ // fkWasEnabled = db->exec("PRAGMA foreign_keys")->getSingleCell().toBool();
+ // if (fkWasEnabled)
+ // {
+ // SqlQueryPtr res = db->exec("PRAGMA foreign_keys = 0");
+ // if (res->isError())
+ // {
+ // qDebug() << "Failed to temporarily disable foreign keys enforcement:" << db->getErrorText();
+ // emit execEnded();
+ // return;
+ // }
+ // }
// Exec file
executionInProgress = 1;
@@ -113,12 +118,14 @@ void SqlFileExecutor::execInThread()
QList<QPair<QString, QString>> errors = executeFromStream(stream, executed, attemptedExecutions, ok, fileSize);
int millis = timer.elapsed();
- if (fkWasEnabled)
- {
- SqlQueryPtr res = db->exec("PRAGMA foreign_keys = 1");
- if (res->isError())
- qDebug() << "Failed to restore foreign keys enforcement after execution SQL from file:" << res->getErrorText();
- }
+ // See comment about fkWasEnabled above.
+ //
+ // if (fkWasEnabled)
+ // {
+ // SqlQueryPtr res = db->exec("PRAGMA foreign_keys = 1");
+ // if (res->isError())
+ // qDebug() << "Failed to restore foreign keys enforcement after execution SQL from file:" << res->getErrorText();
+ // }
if (executionInProgress.loadAcquire())
{
@@ -215,7 +222,7 @@ bool SqlFileExecutor::shouldSkipQuery(const QString& sql)
if (sql.trimmed().isEmpty() || !db->isComplete(sql))
return true;
- QString upper = sql.toUpper().trimmed().split("\n").last().trimmed();
+ QString upper = sql.toUpper().trimmed();
return (upper.startsWith("BEGIN") ||
upper.startsWith("COMMIT") ||
upper.startsWith("ROLLBACK") ||