@@ -115,6 +115,10 @@ class Parser
115115 'class ' => 'SqlParser \\Components \\UnionKeyword ' ,
116116 'field ' => 'union ' ,
117117 ),
118+ 'UNION ALL ' => array (
119+ 'class ' => 'SqlParser \\Components \\UnionKeyword ' ,
120+ 'field ' => 'union ' ,
121+ ),
118122
119123 // Actual clause parsers.
120124 'ALTER ' => array (
@@ -356,11 +360,11 @@ public function parse()
356360 $ lastStatement = null ;
357361
358362 /**
359- * Whether a union is parsed or not .
363+ * Union's type or false for no union .
360364 *
361- * @var bool $inUnion
365+ * @var bool|string $unionType
362366 */
363- $ inUnion = false ;
367+ $ unionType = false ;
364368
365369 /**
366370 * The index of the last token from the last statement.
@@ -417,8 +421,8 @@ public function parse()
417421 continue ;
418422 }
419423
420- if ($ token ->value === 'UNION ' ) {
421- $ inUnion = true ;
424+ if (( $ token ->value === 'UNION ' ) || ( $ token -> value === ' UNION ALL ' ) ) {
425+ $ unionType = $ token -> value ;
422426 continue ;
423427 }
424428
@@ -465,7 +469,7 @@ public function parse()
465469 $ prevLastIdx = $ list ->idx ;
466470
467471 // Handles unions.
468- if (($ inUnion )
472+ if ((! empty ( $ unionType ) )
469473 && ($ lastStatement instanceof SelectStatement)
470474 && ($ statement instanceof SelectStatement)
471475 ) {
@@ -480,7 +484,7 @@ public function parse()
480484 *
481485 * @var SelectStatement $lastStatement
482486 */
483- $ lastStatement ->union [] = $ statement ;
487+ $ lastStatement ->union [] = array ( $ unionType , $ statement) ;
484488
485489 // if there are no no delimiting brackets, the `ORDER` and
486490 // `LIMIT` keywords actually belong to the first statement.
@@ -493,7 +497,7 @@ public function parse()
493497 // union ends.
494498 $ lastStatement ->last = $ statement ->last ;
495499
496- $ inUnion = false ;
500+ $ unionType = false ;
497501 continue ;
498502 }
499503
0 commit comments