Skip to content

Broken code for clause order validation #113

Closed
@nijel

Description

@nijel

The current code is broken, at least the part looking at JOIN clauses - it contains unreachable code (I've spotted this when looking at code not covered by tests).

Code is here: https://github.com/phpmyadmin/sql-parser/blob/master/src/Statement.php#L480

            // Handle ordering of Multiple Joins in a query
            if ($clauseStartIdx != -1) {
                if ($joinStart == 0 && stripos($clauseType, 'JOIN') !== false) {
                    $joinStart = 1;
                } elseif ($joinStart == 1 && stripos($clauseType, 'JOIN') === false) {
                    $joinStart = 2;
                } elseif ($joinStart == 2 && stripos($clauseType, 'JOIN') !== false) {
                    $error = 1;
                }
            }

The problem is that all JOIN clauses are in same group in the $CLAUSES array, so the error condition can never happen as there will be no $clauseType containing JOIN after $joinStart is set to 2.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions