diff options
author | Michal Čihař <michal@cihar.com> | 2017-03-30 16:36:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-30 16:36:25 +0200 |
commit | 7a45d9ff6654b0a09fb4068d3c78b83f1fc9a4b8 (patch) | |
tree | 9b412832e78e62a08dfc00691ced004892e94b2d /src | |
parent | 59d8a581eb843b0c319918bcf893acf890d4cae3 (diff) | |
parent | cfd489b11c9e3b3de62b07c875927c8b8ab653c4 (diff) | |
download | sql-parser-7a45d9ff6654b0a09fb4068d3c78b83f1fc9a4b8.zip sql-parser-7a45d9ff6654b0a09fb4068d3c78b83f1fc9a4b8.tar.gz sql-parser-7a45d9ff6654b0a09fb4068d3c78b83f1fc9a4b8.tar.bz2 |
Merge pull request #145 from devenbansod/fix_144
Fix parsing of DELETE clauses with JOINs
Diffstat (limited to 'src')
-rw-r--r-- | src/Statements/DeleteStatement.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index f4c1e61..90fd26f 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -10,6 +10,7 @@ use PhpMyAdmin\SqlParser\Components\ArrayObj; use PhpMyAdmin\SqlParser\Components\Condition; use PhpMyAdmin\SqlParser\Components\Expression; use PhpMyAdmin\SqlParser\Components\ExpressionArray; +use PhpMyAdmin\SqlParser\Components\JoinKeyword; use PhpMyAdmin\SqlParser\Components\Limit; use PhpMyAdmin\SqlParser\Components\OptionsArray; use PhpMyAdmin\SqlParser\Components\OrderKeyword; @@ -86,6 +87,14 @@ class DeleteStatement extends Statement public $from; /** + * Joins. + * + * @var JoinKeyword[] + */ + public $join; + + + /** * Tables used as sources for this statement. * * @var Expression[] @@ -140,6 +149,9 @@ class DeleteStatement extends Statement if ($this->from != null && count($this->from) > 0) { $ret .= ' FROM ' . ExpressionArray::build($this->from); } + if ($this->join != null && count($this->join) > 0) { + $ret .= ' ' . JoinKeyword::build($this->join); + } if ($this->using != null && count($this->using) > 0) { $ret .= ' USING ' . ExpressionArray::build($this->using); } @@ -220,6 +232,7 @@ class DeleteStatement extends Statement ) { ++$list->idx; // Skip 'FROM' $this->from = ExpressionArray::parse($parser, $list); + $state = 2; } else { $this->columns = ExpressionArray::parse($parser, $list); @@ -236,6 +249,7 @@ class DeleteStatement extends Statement ) { ++$list->idx; // Skip 'FROM' $this->from = ExpressionArray::parse($parser, $list); + $state = 2; } else { $parser->error('Unexpected token.', $token); @@ -243,6 +257,13 @@ class DeleteStatement extends Statement } } elseif ($state === 2) { if ($token->type === Token::TYPE_KEYWORD + && stripos($token->keyword, 'JOIN') !== false + ) { + ++$list->idx; + $this->join = JoinKeyword::parse($parser, $list); + + // remain in state = 2 + } elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'USING' ) { ++$list->idx; // Skip 'USING' |