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 187 forks source link

Inline comments in fields list #113

Closed MrSandvik closed 2 years ago

MrSandvik commented 2 years ago

Hello

Hoping this wonderful project is still alive.. I notice that it doesn't quite handle inline comments as gracefully when they appear in field list definitions.

Here is some sample output where the table declaration has inline comments:

  declare @result as table(
    subquery varchar(4) -- query reference

    , 
    mpehotel int, 
    bookref int -- buch or bktbuch reference no.

    , 
    date1 date, 
    date2 date, 
    time1 varchar(8), 
    time2 varchar(8), 
    guest1 varchar(100) -- Name 1

    , 
    guest2 varchar(100) -- Name 2

    , 
    location varchar(100) -- Room or conference location name

    , 
    adults int, 
    children1 int, 
    children2 int, 
    children3 int, 
    children4 int, 

The added linespaces after these inline comments are unfortunate. I have been trying to dissect and modify your script, but all my efforts have failed. I can see where this is managed in code, but as I am a mere beginner in php, I only fail..

So, if you are still updating this project, I would love to see this handled in a more tidy fashion where inline comments remain in line - i.e. no line breaks in these situations

Thank you!

MrSandvik commented 2 years ago

Solved