diff options
-rw-r--r-- | src/Components/UnionKeyword.php | 6 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50000.php | 1 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50100.php | 1 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50500.php | 1 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50600.php | 1 | ||||
-rw-r--r-- | src/Contexts/ContextMySql50700.php | 1 | ||||
-rw-r--r-- | src/Parser.php | 20 | ||||
-rw-r--r-- | src/Statement.php | 2 | ||||
-rw-r--r-- | src/Statements/SelectStatement.php | 2 | ||||
-rw-r--r-- | tools/contexts/_common.txt | 1 |
10 files changed, 25 insertions, 11 deletions
diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php index d1a1ef5..6286cd0 100644 --- a/src/Components/UnionKeyword.php +++ b/src/Components/UnionKeyword.php @@ -31,6 +31,10 @@ class UnionKeyword extends Component */ public static function build($component, array $options = array()) { - return implode(' UNION ', $component); + $tmp = array(); + foreach ($component as $component) { + $tmp[] = $component[0] . ' ' . $component[1]; + } + return implode(' ', $tmp); } } diff --git a/src/Contexts/ContextMySql50000.php b/src/Contexts/ContextMySql50000.php index c87b2c0..ceedd17 100644 --- a/src/Contexts/ContextMySql50000.php +++ b/src/Contexts/ContextMySql50000.php @@ -146,6 +146,7 @@ class ContextMySql50000 extends Context 'GROUP BY' => 7, 'NOT NULL' => 7, 'ORDER BY' => 7, 'SET NULL' => 7, 'AND CHAIN' => 7, 'FULL JOIN' => 7, 'IF EXISTS' => 7, 'LEFT JOIN' => 7, 'LESS THAN' => 7, 'NO ACTION' => 7, 'ON DELETE' => 7, 'ON UPDATE' => 7, + 'UNION ALL' => 7, 'INNER JOIN' => 7, 'LINEAR KEY' => 7, 'NO RELEASE' => 7, 'OR REPLACE' => 7, 'RIGHT JOIN' => 7, 'LINEAR HASH' => 7, diff --git a/src/Contexts/ContextMySql50100.php b/src/Contexts/ContextMySql50100.php index 3e6cbed..07ea04a 100644 --- a/src/Contexts/ContextMySql50100.php +++ b/src/Contexts/ContextMySql50100.php @@ -159,6 +159,7 @@ class ContextMySql50100 extends Context 'GROUP BY' => 7, 'NOT NULL' => 7, 'ORDER BY' => 7, 'SET NULL' => 7, 'AND CHAIN' => 7, 'FULL JOIN' => 7, 'IF EXISTS' => 7, 'LEFT JOIN' => 7, 'LESS THAN' => 7, 'NO ACTION' => 7, 'ON DELETE' => 7, 'ON UPDATE' => 7, + 'UNION ALL' => 7, 'INNER JOIN' => 7, 'LINEAR KEY' => 7, 'NO RELEASE' => 7, 'OR REPLACE' => 7, 'RIGHT JOIN' => 7, 'LINEAR HASH' => 7, diff --git a/src/Contexts/ContextMySql50500.php b/src/Contexts/ContextMySql50500.php index 1c67329..a56ba1b 100644 --- a/src/Contexts/ContextMySql50500.php +++ b/src/Contexts/ContextMySql50500.php @@ -164,6 +164,7 @@ class ContextMySql50500 extends Context 'GROUP BY' => 7, 'NOT NULL' => 7, 'ORDER BY' => 7, 'SET NULL' => 7, 'AND CHAIN' => 7, 'FULL JOIN' => 7, 'IF EXISTS' => 7, 'LEFT JOIN' => 7, 'LESS THAN' => 7, 'NO ACTION' => 7, 'ON DELETE' => 7, 'ON UPDATE' => 7, + 'UNION ALL' => 7, 'INNER JOIN' => 7, 'LINEAR KEY' => 7, 'NO RELEASE' => 7, 'OR REPLACE' => 7, 'RIGHT JOIN' => 7, 'LINEAR HASH' => 7, diff --git a/src/Contexts/ContextMySql50600.php b/src/Contexts/ContextMySql50600.php index b80e756..481cff5 100644 --- a/src/Contexts/ContextMySql50600.php +++ b/src/Contexts/ContextMySql50600.php @@ -170,6 +170,7 @@ class ContextMySql50600 extends Context 'GROUP BY' => 7, 'NOT NULL' => 7, 'ORDER BY' => 7, 'SET NULL' => 7, 'AND CHAIN' => 7, 'FULL JOIN' => 7, 'IF EXISTS' => 7, 'LEFT JOIN' => 7, 'LESS THAN' => 7, 'NO ACTION' => 7, 'ON DELETE' => 7, 'ON UPDATE' => 7, + 'UNION ALL' => 7, 'INNER JOIN' => 7, 'LINEAR KEY' => 7, 'NO RELEASE' => 7, 'OR REPLACE' => 7, 'RIGHT JOIN' => 7, 'LINEAR HASH' => 7, diff --git a/src/Contexts/ContextMySql50700.php b/src/Contexts/ContextMySql50700.php index bdc1803..14daee2 100644 --- a/src/Contexts/ContextMySql50700.php +++ b/src/Contexts/ContextMySql50700.php @@ -177,6 +177,7 @@ class ContextMySql50700 extends Context 'GROUP BY' => 7, 'NOT NULL' => 7, 'ORDER BY' => 7, 'SET NULL' => 7, 'AND CHAIN' => 7, 'FULL JOIN' => 7, 'IF EXISTS' => 7, 'LEFT JOIN' => 7, 'LESS THAN' => 7, 'NO ACTION' => 7, 'ON DELETE' => 7, 'ON UPDATE' => 7, + 'UNION ALL' => 7, 'INNER JOIN' => 7, 'LINEAR KEY' => 7, 'NO RELEASE' => 7, 'OR REPLACE' => 7, 'RIGHT JOIN' => 7, 'LINEAR HASH' => 7, diff --git a/src/Parser.php b/src/Parser.php index db46e21..c050e42 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -115,6 +115,10 @@ class Parser 'class' => 'SqlParser\\Components\\UnionKeyword', 'field' => 'union', ), + 'UNION ALL' => array( + 'class' => 'SqlParser\\Components\\UnionKeyword', + 'field' => 'union', + ), // Actual clause parsers. 'ALTER' => array( @@ -356,11 +360,11 @@ class Parser $lastStatement = null; /** - * Whether a union is parsed or not. + * Union's type or false for no union. * - * @var bool $inUnion + * @var bool|string $unionType */ - $inUnion = false; + $unionType = false; /** * The index of the last token from the last statement. @@ -417,8 +421,8 @@ class Parser continue; } - if ($token->value === 'UNION') { - $inUnion = true; + if (($token->value === 'UNION') || ($token->value === 'UNION ALL')) { + $unionType = $token->value; continue; } @@ -465,7 +469,7 @@ class Parser $prevLastIdx = $list->idx; // Handles unions. - if (($inUnion) + if ((!empty($unionType)) && ($lastStatement instanceof SelectStatement) && ($statement instanceof SelectStatement) ) { @@ -480,7 +484,7 @@ class Parser * * @var SelectStatement $lastStatement */ - $lastStatement->union[] = $statement; + $lastStatement->union[] = array($unionType, $statement); // if there are no no delimiting brackets, the `ORDER` and // `LIMIT` keywords actually belong to the first statement. @@ -493,7 +497,7 @@ class Parser // union ends. $lastStatement->last = $statement->last; - $inUnion = false; + $unionType = false; continue; } diff --git a/src/Statement.php b/src/Statement.php index a9d4dc8..472d7de 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -251,7 +251,7 @@ abstract class Statement // Unions are parsed by the parser because they represent more than // one statement. - if ($token->value === 'UNION') { + if (($token->value === 'UNION') || ($token->value === 'UNION ALL')) { break; } diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index 4bcbf2d..5d306f0 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -106,7 +106,7 @@ class SelectStatement extends Statement 'LIMIT' => array('LIMIT', 3), 'PROCEDURE' => array('PROCEDURE', 3), 'INTO' => array('INTO', 3), - 'UNION' => array('UNION', 3), + 'UNION' => array('UNION', 1), // These are available only when `UNION` is present. // 'ORDER BY' => array('ORDER BY', 3), // 'LIMIT' => array('LIMIT', 3), diff --git a/tools/contexts/_common.txt b/tools/contexts/_common.txt index 3bb1476..a1139b3 100644 --- a/tools/contexts/_common.txt +++ b/tools/contexts/_common.txt @@ -84,6 +84,7 @@ TIMESTAMP (D) TINYBLOB (D) TINYINT (D) TINYTEXT (D) +UNION ALL UNIQUE (K) UNIQUE INDEX (K) UNIQUE KEY (K) |