aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatexpr.cpp')
-rw-r--r--Plugins/SqlEnterpriseFormatter/formatexpr.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/Plugins/SqlEnterpriseFormatter/formatexpr.cpp b/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
index b1a36b5..e79995f 100644
--- a/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
+++ b/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
@@ -6,6 +6,8 @@
#include "parser/ast/sqliteraise.h"
#include "sqlenterpriseformatter.h"
+QRegularExpression FormatExpr::WORD_ONLY_RE = QRegularExpression("^[a-zA-Z]+$");
+
FormatExpr::FormatExpr(SqliteExpr* expr) :
expr(expr)
{
@@ -51,7 +53,11 @@ void FormatExpr::formatInternal()
{
// Operator can be a keyword
QString opStr = cfg->SqlEnterpriseFormatter.UppercaseKeywords.get() ? expr->unaryOp.toUpper() : expr->unaryOp.toLower();
- withOperator(opStr, FormatToken::Flag::NO_SPACE_BEFORE|FormatToken::Flag::NO_SPACE_AFTER);
+ if (WORD_ONLY_RE.match(opStr).hasMatch())
+ withKeyword(opStr);
+ else
+ withOperator(opStr, FormatToken::Flag::NO_SPACE_AFTER);
+
withStatement(expr->expr1, "unaryOp");
break;
}
@@ -148,6 +154,11 @@ void FormatExpr::formatInternal()
withKeyword("BETWEEN").withStatement(expr->expr2, "between1").withKeyword("AND").withStatement(expr->expr3, "between2");
break;
}
+ case SqliteExpr::Mode::ROW_VALUE:
+ {
+ withParExprLeft().withStatementList(expr->exprList, FormatToken::Flag::NO_NEWLINE_AFTER).withParExprRight();
+ break;
+ }
case SqliteExpr::Mode::IN:
{
withStatement(expr->expr1);
@@ -183,22 +194,34 @@ void FormatExpr::formatInternal()
withStatement(expr->expr1, "case");
bool then = false;
- foreach (SqliteExpr* expr, expr->exprList)
+ for (SqliteExpr* innerExpr : expr->exprList)
{
if (then)
withKeyword("THEN");
else
withKeyword("WHEN");
- withIncrIndent("case");
- withStatement(expr);
+ if (expr->expr1)
+ withIncrIndent("case");
+ else
+ withIncrIndent();
+
+ withStatement(innerExpr);
withDecrIndent();
then = !then;
}
if (expr->expr2)
- withKeyword("ELSE").withIncrIndent("case").withStatement(expr->expr2).withDecrIndent();
+ {
+ withKeyword("ELSE");
+ if (expr->expr1)
+ withIncrIndent("case");
+ else
+ withIncrIndent();
+
+ withStatement(expr->expr2).withDecrIndent();
+ }
withKeyword("END");
break;