Skip to content

Commit

Permalink
Fix issue #223: can't parse multiple call statements (#224)
Browse files Browse the repository at this point in the history
Fix for errors when using multiple CALL statements and no arguments/parenthesis.

Fixes: #223
  • Loading branch information
sinri authored and ibennetch committed May 6, 2019
1 parent 7bd76e9 commit f3bee14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace PhpMyAdmin\SqlParser;

use PhpMyAdmin\SqlParser\Components\FunctionCall;
use PhpMyAdmin\SqlParser\Components\OptionsArray;

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/Statements/CallStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) : "") . ")";
}
}

0 comments on commit f3bee14

Please sign in to comment.