diff options
| author | 2014-12-06 17:33:25 -0500 | |
|---|---|---|
| committer | 2014-12-06 17:33:25 -0500 | |
| commit | 7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch) | |
| tree | a35c14143716e1f2c98f808c81f89426045a946f /Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp')
| -rw-r--r-- | Plugins/SqlEnterpriseFormatter/formatforeignkey.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
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; + } +} |
