summaryrefslogtreecommitdiffstats
path: root/src/Utils/Query.php
diff options
context:
space:
mode:
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;