diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2015-07-25 14:19:28 +0300 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2015-07-25 14:19:28 +0300 |
commit | 6e335616597277d0687bd036fc9acc05386369a0 (patch) | |
tree | a8ee43ace199160a54eceb04f0f26fa25117d42d /src/Utils/Query.php | |
parent | fc390a8d2af884f5f81dd313687046932a833b2e (diff) | |
download | sql-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.php | 11 |
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; |