summaryrefslogtreecommitdiffstats
path: root/src/Utils/Query.php
diff options
context:
space:
mode:
authorDan Ungureanu <udan1107@gmail.com>2015-07-25 14:19:28 +0300
committerDan Ungureanu <udan1107@gmail.com>2015-07-25 14:19:28 +0300
commit6e335616597277d0687bd036fc9acc05386369a0 (patch)
treea8ee43ace199160a54eceb04f0f26fa25117d42d /src/Utils/Query.php
parentfc390a8d2af884f5f81dd313687046932a833b2e (diff)
downloadsql-parser-6e335616597277d0687bd036fc9acc05386369a0.zip
sql-parser-6e335616597277d0687bd036fc9acc05386369a0.tar.gz
sql-parser-6e335616597277d0687bd036fc9acc05386369a0.tar.bz2
Improved support for UNION.
Diffstat (limited to 'src/Utils/Query.php')
-rw-r--r--src/Utils/Query.php11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Utils/Query.php b/src/Utils/Query.php
index bec402a..1f887ab 100644
--- a/src/Utils/Query.php
+++ b/src/Utils/Query.php
@@ -533,6 +533,14 @@ class Query
*/
$clauses = array_flip(array_keys($statement::$CLAUSES));
+ // This is a cheap fix for `SELECT` statements that contain `UNION`.
+ // Replacing the `ORDER BY` or `LIMIT` clauses should replace the last
+ // clause.
+ if (!empty($statement->union)) {
+ $clauses['ORDER BY'] = count($clauses) + 1;
+ $clauses['LIMIT'] = count($clauses) + 2;
+ }
+
/**
* Lexer used for lexing the clause.
* @var Lexer $lexer
@@ -552,10 +560,9 @@ class Query
$clauseIdx = $clauses[$clauseType];
$firstClauseIdx = $clauseIdx;
-
$lastClauseIdx = $clauseIdx + 1;
- // Determining the behaviour of this function.
+ // Determining the behavior of this function.
if ($type === -1) {
$firstClauseIdx = -1; // Something small enough.
$lastClauseIdx = $clauseIdx - 1;