Skip to content

Commit

Permalink
Add support for MariaDB 10.3 INTERSECT and EXCEPT.
Browse files Browse the repository at this point in the history
Fixes #166

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Aug 30, 2017
1 parent 1c1abcc commit 6ee6fa8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

* Initial support for MariaDB SQL contexts.
* Add support for MariaDB 10.3 INTERSECT and EXCEPT.

## [4.1.10] - 2017-08-21

Expand Down
15 changes: 14 additions & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class Parser extends Core
'field' => 'end_options',
),

'INTERSECT' => array(
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
),
'EXCEPT' => array(
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
),
'UNION' => array(
'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword',
'field' => 'union',
Expand Down Expand Up @@ -427,7 +435,12 @@ public function parse()
continue;
}

if (($token->keyword === 'UNION') || ($token->keyword === 'UNION ALL') || ($token->keyword === 'UNION DISTINCT')) {
if (($token->keyword === 'UNION') ||
($token->keyword === 'UNION ALL') ||
($token->keyword === 'UNION DISTINCT') ||
($token->keyword === 'EXCEPT') ||
($token->keyword === 'INTERSECT')
) {
$unionType = $token->keyword;
continue;
}
Expand Down
7 changes: 6 additions & 1 deletion src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ public function parse(Parser $parser, TokensList $list)

// Unions are parsed by the parser because they represent more than
// one statement.
if (($token->value === 'UNION') || ($token->value === 'UNION ALL') || ($token->value === 'UNION DISTINCT')) {
if (($token->keyword === 'UNION') ||
($token->keyword === 'UNION ALL') ||
($token->keyword === 'UNION DISTINCT') ||
($token->keyword === 'EXCEPT') ||
($token->keyword === 'INTERSECT')
) {
break;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Statements/SelectStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class SelectStatement extends Statement
'LIMIT' => array('LIMIT', 3),
'PROCEDURE' => array('PROCEDURE', 3),
'UNION' => array('UNION', 1),
'EXCEPT' => array('EXCEPT', 1),
'INTERSECT' => array('INTERSECT', 1),
'_END_OPTIONS' => array('_END_OPTIONS', 1),
// These are available only when `UNION` is present.
// 'ORDER BY' => array('ORDER BY', 3),
Expand Down

0 comments on commit 6ee6fa8

Please sign in to comment.