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 --- Plugins/SqlEnterpriseFormatter/formatupdate.cpp | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Plugins/SqlEnterpriseFormatter/formatupdate.cpp (limited to 'Plugins/SqlEnterpriseFormatter/formatupdate.cpp') diff --git a/Plugins/SqlEnterpriseFormatter/formatupdate.cpp b/Plugins/SqlEnterpriseFormatter/formatupdate.cpp new file mode 100644 index 0000000..ffc3911 --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/formatupdate.cpp @@ -0,0 +1,47 @@ +#include "formatupdate.h" +#include "parser/ast/sqliteupdate.h" +#include "parser/ast/sqliteexpr.h" +#include "formatwith.h" + +FormatUpdate::FormatUpdate(SqliteUpdate* upd) : + upd(upd) +{ +} + +void FormatUpdate::formatInternal() +{ + if (upd->with) + withStatement(upd->with); + + markKeywordLineUp("UPDATE"); + withKeyword("UPDATE"); + if (upd->onConflict != SqliteConflictAlgo::null) + withKeyword("OR").withKeyword(sqliteConflictAlgo(upd->onConflict)); + + if (!upd->database.isNull()) + withId(upd->database).withIdDot(); + + withId(upd->table); + + if (upd->indexedByKw) + withKeyword("INDEXED").withKeyword("BY").withId(upd->indexedBy); + else if (upd->notIndexedKw) + withKeyword("NOT").withKeyword("INDEXED"); + + withNewLine().withLinedUpKeyword("SET"); + + bool first = true; + foreach (const SqliteUpdate::ColumnAndValue& keyVal, upd->keyValueMap) + { + if (!first) + withListComma(); + + withId(keyVal.first).withOperator("=").withStatement(keyVal.second); + first = false; + } + + if (upd->where) + withNewLine().withLinedUpKeyword("WHERE").withStatement(upd->where); + + withSemicolon(); +} -- cgit v1.2.3