Skip to content

Commit f3bee14

Browse files
sinriibennetch
authored andcommitted
Fix issue #223: can't parse multiple call statements (#224)
Fix for errors when using multiple CALL statements and no arguments/parenthesis. Fixes: #223
1 parent 7bd76e9 commit f3bee14

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/Statement.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PhpMyAdmin\SqlParser;
1111

12+
use PhpMyAdmin\SqlParser\Components\FunctionCall;
1213
use PhpMyAdmin\SqlParser\Components\OptionsArray;
1314

1415
/**
@@ -247,10 +248,10 @@ public function parse(Parser $parser, TokensList $list)
247248
// Unions are parsed by the parser because they represent more than
248249
// one statement.
249250
if (($token->keyword === 'UNION') ||
250-
($token->keyword === 'UNION ALL') ||
251-
($token->keyword === 'UNION DISTINCT') ||
252-
($token->keyword === 'EXCEPT') ||
253-
($token->keyword === 'INTERSECT')
251+
($token->keyword === 'UNION ALL') ||
252+
($token->keyword === 'UNION DISTINCT') ||
253+
($token->keyword === 'EXCEPT') ||
254+
($token->keyword === 'INTERSECT')
254255
) {
255256
break;
256257
}
@@ -356,7 +357,7 @@ public function parse(Parser $parser, TokensList $list)
356357
} elseif ($class === null) {
357358
if ($this instanceof Statements\SelectStatement
358359
&& ($token->value === 'FOR UPDATE'
359-
|| $token->value === 'LOCK IN SHARE MODE')
360+
|| $token->value === 'LOCK IN SHARE MODE')
360361
) {
361362
// Handle special end options in Select statement
362363
// See Statements\SelectStatement::$END_OPTIONS
@@ -367,7 +368,7 @@ public function parse(Parser $parser, TokensList $list)
367368
);
368369
} elseif ($this instanceof Statements\SetStatement
369370
&& ($token->value === 'COLLATE'
370-
|| $token->value === 'DEFAULT')
371+
|| $token->value === 'DEFAULT')
371372
) {
372373
// Handle special end options in SET statement
373374
// See Statements\SetStatement::$END_OPTIONS
@@ -398,6 +399,13 @@ public function parse(Parser $parser, TokensList $list)
398399
}
399400

400401
$this->after($parser, $list, $token);
402+
403+
// #223 Here may make a patch, if last is delimiter, back one
404+
if ((new $class()) instanceof FunctionCall) {
405+
if ($list->offsetGet($list->idx)->type === Token::TYPE_DELIMITER) {
406+
--$list->idx;
407+
}
408+
}
401409
}
402410

403411
// This may be corrected by the parser.
@@ -500,8 +508,8 @@ public function validateClauseOrder($parser, $list)
500508
if ($clauseStartIdx !== -1
501509
&& $this instanceof Statements\SelectStatement
502510
&& ($clauseType === 'FORCE'
503-
|| $clauseType === 'IGNORE'
504-
|| $clauseType === 'USE')
511+
|| $clauseType === 'IGNORE'
512+
|| $clauseType === 'USE')
505513
) {
506514
// TODO: ordering of clauses in a SELECT statement with
507515
// Index hints is not supported

src/Statements/CallStatement.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@ class CallStatement extends Statement
3030
* @var FunctionCall
3131
*/
3232
public $call;
33+
34+
/**
35+
* Build statement for CALL.
36+
*
37+
* @return string
38+
*/
39+
public function build()
40+
{
41+
return "CALL " . $this->call->name . "(" . ($this->call->parameters ? implode(",", $this->call->parameters->raw) : "") . ")";
42+
}
3343
}

0 commit comments

Comments
 (0)