diff --git a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.Designer.cs b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.Designer.cs index 32153f7f..6028b9d6 100644 --- a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.Designer.cs +++ b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.Designer.cs @@ -105,6 +105,15 @@ internal static string FolderCreationFailureWarningMessage { } } + /// + /// Looks up a localized string similar to Cannot specify both 'ab' and 'rb'!. + /// + internal static string InvalidBracketsAroundNamesCombination { + get { + return ResourceManager.GetString("InvalidBracketsAroundNamesCombination", resourceCulture); + } + } + /// /// Looks up a localized string similar to No files found matching filename/pattern ({0}) and extension ({1}). /// diff --git a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.es.resx b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.es.resx index 26a1b7a4..a1948751 100644 --- a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.es.resx +++ b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.es.resx @@ -120,6 +120,9 @@ Hemos encontrado argumentos no reconocidos! + + InvalidBracketsAroundNamesCombination! + Copia de seguridad fallada: {0}{1} Saltando este archivo. {0} is the filename, {1} is a linebreak. @@ -180,7 +183,9 @@ ecs expandCaseStatements (predeterminado: verdadero) ecl expandCommaLists (predeterminado: verdadero) ecl expandInLists (predeterminado: verdadero) uk uppercaseKeywords (predeterminado: verdadero) -sk standardizeKeywords (predeterminado: falso) +sk standardizeKeywords (predeterminado: falso) +ab addBracketsAroundNames (predeterminado: falso) +rb removeBracketsAroundNames (predeterminado: falso) ae allowParsingErrors (predeterminado: falso) e extensions (predeterminado: sql) r recursive (predeterminado: falso) diff --git a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.fr.resx b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.fr.resx index ef2fde05..375e1874 100644 --- a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.fr.resx +++ b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.fr.resx @@ -120,6 +120,9 @@ Paramètres inconnus trouvés! + + InvalidBracketsAroundNamesCombination! + Sauvegarde échouée: {0}{1} On saute la mise en forme pour ce fichier. {0} is the filename, {1} is a linebreak. @@ -181,6 +184,8 @@ ecl expandCommaLists (par défaut: vrai) eil expandInLists (par défaut: vrai) uk uppercaseKeywords (par défaut: vrai) sk standardizeKeywords (par défaut: faux) +ab addBracketsAroundNames (par défaut: faux) +rb removeBracketsAroundNames (par défaut: faux) ae allowParsingErrors (par défaut: faux) e extensions (par défaut: sql) r recursive (par défaut: faux) @@ -208,4 +213,4 @@ echo select unecolonnequelconque from untableauquelconque | SqlFormatter Aucun fichier d'entrée (ou tube/pipe) n'a été proportionné. - \ No newline at end of file + diff --git a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.resx b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.resx index 0848be9f..b3d8b34e 100644 --- a/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.resx +++ b/PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.resx @@ -180,6 +180,8 @@ ecl expandCommaLists (default: true) eil expandInLists (default: true) uk uppercaseKeywords (default: true) sk standardizeKeywords (default: false) +ab addBracketsAroundNames (default: false) +rb removeBracketsAroundNames (default: false) ae allowParsingErrors (default: false) e extensions (default: sql) r recursive (default: false) @@ -204,6 +206,9 @@ echo select somecolumn from sometable | SqlFormatter Unrecognized arguments found! + + Cannot specify both 'ab' and 'rb'! + The provided Language Code is not supported. diff --git a/PoorMansTSqlFormatterCmdLine/Program.cs b/PoorMansTSqlFormatterCmdLine/Program.cs index 1d74cf4d..de4f90b2 100644 --- a/PoorMansTSqlFormatterCmdLine/Program.cs +++ b/PoorMansTSqlFormatterCmdLine/Program.cs @@ -57,7 +57,9 @@ static int Main(string[] args) ExpandCommaLists = true, BreakJoinOnSections = false, UppercaseKeywords = true, - ExpandInLists = true + ExpandInLists = true, + AddBracketsAroundNames = false, + RemoveBracketsAroundNames = false }; //bulk formatter options @@ -88,6 +90,8 @@ static int Main(string[] args) .Add("bjo|breakJoinOnSections", delegate(string v) { options.BreakJoinOnSections = v != null; }) .Add("uk|uppercaseKeywords", delegate(string v) { options.UppercaseKeywords = v != null; }) .Add("sk|standardizeKeywords", delegate(string v) { options.KeywordStandardization = v != null; }) + .Add("ab|addBracketsAroundNames", delegate (string v) { options.AddBracketsAroundNames = v != null; }) + .Add("rb|removeBracketsAroundNames", delegate (string v) { options.RemoveBracketsAroundNames = v != null; }) .Add("ae|allowParsingErrors", delegate(string v) { allowParsingErrors = v != null; }) .Add("e|extensions=", delegate(string v) { extensions.Add((v.StartsWith(".") ? "" : ".") + v); }) @@ -152,6 +156,13 @@ static int Main(string[] args) Console.Error.WriteLine(_generalResourceManager.GetString("UnrecognizedArgumentsErrorMessage")); } + // then check for incompatible settings + if (options.AddBracketsAroundNames && options.RemoveBracketsAroundNames) + { + showUsageError = true; + Console.Error.WriteLine(_generalResourceManager.GetString("InvalidBracketsAroundNamesCombination")); + } + if (extensions.Count == 0) extensions.Add(".sql"); diff --git a/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatter.cs b/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatter.cs index 86005967..5540073d 100644 --- a/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatter.cs +++ b/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatter.cs @@ -47,7 +47,7 @@ public TSqlStandardFormatter(TSqlStandardFormatterOptions options) } [Obsolete("Use the constructor with the TSqlStandardFormatterOptions parameter")] - public TSqlStandardFormatter(string indentString, int spacesPerTab, int maxLineWidth, bool expandCommaLists, bool trailingCommas, bool spaceAfterExpandedComma, bool expandBooleanExpressions, bool expandCaseStatements, bool expandBetweenConditions, bool breakJoinOnSections, bool uppercaseKeywords, bool htmlColoring, bool keywordStandardization) + public TSqlStandardFormatter(string indentString, int spacesPerTab, int maxLineWidth, bool expandCommaLists, bool trailingCommas, bool spaceAfterExpandedComma, bool expandBooleanExpressions, bool expandCaseStatements, bool expandBetweenConditions, bool breakJoinOnSections, bool uppercaseKeywords, bool htmlColoring, bool keywordStandardization, bool addBracketsAroundNames, bool removeBracketsAroundNames) { Options = new TSqlStandardFormatterOptions { @@ -63,7 +63,9 @@ public TSqlStandardFormatter(string indentString, int spacesPerTab, int maxLineW UppercaseKeywords = uppercaseKeywords, BreakJoinOnSections = breakJoinOnSections, HTMLColoring = htmlColoring, - KeywordStandardization = keywordStandardization + KeywordStandardization = keywordStandardization, + AddBracketsAroundNames = addBracketsAroundNames, + RemoveBracketsAroundNames = removeBracketsAroundNames }; if (keywordStandardization) @@ -534,7 +536,14 @@ private void ProcessSqlNode(Node contentElement, TSqlStandardFormattingState sta case SqlStructureConstants.ENAME_BRACKET_QUOTED_NAME: WhiteSpace_SeparateWords(state); - state.AddOutputContent("[" + contentElement.TextValue.Replace("]", "]]") + "]"); + if (Options.RemoveBracketsAroundNames) + { + state.AddOutputContent(contentElement.TextValue.Replace("[", "").Replace("]", "")); + } + else + { + state.AddOutputContent("[" + contentElement.TextValue.Replace("]", "]]") + "]"); + } state.WordSeparatorExpected = true; break; @@ -646,7 +655,18 @@ private void ProcessSqlNode(Node contentElement, TSqlStandardFormattingState sta case SqlStructureConstants.ENAME_MONETARY_VALUE: case SqlStructureConstants.ENAME_LABEL: WhiteSpace_SeparateWords(state); - state.AddOutputContent(contentElement.TextValue); + if (Options.AddBracketsAroundNames && !contentElement.TextValue.StartsWith("@")) + { + state.AddOutputContent("[" + contentElement.TextValue + "]"); + } + else if (Options.RemoveBracketsAroundNames) + { + state.AddOutputContent(contentElement.TextValue.Replace("[", "").Replace("]", "")); + } + else + { + state.AddOutputContent(contentElement.TextValue); + } state.WordSeparatorExpected = true; break; diff --git a/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatterOptions.cs b/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatterOptions.cs index 1df1310a..5cf67f46 100644 --- a/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatterOptions.cs +++ b/PoorMansTSqlFormatterLibShared/Formatters/TSqlStandardFormatterOptions.cs @@ -47,6 +47,8 @@ public TSqlStandardFormatterOptions() ExpandInLists = true; NewClauseLineBreaks = 1; NewStatementLineBreaks = 2; + AddBracketsAroundNames = false; + RemoveBracketsAroundNames = false; } //Doesn't particularly need to be lazy-loaded, and doesn't need to be threadsafe. @@ -82,7 +84,9 @@ public TSqlStandardFormatterOptions(string serializedString) : this() { else if (key == "ExpandInLists") ExpandInLists = Convert.ToBoolean(value); else if (key == "NewClauseLineBreaks") NewClauseLineBreaks = Convert.ToInt32(value); else if (key == "NewStatementLineBreaks") NewStatementLineBreaks = Convert.ToInt32(value); - else throw new ArgumentException("Unknown option: " + key); + else if (key == "AddBracketsAroundNames") AddBracketsAroundNames = Convert.ToBoolean(value); + else if (key == "RemoveBracketsAroundNames") RemoveBracketsAroundNames = Convert.ToBoolean(value); + else throw new ArgumentException("Unknown option: " + key); } } @@ -111,7 +115,9 @@ public string ToSerializedString() if (NewClauseLineBreaks != _defaultOptions.NewClauseLineBreaks) overrides.Add("NewClauseLineBreaks", NewClauseLineBreaks.ToString()); if (NewStatementLineBreaks != _defaultOptions.NewStatementLineBreaks) overrides.Add("NewStatementLineBreaks", NewStatementLineBreaks.ToString()); NewStatementLineBreaks = 2; - + if (AddBracketsAroundNames != _defaultOptions.AddBracketsAroundNames) overrides.Add("AddBracketsAroundNames", AddBracketsAroundNames.ToString()); + if (RemoveBracketsAroundNames != _defaultOptions.RemoveBracketsAroundNames) overrides.Add("RemoveBracketsAroundNames", RemoveBracketsAroundNames.ToString()); + if (overrides.Count == 0) return string.Empty; return string.Join(",", overrides.Select((kvp) => kvp.Key + "=" + kvp.Value).ToArray()); @@ -145,6 +151,8 @@ public string IndentString public bool ExpandInLists { get; set; } public int NewClauseLineBreaks { get; set; } public int NewStatementLineBreaks { get; set; } + public bool AddBracketsAroundNames { get; set; } + public bool RemoveBracketsAroundNames { get; set; } } }