File tree Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -457,20 +457,48 @@ public function validateClauseOrder($parser, $list)
457
457
}
458
458
459
459
$ minIdx = -1 ;
460
+
461
+ /**
462
+ * For tracking JOIN clauses in a query
463
+ * 0 - JOIN not found till now
464
+ * 1 - JOIN has been found
465
+ * 2 - A Non-JOIN clause has been found
466
+ * after a previously found JOIN clause
467
+ *
468
+ * @var int $joinStart
469
+ */
470
+ $ joinStart = 0 ;
471
+
472
+ $ error = 0 ;
460
473
foreach ($ clauses as $ clauseType => $ index ) {
461
474
$ clauseStartIdx = Utils \Query::getClauseStartOffset (
462
475
$ this ,
463
476
$ list ,
464
477
$ clauseType
465
478
);
466
479
480
+ // Handle ordering of Multiple Joins in a query
481
+ if ($ clauseStartIdx != -1 ) {
482
+ if ($ joinStart == 0 && stripos ($ clauseType , 'JOIN ' )) {
483
+ $ joinStart = 1 ;
484
+ } elseif ($ joinStart == 1 && ! stripos ($ clauseType , 'JOIN ' )) {
485
+ $ joinStart = 2 ;
486
+ } elseif ($ joinStart == 2 && stripos ($ clauseType , 'JOIN ' )) {
487
+ $ error = 1 ;
488
+ }
489
+ }
490
+
467
491
if ($ clauseStartIdx != -1 && $ clauseStartIdx < $ minIdx ) {
468
- $ token = $ list ->tokens [$ clauseStartIdx ];
469
- $ parser ->error (
470
- __ ('Unexpected ordering of clauses. ' ),
471
- $ token
472
- );
473
- return false ;
492
+ if ($ joinStart == 0 || ($ joinStart == 2 && $ error = 1 )) {
493
+ $ token = $ list ->tokens [$ clauseStartIdx ];
494
+ $ parser ->error (
495
+ __ ('Unexpected ordering of clauses. ' ),
496
+ $ token
497
+ );
498
+ return false ;
499
+ } else {
500
+ $ minIdx = $ clauseStartIdx ;
501
+ }
474
502
} elseif ($ clauseStartIdx != -1 ) {
475
503
$ minIdx = $ clauseStartIdx ;
476
504
}
You can’t perform that action at this time.
0 commit comments