greenlion / PHP-SQL-Parser

A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL
BSD 3-Clause "New" or "Revised" License
601 stars 156 forks source link

UnableToCalculatePositionException if a function is used inside JOIN condition #358

Closed czoIg closed 2 years ago

czoIg commented 2 years ago

With the following code:

$query = 'SELECT start_date FROM users INNER JOIN vacation ON DATE(start_date) <= DATE(end_date)';
$parser = new \PHPSQLParser\PHPSQLParser($query, true);

an exception is thrown:

# Error        PHPSQLParser\exceptions\UnableToCalculatePositionException
# File      External/greenlion/php-sql-parser/src/PHPSQLParser/positions/PositionCalculator.php
# Line 243
# Trace
# File       Function        Line
# External/greenlion/php-sql-parser/src/PHPSQLParser/positions/PositionCalculator.php   lookForBaseExpression   259
# External/greenlion/php-sql-parser/src/PHPSQLParser/positions/PositionCalculator.php   lookForBaseExpression   259
# External/greenlion/php-sql-parser/src/PHPSQLParser/positions/PositionCalculator.php   lookForBaseExpression   125
# External/greenlion/php-sql-parser/src/PHPSQLParser/PHPSQLParser.php   setPositionsWithinSQL   100
# External/greenlion/php-sql-parser/src/PHPSQLParser/PHPSQLParser.php   parse   75

# [2020-04-01 07:02:15] - Exception     cannot calculate position of vacation ON DATE(start_date) <= DATE(end_date) within )
greenlion commented 2 years ago

Thanks!