aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlEnterpriseFormatter/formatupdate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatupdate.cpp')
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatupdate.cpp47
1 files changed, 47 insertions, 0 deletions
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();
+}