aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlEnterpriseFormatter/formatexpr.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2017-02-09 04:36:04 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2017-02-09 04:36:04 -0500
commitd9aa870e5d509cc7309ab82dd102a937ab58613a (patch)
treed92d03d76b5c390b335f1cfd761f1a0b59ec8496 /Plugins/SqlEnterpriseFormatter/formatexpr.cpp
parent68ee4cbcbe424b95969c70346283a9f217f63825 (diff)
Imported Upstream version 3.1.1+dfsg1upstream/3.1.1+dfsg1
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;