jdorn / sql-formatter

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.
http://jdorn.github.com/sql-formatter/
MIT License
3.89k stars 185 forks source link

Formatting breaks when using '\' #112

Open buutqn opened 2 years ago

buutqn commented 2 years ago

The following queries are formatted using SqlFormatter:format() method

SELECT 
    path, 
    CHARINDEX(
        '\', path_sep) AS sep FROM dirs AS d
SELECT 
    path, 
    '\' AS sep FROM dirs AS d
mvorisek commented 7 months ago

This is sadly true as the https://github.com/jdorn/sql-formatter/blob/v1.2.17/lib/SqlFormatter.php#L339 and even https://github.com/doctrine/sql-formatter/blob/1.2.0/src/Tokenizer.php#L984 string tokenize code assumes MySQL grammar.