From 0d5bf185ee743843773d79a69233ff04e3c7147b Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Tue, 17 Nov 2015 22:12:00 +0200 Subject: [PATCH] Fixes #11664. Online syntax verifier bug - "IF" on SELECT statement Fixes #11665. Format breaks query with COUNT() Update sql-parser to udan11/sql-parser@5621792c48cc6756508379ba941cb8c271df24bd (v3.0.7). Signed-off-by: Dan Ungureanu --- .../sql-parser/src/Components/ExpressionArray.php | 1 + libraries/sql-parser/src/Utils/Formatter.php | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/sql-parser/src/Components/ExpressionArray.php b/libraries/sql-parser/src/Components/ExpressionArray.php index 5c84dcd95053..b05ccc1838fe 100644 --- a/libraries/sql-parser/src/Components/ExpressionArray.php +++ b/libraries/sql-parser/src/Components/ExpressionArray.php @@ -70,6 +70,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = if (($token->type === Token::TYPE_KEYWORD) && ($token->flags & Token::FLAG_KEYWORD_RESERVED) + && ((~$token->flags & Token::FLAG_KEYWORD_FUNCTION)) && ($token->value !== 'DUAL') ) { // No keyword is expected. diff --git a/libraries/sql-parser/src/Utils/Formatter.php b/libraries/sql-parser/src/Utils/Formatter.php index ea4b419ff4b1..7ff13463f67f 100644 --- a/libraries/sql-parser/src/Utils/Formatter.php +++ b/libraries/sql-parser/src/Utils/Formatter.php @@ -304,7 +304,9 @@ public function formatList($list) if (($this->options['parts_newline']) && (!$formattedOptions) && (empty(self::$INLINE_CLAUSES[$lastClause])) - && ($curr->type != Token::TYPE_KEYWORD) + && (($curr->type !== Token::TYPE_KEYWORD) + || (($curr->type === Token::TYPE_KEYWORD) + && ($curr->flags & Token::FLAG_KEYWORD_FUNCTION))) ) { $formattedOptions = true; $lineEnded = true; @@ -334,8 +336,8 @@ public function formatList($list) // Formatting fragments delimited by comma. if (($prev->type === Token::TYPE_OPERATOR) && ($prev->value === ',')) { // Fragments delimited by a comma are broken into multiple - // pieces only if the clause if the clause is not inlined or - // this fragment is between brackets that were on new line. + // pieces only if the clause is not inlined or this fragment + // is between brackets that are on new line. if (((empty(self::$INLINE_CLAUSES[$lastClause])) && ($this->options['parts_newline'])) || (end($blocksLineEndings) === true) @@ -401,8 +403,7 @@ public function formatList($list) $comment = ''; } - // Saving the next token as the one that will be processed during - // the next iteration. + // Iteration finished, consider current token as previous. $prev = $curr; }