diff options
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp index d54a359..a37f387 100644 --- a/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/windows/viewwindow.cpp @@ -19,6 +19,7 @@ #include "dialogs/ddlpreviewdialog.h" #include "uiconfig.h" #include "services/config.h" +#include "services/codeformatter.h" #include <QPushButton> #include <QProgressBar> #include <QDebug> @@ -407,6 +408,12 @@ void ViewWindow::applyInitialTab() ui->tabWidget->setCurrentIndex(0); } +QString ViewWindow::getCurrentDdl() const +{ + static_qstring(ddlTpl, "CREATE VIEW %1 AS %2"); + return ddlTpl.arg(wrapObjIfNeeded(ui->nameEdit->text(), db->getDialect())).arg(ui->queryEdit->toPlainText()); +} + void ViewWindow::addTrigger() { DbObjectDialogs dialogs(db, this); @@ -653,13 +660,14 @@ void ViewWindow::parseDdl() createView->dialect = db->getDialect(); } originalCreateView = SqliteCreateViewPtr::create(*createView); - originalQuery = originalCreateView->select->detokenize(); + + // Replacing \r\n with \n, cause \r\n can be carried over from version 2.x.x, which did this incorrectly. + originalQuery = originalCreateView->select->detokenize().replace("\r\n", "\n"); } void ViewWindow::updateDdlTab() { - QString ddl = "CREATE VIEW %1 AS %2"; - ui->ddlEdit->setPlainText(ddl.arg(wrapObjIfNeeded(ui->nameEdit->text(), db->getDialect())).arg(ui->queryEdit->toPlainText())); + ui->ddlEdit->setPlainText(FORMATTER->format("sql", getCurrentDdl(), db)); } bool ViewWindow::isModified() const @@ -711,13 +719,22 @@ void ViewWindow::executeStructureChanges() QStringList sqls; QList<bool> sqlMandatoryFlags; - createView->rebuildTokens(); + QString theDdl = getCurrentDdl(); if (!existingView) { - sqls << createView->detokenize(); + sqls << theDdl; } else { + Parser parser(db->getDialect()); + if (!parser.parse(theDdl)) + { + qCritical() << "Could not re-parse the view for executing it:" << parser.getErrorString(); + notifyError(tr("The view code could not be parsed properly for execution. This is a SQLiteStudio's bug. Please report it.")); + return; + } + + createView = parser.getQueries().first().dynamicCast<SqliteCreateView>(); if (viewModifier) delete viewModifier; |
