diff --git a/src/Statement.php b/src/Statement.php index 6eb42c748..0ed6b8ba6 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\SqlParser; +use PhpMyAdmin\SqlParser\Components\FunctionCall; use PhpMyAdmin\SqlParser\Components\OptionsArray; /** @@ -247,10 +248,10 @@ public function parse(Parser $parser, TokensList $list) // Unions are parsed by the parser because they represent more than // one statement. if (($token->keyword === 'UNION') || - ($token->keyword === 'UNION ALL') || - ($token->keyword === 'UNION DISTINCT') || - ($token->keyword === 'EXCEPT') || - ($token->keyword === 'INTERSECT') + ($token->keyword === 'UNION ALL') || + ($token->keyword === 'UNION DISTINCT') || + ($token->keyword === 'EXCEPT') || + ($token->keyword === 'INTERSECT') ) { break; } @@ -356,7 +357,7 @@ public function parse(Parser $parser, TokensList $list) } elseif ($class === null) { if ($this instanceof Statements\SelectStatement && ($token->value === 'FOR UPDATE' - || $token->value === 'LOCK IN SHARE MODE') + || $token->value === 'LOCK IN SHARE MODE') ) { // Handle special end options in Select statement // See Statements\SelectStatement::$END_OPTIONS @@ -367,7 +368,7 @@ public function parse(Parser $parser, TokensList $list) ); } elseif ($this instanceof Statements\SetStatement && ($token->value === 'COLLATE' - || $token->value === 'DEFAULT') + || $token->value === 'DEFAULT') ) { // Handle special end options in SET statement // See Statements\SetStatement::$END_OPTIONS @@ -398,6 +399,13 @@ public function parse(Parser $parser, TokensList $list) } $this->after($parser, $list, $token); + + // #223 Here may make a patch, if last is delimiter, back one + if ((new $class()) instanceof FunctionCall) { + if ($list->offsetGet($list->idx)->type === Token::TYPE_DELIMITER) { + --$list->idx; + } + } } // This may be corrected by the parser. @@ -500,8 +508,8 @@ public function validateClauseOrder($parser, $list) if ($clauseStartIdx !== -1 && $this instanceof Statements\SelectStatement && ($clauseType === 'FORCE' - || $clauseType === 'IGNORE' - || $clauseType === 'USE') + || $clauseType === 'IGNORE' + || $clauseType === 'USE') ) { // TODO: ordering of clauses in a SELECT statement with // Index hints is not supported diff --git a/src/Statements/CallStatement.php b/src/Statements/CallStatement.php index 51f1011c3..00cb95c6d 100644 --- a/src/Statements/CallStatement.php +++ b/src/Statements/CallStatement.php @@ -30,4 +30,14 @@ class CallStatement extends Statement * @var FunctionCall */ public $call; + + /** + * Build statement for CALL. + * + * @return string + */ + public function build() + { + return "CALL " . $this->call->name . "(" . ($this->call->parameters ? implode(",", $this->call->parameters->raw) : "") . ")"; + } }