diff options
| author | 2017-02-09 04:37:26 -0500 | |
|---|---|---|
| committer | 2017-02-09 04:37:26 -0500 | |
| commit | c9d6debf9015b7853c3e061bbc64a555d85e2fcd (patch) | |
| tree | 53341bc57ae9fbad2beb5b6c08d97a68bee0ec8e /Plugins/SqlEnterpriseFormatter/formatexpr.cpp | |
| parent | d5caba2b1f36dc3b92fa705a06097d0597fa2ddd (diff) | |
| parent | d9aa870e5d509cc7309ab82dd102a937ab58613a (diff) | |
Merge tag 'upstream/3.1.1+dfsg1'
Upstream version 3.1.1+dfsg1
# gpg: Signature made Thu 09 Feb 2017 04:37:24 AM EST
# gpg: using RSA key 5001E1B09AA3744B
# gpg: issuer "unit193@ubuntu.com"
# gpg: Good signature from "Unit 193 <unit193@ubuntu.com>" [unknown]
# gpg: aka "Unit 193 <unit193@gmail.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg: There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 8DB3 E586 865D 2B4A 2B18 5A5C 5001 E1B0 9AA3 744B
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatexpr.cpp')
| -rw-r--r-- | Plugins/SqlEnterpriseFormatter/formatexpr.cpp | 33 |
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; |
