From d9aa870e5d509cc7309ab82dd102a937ab58613a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Thu, 9 Feb 2017 04:36:04 -0500 Subject: Imported Upstream version 3.1.1+dfsg1 --- Plugins/SqlEnterpriseFormatter/formatexpr.cpp | 33 +++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'Plugins/SqlEnterpriseFormatter/formatexpr.cpp') 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; -- cgit v1.2.3