summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-12-17 22:57:04 +0200
committerDan Ungureanu <udan1107@gmail.com>2015-12-17 22:57:04 +0200
commit8bbff36381ce22c4fd4cb90d56b517d5c1451a77 (patch)
tree4be8225cf2d6645c1d86ce024354ab8a747f662c /src
parent7d64afacbeb598886435bb9e25f0f395d19aee00 (diff)
downloadsql-parser-8bbff36381ce22c4fd4cb90d56b517d5c1451a77.zip
sql-parser-8bbff36381ce22c4fd4cb90d56b517d5c1451a77.tar.gz
sql-parser-8bbff36381ce22c4fd4cb90d56b517d5c1451a77.tar.bz2
Added UNION ALL as a type of UNION.
Diffstat (limited to 'src')
-rw-r--r--src/Components/UnionKeyword.php6
-rw-r--r--src/Contexts/ContextMySql50000.php1
-rw-r--r--src/Contexts/ContextMySql50100.php1
-rw-r--r--src/Contexts/ContextMySql50500.php1
-rw-r--r--src/Contexts/ContextMySql50600.php1
-rw-r--r--src/Contexts/ContextMySql50700.php1
-rw-r--r--src/Parser.php20
-rw-r--r--src/Statement.php2
-rw-r--r--src/Statements/SelectStatement.php2
9 files changed, 24 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),