TaoK / PoorMansTSqlFormatter

A small free .Net and JS library (with demo UI, command-line bulk formatter, SSMS/VS add-in, notepad++ plugin, winmerge plugin, and demo webpage) for reformatting and coloring T-SQL code to the user's preferences.
http://www.architectshack.com/PoorMansTSqlFormatter.ashx
GNU Affero General Public License v3.0
970 stars 268 forks source link

Option: Don't touch the case, even for keywords #111

Open kuanjuliu opened 11 years ago

kuanjuliu commented 11 years ago

I've noticed that if a table has a column rather unfortunately named "Data" it will get capitalized. Obviously, that can cause havoc in the code itself, as TableName.Data is definitely not the same as TableName.DATA if you have case-sensitivity enabled, as we have.

So far I've only seen this problem with "Data", but there may be other poorly-named columns that would suffer the same fate.

BTW another very big player out there [ahem]RedGate[/ahem] also capitalized "Value" (as in TableName.Value became TableName.VALUE), along with a whole slew of system functions. So, go Tao!

(Can you tell we just converted from MySQL to SQL Server, lol?)

TimothyK commented 10 years ago

I run into this one with the Status column I have in my database.

A simpler solution that trying to figure out what are keywords or column names could be to give more options for "Uppercase Keywords". The Uppercase Keywords option, like all other options, is a Boolean. With this setting we get a choice whether we want to see our Status column formatted as STATUS or status.

The Uppercase Keywords (Boolean) option should be changed to a Keyword Casing option. This would have 4 possible values: Upper, Lower, Title Case, or Unchanged. I'd be very happy if I could set this to Title Case or Unchanged to get my Status column coming out the way I want.

Last year my pull request was accepted that did some refactoring on the serialization and storage of option parameters. This enhancement request was where I was going with this. It should be possible to add a new KeywordCasing option, whilst still having a migration path to offer backward compatibility for the UppercaseKeywords option.

joshka commented 10 years ago

A column named "Name" is another one that seems to trigger this bug.

Otiel commented 9 years ago

I encounter the same with "Status" and "Name" columns. "Value" is not modified.

Until this bug is fixed, one solution is to add brackets (e.g. [Name]) around the column names.

TaoK commented 7 years ago

I really like @TimothyK's proposal here: these things ARE keywords, and distinguishing between "keywords in a column name position" and "keywords elsewhere" would be (in my opinion) needlessly complex, but giving people an option like "don't uppercase keywords, don't lowercase them, just leave them alone dammit" would clearly make sense.

TaoK commented 7 years ago

"Name" in particular is a bug, as identified in Pull Request #141