diff options
| author | 2015-04-19 22:30:43 -0400 | |
|---|---|---|
| committer | 2015-04-19 22:30:43 -0400 | |
| commit | 094918f048c81474b22f9ba2940c96dc4033d753 (patch) | |
| tree | 2b89c77ad7dc9c55e9ba383f23f9f25b82df358e /Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp | |
| parent | 640fff60ceecde402131937dddb3458f7a003e9c (diff) | |
| parent | a308f430f694423064ebc86fd0506c8c6fdb3d93 (diff) | |
Merge tag 'upstream/3.0.5'
Upstream version 3.0.5
# gpg: Signature made Sun 19 Apr 2015 10:30:41 PM EDT using RSA key ID EBE9BD91
# gpg: Good signature from "Unit 193 <unit193@gmail.com>"
# gpg: aka "Unit 193 <unit193@ninthfloor.org>"
# gpg: aka "Unit 193 <unit193@ubuntu.com>"
# gpg: aka "Unit 193 <unit193@ninthfloor.com>"
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp')
| -rw-r--r-- | Plugins/SqlEnterpriseFormatter/formatcreatetrigger.cpp | 60 |
1 files changed, 42 insertions, 18 deletions
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; |
