sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

Bug: Column names equal to keywords are uppercased

Open RafaelKr opened this issue 1 year ago • 1 comments

I have the following Column definition in my Symfony project

#[ORM\Entity]
class Queue {
   [...]

    #[ORM\Column(
        insertable: false,
        updatable: false,
        columnDefinition: 'SERIAL',
    )]
    private ?int $autoIncrement = null;

   [...]
}

When generating a migration without --formatted option the column name is auto_increment. But with --formatted the column name will be AUTO_INCREMENT.

The resulting column name should be lowercase.

Edit: The doctrine/sql-formatter version is 1.2.0 Could be related to https://github.com/doctrine/sql-formatter/pull/93

RafaelKr avatar Mar 28 '24 09:03 RafaelKr

Cc @rinu

greg0ire avatar Mar 28 '24 09:03 greg0ire

I propose to revert #93 as reserved words cannot be assumed to be reserved in context-free grammar especially not knowing what database is used.

Even if someone would partly disagree, the upper casing must not be done by the tokenizer because of what said above.

Here is an example: https://dbfiddle.uk/Hz6SWg8B

lock is "known reserved word" - https://github.com/doctrine/sql-formatter/blob/1.4.0/src/Tokenizer.php#L159 - but:

-select 'x' AS lock;
+select 'x' AS LOCK;

would produce different result as the result will have LOCK column name instead of lock. The tokenizer nor formatter must do such/any change with functional impact.

mvorisek avatar May 13 '24 10:05 mvorisek

I propose to revert #93 as reserved words cannot be assumed to be reserved in context-free grammar especially not knowing what database is used.

I agree.

derrabus avatar May 13 '24 11:05 derrabus