diff options
| author | 2015-04-19 22:30:21 -0400 | |
|---|---|---|
| committer | 2015-04-19 22:30:21 -0400 | |
| commit | a308f430f694423064ebc86fd0506c8c6fdb3d93 (patch) | |
| tree | ceacd24fecf92f40980f8d8f3fd169e317c886af /Plugins | |
| parent | a5b034d4a9c44f9bc1e83b01de82530f8fc63013 (diff) | |
Imported Upstream version 3.0.5upstream/3.0.5
Diffstat (limited to 'Plugins')
6 files changed, 53 insertions, 21 deletions
diff --git a/Plugins/DbSqlite2/dbsqlite2.json b/Plugins/DbSqlite2/dbsqlite2.json index 6761faf..c1e1817 100644 --- a/Plugins/DbSqlite2/dbsqlite2.json +++ b/Plugins/DbSqlite2/dbsqlite2.json @@ -2,6 +2,6 @@ "type": "DbPlugin", "title": "SQLite 2", "description": "Provides support for SQLite 2.* databases", - "version": 10002, + "version": 10003, "author": "SalSoft" } diff --git a/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp b/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp index 01351e6..6eb8b21 100644 --- a/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp @@ -9,55 +9,71 @@ FormatCreateTrigger::FormatCreateTrigger(SqliteCreateTrigger* createTrig) : void FormatCreateTrigger::formatInternal() { handleExplainQuery(createTrig); - withKeyword("CREATE"); + + QStringList keywords; + + keywords << "CREATE"; if (createTrig->tempKw) - withKeyword("TEMP"); + keywords << "TEMP"; else if (createTrig->temporaryKw) - withKeyword("TEMPORARY"); + keywords << "TEMPORARY"; - withKeyword("TRIGGER"); + keywords << "TRIGGER"; if (createTrig->ifNotExistsKw) - withKeyword("IF").withKeyword("NOT").withKeyword("EXISTS"); + keywords << "IF" << "NOT" << "EXISTS"; + + QString kwLineUp = keywords.join(" "); + markKeywordLineUp(kwLineUp, TRIGGER_MARK); + + for (const QString& kw : keywords) + withKeyword(kw); if (dialect == Dialect::Sqlite3 && !createTrig->database.isNull()) withId(createTrig->database).withIdDot(); - withId(createTrig->trigger); + withId(createTrig->trigger).withNewLine(); + + FormatStatementEnricher eventStmtEnricher = nullptr; switch (createTrig->eventTime) { case SqliteCreateTrigger::Time::BEFORE: - withKeyword("BEFORE"); + withLinedUpKeyword("BEFORE", TRIGGER_MARK); break; case SqliteCreateTrigger::Time::AFTER: - withKeyword("AFTER"); + withLinedUpKeyword("AFTER", TRIGGER_MARK); break; case SqliteCreateTrigger::Time::INSTEAD_OF: - withKeyword("INSTEAD").withKeyword("OF"); + withLinedUpKeyword("INSTEAD OF", TRIGGER_MARK); break; case SqliteCreateTrigger::Time::null: + eventStmtEnricher = [kwLineUp](FormatStatement* stmt) + { + dynamic_cast<FormatCreateTriggerEvent*>(stmt)->setLineUpKeyword(kwLineUp); + }; break; } - withStatement(createTrig->event).withKeyword("ON"); + withStatement(createTrig->event, QString(), eventStmtEnricher).withNewLine(); + withLinedUpKeyword("ON", TRIGGER_MARK); if (dialect == Dialect::Sqlite2 && !createTrig->database.isNull()) withId(createTrig->database).withIdDot(); - withId(createTrig->table); + withId(createTrig->table).withNewLine(); switch (createTrig->scope) { case SqliteCreateTrigger::Scope::FOR_EACH_ROW: - withKeyword("FOR").withKeyword("EACH").withKeyword("ROW"); + withLinedUpKeyword("FOR EACH", TRIGGER_MARK).withKeyword("ROW").withNewLine(); break; case SqliteCreateTrigger::Scope::FOR_EACH_STATEMENT: - withKeyword("FOR").withKeyword("EACH").withKeyword("STATEMENT"); + withLinedUpKeyword("FOR EACH", TRIGGER_MARK).withKeyword("STATEMENT").withNewLine(); break; case SqliteCreateTrigger::Scope::null: break; } if (createTrig->precondition) - withKeyword("WHEN").withStatement(createTrig->precondition); + withLinedUpKeyword("WHEN", TRIGGER_MARK).withStatement(createTrig->precondition); withNewLine().withKeyword("BEGIN").withNewLine().withIncrIndent().withStatementList(createTrig->queries, QString(), ListSeparator::SEMICOLON).withSemicolon(); withDecrIndent().withKeyword("END").withSemicolon(); @@ -69,21 +85,29 @@ FormatCreateTriggerEvent::FormatCreateTriggerEvent(SqliteCreateTrigger::Event* e { } +void FormatCreateTriggerEvent::setLineUpKeyword(const QString& lineUpKw) +{ + this->lineUpKw = lineUpKw; +} + void FormatCreateTriggerEvent::formatInternal() { + if (!lineUpKw.isNull()) + markKeywordLineUp(lineUpKw, TRIGGER_MARK); + switch (ev->type) { case SqliteCreateTrigger::Event::INSERT: - withKeyword("INSERT"); + withLinedUpKeyword("INSERT", TRIGGER_MARK); break; case SqliteCreateTrigger::Event::UPDATE: - withKeyword("UPDATE"); + withLinedUpKeyword("UPDATE", TRIGGER_MARK); break; case SqliteCreateTrigger::Event::DELETE: - withKeyword("DELETE"); + withLinedUpKeyword("DELETE", TRIGGER_MARK); break; case SqliteCreateTrigger::Event::UPDATE_OF: - withKeyword("UPDATE").withKeyword("OF").withIdList(ev->columnNames); + withLinedUpKeyword("UPDATE OF", TRIGGER_MARK).withIdList(ev->columnNames); break; case SqliteCreateTrigger::Event::null: break; diff --git a/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.h b/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.h index 795c2c7..108a31e 100644 --- a/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.h +++ b/Plugins/SqlEnterpriseFormatter/formatcreatetrigger.h @@ -3,6 +3,7 @@ #include "formatstatement.h" #include "parser/ast/sqlitecreatetrigger.h" +#include "common/global.h" class FormatCreateTrigger : public FormatStatement { @@ -14,18 +15,24 @@ class FormatCreateTrigger : public FormatStatement private: SqliteCreateTrigger* createTrig = nullptr; + + static_char* TRIGGER_MARK = "TRIGGER"; }; class FormatCreateTriggerEvent : public FormatStatement { public: FormatCreateTriggerEvent(SqliteCreateTrigger::Event* ev); + void setLineUpKeyword(const QString& lineUpKw); protected: void formatInternal(); private: SqliteCreateTrigger::Event* ev = nullptr; + QString lineUpKw; + + static_char* TRIGGER_MARK = "TRIGGER"; }; #endif // FORMATCREATETRIGGER_H diff --git a/Plugins/SqlEnterpriseFormatter/formatexpr.cpp b/Plugins/SqlEnterpriseFormatter/formatexpr.cpp index da51ae6..ec5d4d6 100644 --- a/Plugins/SqlEnterpriseFormatter/formatexpr.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatexpr.cpp @@ -107,6 +107,7 @@ void FormatExpr::formatInternal() break; case SqliteExpr::Mode::NOTNULL: { + withStatement(expr->expr1); switch (expr->notNull) { case SqliteExpr::NotNull::ISNULL: diff --git a/Plugins/SqlEnterpriseFormatter/formatstatement.cpp b/Plugins/SqlEnterpriseFormatter/formatstatement.cpp index dfdbb14..e5eaed4 100644 --- a/Plugins/SqlEnterpriseFormatter/formatstatement.cpp +++ b/Plugins/SqlEnterpriseFormatter/formatstatement.cpp @@ -459,7 +459,7 @@ void FormatStatement::handleExplainQuery(SqliteQuery* query) { withKeyword("EXPLAIN"); if (query->queryPlan) - withKeyword("QUERY").withKeyword("PLAN"); + withKeyword("QUERY").withKeyword("PLAN").withNewLine(); } } diff --git a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.json b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.json index 85d6414..c0ba2df 100644 --- a/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.json +++ b/Plugins/SqlEnterpriseFormatter/sqlenterpriseformatter.json @@ -2,6 +2,6 @@ "type": "CodeFormatterPlugin", "title": "SQL Enterprise", "description": "Advanced SQL formatter.", - "version": 10005, + "version": 10006, "author": "SalSoft" } |
