aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-12-17 07:06:30 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-12-17 07:06:30 -0500
commit1fdc150116cad39aae5c5da407c3312b47a59e3a (patch)
tree123c79a4d7ad2d45781ba03ce939f7539fb428d8 /Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp
parentfeda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff)
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp')
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp b/Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp
new file mode 100644
index 0000000..5808af4
--- /dev/null
+++ b/Plugins/SqlEnterpriseFormatter/formatwindowdefinition.cpp
@@ -0,0 +1,91 @@
+#include "formatwindowdefinition.h"
+#include "parser/ast/sqliteexpr.h"
+#include "parser/ast/sqliteorderby.h"
+
+FormatWindowDefinition::FormatWindowDefinition(SqliteWindowDefinition* windowDef) :
+ windowDef(windowDef)
+{
+}
+
+void FormatWindowDefinition::formatInternal()
+{
+ withId(windowDef->name).withKeyword("AS").withParExprLeft().withStatement(windowDef->window).withParExprRight();
+}
+
+FormatWindowDefinitionWindow::FormatWindowDefinitionWindow(SqliteWindowDefinition::Window* window) :
+ window(window)
+{
+}
+
+void FormatWindowDefinitionWindow::formatInternal()
+{
+ if (!window->name.isNull())
+ withId(window->name);
+
+ switch (window->mode)
+ {
+ case SqliteWindowDefinition::Window::Mode::PARTITION_BY:
+ withKeyword("PARTITION").withKeyword("BY").withStatementList(window->exprList);
+ break;
+ case SqliteWindowDefinition::Window::Mode::ORDER_BY:
+ break;
+ case SqliteWindowDefinition::Window::Mode::null:
+ break;
+ }
+
+ if (window->orderBy.size() > 0)
+ withKeyword("ORDER").withKeyword("BY").withStatementList(window->orderBy);
+
+ if (window->frame)
+ withStatement(window->frame);
+}
+
+FormatWindowDefinitionWindowFrame::FormatWindowDefinitionWindowFrame(SqliteWindowDefinition::Window::Frame* frame) :
+ frame(frame)
+{
+}
+
+void FormatWindowDefinitionWindowFrame::formatInternal()
+{
+ if (frame->rangeOrRows != SqliteWindowDefinition::Window::Frame::RangeOrRows::null)
+ withKeyword(SqliteWindowDefinition::Window::Frame::fromRangeOrRows(frame->rangeOrRows));
+
+ if (frame->endBound)
+ withKeyword("BETWEEN").withStatement(frame->startBound).withKeyword("AND").withStatement(frame->endBound);
+ else
+ withStatement(frame->startBound);
+
+ if (frame->exclude != SqliteWindowDefinition::Window::Frame::Exclude::null)
+ {
+ withKeyword("EXCLUDE");
+ for (const QString& kw : SqliteWindowDefinition::Window::Frame::fromExclude(frame->exclude).split(" "))
+ withKeyword(kw);
+ }
+}
+
+FormatWindowDefinitionWindowFrameBound::FormatWindowDefinitionWindowFrameBound(SqliteWindowDefinition::Window::Frame::Bound* bound) :
+ bound(bound)
+{
+}
+
+void FormatWindowDefinitionWindowFrameBound::formatInternal()
+{
+ switch (bound->type)
+ {
+ case SqliteWindowDefinition::Window::Frame::Bound::Type::UNBOUNDED_PRECEDING:
+ withKeyword("UNBOUNDED").withKeyword("PRECEDING");
+ break;
+ case SqliteWindowDefinition::Window::Frame::Bound::Type::UNBOUNDED_FOLLOWING:
+ withKeyword("UNBOUNDED").withKeyword("FOLLOWING");
+ break;
+ case SqliteWindowDefinition::Window::Frame::Bound::Type::EXPR_PRECEDING:
+ withStatement(bound->expr).withKeyword("PRECEDING");
+ break;
+ case SqliteWindowDefinition::Window::Frame::Bound::Type::EXPR_FOLLOWING:
+ withStatement(bound->expr).withKeyword("FOLLOWING");
+ break;
+ case SqliteWindowDefinition::Window::Frame::Bound::Type::CURRENT_ROW:
+ withKeyword("CURRENT").withKeyword("ROW");
+ break;
+ }
+}