summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEverstray Jun Sinri Edogawa <e.joshua.s.e@gmail.com>2019-05-07 04:43:55 +0800
committerIsaac Bennetch <bennetch@gmail.com>2019-05-06 16:43:55 -0400
commitf3bee14c29d783778be6dab4ca2b553a625e5baa (patch)
treeb97e879f3f6bd186e88d69b5ab62e26f634ea1ef /src
parent7bd76e952a4faff7a0d8b338fca66d7ff1f82676 (diff)
downloadsql-parser-f3bee14c29d783778be6dab4ca2b553a625e5baa.zip
sql-parser-f3bee14c29d783778be6dab4ca2b553a625e5baa.tar.gz
sql-parser-f3bee14c29d783778be6dab4ca2b553a625e5baa.tar.bz2
Fix issue #223: can't parse multiple call statements (#224)
Fix for errors when using multiple CALL statements and no arguments/parenthesis. Fixes: #223
Diffstat (limited to 'src')
-rw-r--r--src/Statement.php24
-rw-r--r--src/Statements/CallStatement.php10
2 files changed, 26 insertions, 8 deletions
diff --git a/src/Statement.php b/src/Statement.php
index c88722e..439eb13 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\SqlParser;
+use PhpMyAdmin\SqlParser\Components\FunctionCall;
use PhpMyAdmin\SqlParser\Components\OptionsArray;
/**
@@ -247,10 +248,10 @@ abstract class Statement
// 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 @@ abstract class Statement
} 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 @@ abstract class Statement
);
} 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 @@ abstract class Statement
}
$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 @@ abstract class Statement
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 8b02787..570d3a8 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) : "") . ")";
+ }
}