From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- .../SqlEnterpriseFormatter/formatforeignkey.cpp | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp (limited to 'Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp') diff --git a/Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp b/Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp new file mode 100644 index 0000000..6b28a86 --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp @@ -0,0 +1,78 @@ +#include "formatforeignkey.h" + +FormatForeignKey::FormatForeignKey(SqliteForeignKey* fk) : + fk(fk) +{ +} + +void FormatForeignKey::formatInternal() +{ + withKeyword("REFERENCES").withId(fk->foreignTable); + + if (fk->indexedColumns.size() > 0) + withParExprLeft().withStatementList(fk->indexedColumns).withParExprRight(); + + if (fk->conditions.size() > 0) + { + markAndKeepIndent("constr_conditions").withStatementList(fk->conditions, QString(), ListSeparator::NEW_LINE).withDecrIndent(); + } + + if (fk->deferrable != SqliteDeferrable::null) + { + if (fk->deferrable == SqliteDeferrable::NOT_DEFERRABLE) + withKeyword("NOT").withKeyword("DEFERRABLE"); + else if (fk->deferrable == SqliteDeferrable::DEFERRABLE) + withKeyword("DEFERRABLE"); + + if (fk->initially != SqliteInitially::null) + withKeyword("INITIALLY").withKeyword(sqliteInitially(fk->initially)); + } +} + + +FormatForeignKeyCondition::FormatForeignKeyCondition(SqliteForeignKey::Condition* cond) : + cond(cond) +{ +} + +void FormatForeignKeyCondition::formatInternal() +{ + switch (cond->action) + { + case SqliteForeignKey::Condition::UPDATE: + withKeyword("ON").withKeyword("UPDATE"); + break; + case SqliteForeignKey::Condition::INSERT: + withKeyword("ON").withKeyword("INSERT"); + break; + case SqliteForeignKey::Condition::DELETE: + withKeyword("ON").withKeyword("DELETE"); + break; + case SqliteForeignKey::Condition::MATCH: + withKeyword("MATCH").withId(cond->name); + return; + } + formatReaction(); +} + +void FormatForeignKeyCondition::formatReaction() +{ + switch (cond->reaction) + { + case SqliteForeignKey::Condition::SET_NULL: + withKeyword("SET").withKeyword("NULL"); + break; + case SqliteForeignKey::Condition::SET_DEFAULT: + withKeyword("SET").withKeyword("DEFAULT"); + break; + case SqliteForeignKey::Condition::CASCADE: + withKeyword("CASCADE"); + break; + case SqliteForeignKey::Condition::RESTRICT: + withKeyword("RESTRICT"); + break; + case SqliteForeignKey::Condition::NO_ACTION: + withKeyword("NO").withKeyword("ACTION"); + break; + } +} -- cgit v1.2.3