Skip to content
Browse files

Issue #49: Configurable number of breaks between clauses and statements

  • Loading branch information...
1 parent bc56ac4 commit 65d68530088c7fb2c2b98c6810d7b227a42a2c88 @TaoK committed Oct 13, 2013
View
1 CHANGELOG.md
@@ -14,6 +14,7 @@
* Github Issue #97: [Bugfix] Parsing error when single uppercase N is followed by a non-word character [thanks to derekfrye for the bug report]
* Github Issue #91: [Bugfix] Incorrect formatting of "*=" operator [thanks to ralfkret for the bug report]
* Github Issue #51: [Enhancement] Added support for the OUT synonym of OUTPUT (for arguments), and corresponding keyword standardization support
+* Github Issue #49: [Enhancement] Added options to control line spacing between clauses and statements [thanks to Farzad Jalali, Sheldon Hull and Benjamin Solomon for the request]
### Version 1.4.4 (SSMS / Visual Studio Add-In only)
View
2 PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.es.resx
@@ -170,6 +170,8 @@ SqlFormatter <archivo or patrón> <opciones>
is indentString (predeterminado: \t)
st spacesPerTab (predeterminado: 4)
mw maxLineWidth (predeterminado: 999)
+sb statementBreaks (predeterminado: 2)
+cb clauseBreaks (predeterminado: 1)
tc trailingCommas (predeterminado: falso)
sac spaceAfterExpandedComma (predeterminado: falso)
ebc expandBetweenConditions (predeterminado: verdadero)
View
2 PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.fr.resx
@@ -170,6 +170,8 @@ SqlFormatter <nom de fichier ou modèle> <options>
is indentString (par défaut: \t)
st spacesPerTab (par défaut: 4)
mw maxLineWidth (par défaut: 999)
+sb statementBreaks (par défaut: 2)
+cb clauseBreaks (par défaut: 1)
tc trailingCommas (par défaut: faux)
sac spaceAfterExpandedComma (par défaut: faux)
ebc expandBetweenConditions (par défaut: vrai)
View
2 PoorMansTSqlFormatterCmdLine/GeneralLanguageContent.resx
@@ -169,6 +169,8 @@ SqlFormatter <filename or pattern> <options>
is indentString (default: \t)
st spacesPerTab (default: 4)
mw maxLineWidth (default: 999)
+sb statementBreaks (default: 2)
+cb clauseBreaks (default: 1)
tc trailingCommas (default: false)
sac spaceAfterExpandedComma (default: false)
ebc expandBetweenConditions (default: true)
View
10 PoorMansTSqlFormatterCmdLine/Program.cs
@@ -46,8 +46,10 @@ static int Main(string[] args)
KeywordStandardization = true,
IndentString = "\t",
SpacesPerTab = 4,
- MaxLineWidth = 999,
- TrailingCommas = false,
+ MaxLineWidth = 999,
+ NewStatementLineBreaks = 2,
+ NewClauseLineBreaks = 1,
+ TrailingCommas = false,
SpaceAfterExpandedComma = false,
ExpandBetweenConditions = true,
ExpandBooleanExpressions = true,
@@ -74,7 +76,9 @@ static int Main(string[] args)
.Add("is|indentString=", delegate(string v) { options.IndentString = v; })
.Add("st|spacesPerTab=", delegate(string v) { options.SpacesPerTab = int.Parse(v); })
.Add("mw|maxLineWidth=", delegate(string v) { options.MaxLineWidth = int.Parse(v); })
- .Add("tc|trailingCommas", delegate(string v) { options.TrailingCommas = v != null; })
+ .Add("sb|statementBreaks=", delegate(string v) { options.NewStatementLineBreaks = int.Parse(v); })
+ .Add("cb|clauseBreaks=", delegate(string v) { options.NewClauseLineBreaks = int.Parse(v); })
+ .Add("tc|trailingCommas", delegate(string v) { options.TrailingCommas = v != null; })
.Add("sac|spaceAfterExpandedComma", delegate(string v) { options.SpaceAfterExpandedComma = v != null; })
.Add("ebc|expandBetweenConditions", delegate(string v) { options.ExpandBetweenConditions = v != null; })
.Add("ebe|expandBooleanExpressions", delegate(string v) { options.ExpandBooleanExpressions = v != null; })
View
50 PoorMansTSqlFormatterDemo/MainForm.Designer.cs
@@ -69,6 +69,7 @@ private void InitializeComponent()
this.radio_Formatting_Standard = new System.Windows.Forms.RadioButton();
this.grp_Options = new System.Windows.Forms.GroupBox();
this.chk_BreakJoinOnSections = new System.Windows.Forms.CheckBox();
+ this.chk_ExpandInLists = new System.Windows.Forms.CheckBox();
this.chk_EnableKeywordStandardization = new System.Windows.Forms.CheckBox();
this.txt_MaxWidth = new System.Windows.Forms.TextBox();
this.lbl_MaxWidth = new System.Windows.Forms.Label();
@@ -104,7 +105,10 @@ private void InitializeComponent()
this.frenchToolStripMenuItem = new PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem();
this.spanishToolStripMenuItem = new PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.chk_ExpandInLists = new System.Windows.Forms.CheckBox();
+ this.lbl_StatementBreaks = new System.Windows.Forms.Label();
+ this.txt_StatementBreaks = new System.Windows.Forms.TextBox();
+ this.lbl_ClauseBreaks = new System.Windows.Forms.Label();
+ this.txt_ClauseBreaks = new System.Windows.Forms.TextBox();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
@@ -293,6 +297,10 @@ private void InitializeComponent()
this.grp_Options.Controls.Add(this.chk_BreakJoinOnSections);
this.grp_Options.Controls.Add(this.chk_ExpandInLists);
this.grp_Options.Controls.Add(this.chk_EnableKeywordStandardization);
+ this.grp_Options.Controls.Add(this.txt_ClauseBreaks);
+ this.grp_Options.Controls.Add(this.lbl_ClauseBreaks);
+ this.grp_Options.Controls.Add(this.txt_StatementBreaks);
+ this.grp_Options.Controls.Add(this.lbl_StatementBreaks);
this.grp_Options.Controls.Add(this.txt_MaxWidth);
this.grp_Options.Controls.Add(this.lbl_MaxWidth);
this.grp_Options.Controls.Add(this.txt_IndentWidth);
@@ -318,6 +326,15 @@ private void InitializeComponent()
this.chk_BreakJoinOnSections.UseVisualStyleBackColor = true;
this.chk_BreakJoinOnSections.CheckedChanged += new System.EventHandler(this.FormatSettingsControlChanged);
//
+ // chk_ExpandInLists
+ //
+ resources.ApplyResources(this.chk_ExpandInLists, "chk_ExpandInLists");
+ this.chk_ExpandInLists.Checked = true;
+ this.chk_ExpandInLists.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.chk_ExpandInLists.Name = "chk_ExpandInLists";
+ this.chk_ExpandInLists.UseVisualStyleBackColor = true;
+ this.chk_ExpandInLists.CheckedChanged += new System.EventHandler(this.FormatSettingsControlChanged);
+ //
// chk_EnableKeywordStandardization
//
resources.ApplyResources(this.chk_EnableKeywordStandardization, "chk_EnableKeywordStandardization");
@@ -577,14 +594,27 @@ private void InitializeComponent()
resources.ApplyResources(this.aboutToolStripMenuItem, "aboutToolStripMenuItem");
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
- // chk_ExpandInLists
+ // lbl_StatementBreaks
//
- resources.ApplyResources(this.chk_ExpandInLists, "chk_ExpandInLists");
- this.chk_ExpandInLists.Checked = true;
- this.chk_ExpandInLists.CheckState = System.Windows.Forms.CheckState.Checked;
- this.chk_ExpandInLists.Name = "chk_ExpandInLists";
- this.chk_ExpandInLists.UseVisualStyleBackColor = true;
- this.chk_ExpandInLists.CheckedChanged += new System.EventHandler(this.FormatSettingsControlChanged);
+ resources.ApplyResources(this.lbl_StatementBreaks, "lbl_StatementBreaks");
+ this.lbl_StatementBreaks.Name = "lbl_StatementBreaks";
+ //
+ // txt_StatementBreaks
+ //
+ resources.ApplyResources(this.txt_StatementBreaks, "txt_StatementBreaks");
+ this.txt_StatementBreaks.Name = "txt_StatementBreaks";
+ this.txt_StatementBreaks.TextChanged += new System.EventHandler(this.FormatSettingsControlChanged);
+ //
+ // lbl_ClauseBreaks
+ //
+ resources.ApplyResources(this.lbl_ClauseBreaks, "lbl_ClauseBreaks");
+ this.lbl_ClauseBreaks.Name = "lbl_ClauseBreaks";
+ //
+ // txt_ClauseBreaks
+ //
+ resources.ApplyResources(this.txt_ClauseBreaks, "txt_ClauseBreaks");
+ this.txt_ClauseBreaks.Name = "txt_ClauseBreaks";
+ this.txt_ClauseBreaks.TextChanged += new System.EventHandler(this.FormatSettingsControlChanged);
//
// MainForm
//
@@ -687,6 +717,10 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox chk_RandomizeLineLength;
private System.Windows.Forms.CheckBox chk_KeywordSubstitution;
private System.Windows.Forms.CheckBox chk_ExpandInLists;
+ private System.Windows.Forms.TextBox txt_ClauseBreaks;
+ private System.Windows.Forms.Label lbl_ClauseBreaks;
+ private System.Windows.Forms.TextBox txt_StatementBreaks;
+ private System.Windows.Forms.Label lbl_StatementBreaks;
}
}
View
16 PoorMansTSqlFormatterDemo/MainForm.cs
@@ -90,8 +90,10 @@ public MainForm()
radio_Formatting_Standard.Checked = Properties.Settings.Default.Formatter.Equals(FORMATTER_STANDARD, StringComparison.InvariantCultureIgnoreCase);
txt_Indent.Text = Properties.Settings.Default.Indent;
txt_IndentWidth.Text = Properties.Settings.Default.IndentWidth.ToString();
- txt_MaxWidth.Text = Properties.Settings.Default.MaxWidth.ToString();
- chk_ExpandCommaLists.Checked = Properties.Settings.Default.ExpandCommaLists;
+ txt_MaxWidth.Text = Properties.Settings.Default.MaxWidth.ToString();
+ txt_StatementBreaks.Text = Properties.Settings.Default.NewStatementLineBreaks.ToString();
+ txt_ClauseBreaks.Text = Properties.Settings.Default.NewClauseLineBreaks.ToString();
+ chk_ExpandCommaLists.Checked = Properties.Settings.Default.ExpandCommaLists;
chk_TrailingCommas.Checked = Properties.Settings.Default.TrailingCommas;
chk_SpaceAfterComma.Checked = Properties.Settings.Default.SpaceAfterComma;
chk_ExpandBooleanExpressions.Checked = Properties.Settings.Default.ExpandBooleanExpressions;
@@ -135,7 +137,9 @@ private void SaveFormatSettings()
Properties.Settings.Default.Indent = txt_Indent.Text.Replace("\t", "\\t").Replace(" ", "\\s");
Properties.Settings.Default.IndentWidth = int.Parse(txt_IndentWidth.Text);
Properties.Settings.Default.MaxWidth = int.Parse(txt_MaxWidth.Text);
- Properties.Settings.Default.ExpandCommaLists = chk_ExpandCommaLists.Checked;
+ Properties.Settings.Default.NewStatementLineBreaks = int.Parse(txt_StatementBreaks.Text);
+ Properties.Settings.Default.NewClauseLineBreaks = int.Parse(txt_ClauseBreaks.Text);
+ Properties.Settings.Default.ExpandCommaLists = chk_ExpandCommaLists.Checked;
Properties.Settings.Default.TrailingCommas = chk_TrailingCommas.Checked;
Properties.Settings.Default.SpaceAfterComma = chk_SpaceAfterComma.Checked;
Properties.Settings.Default.ExpandBooleanExpressions = chk_ExpandBooleanExpressions.Checked;
@@ -180,8 +184,10 @@ private void SetFormatter()
BreakJoinOnSections = chk_BreakJoinOnSections.Checked,
UppercaseKeywords = chk_UppercaseKeywords.Checked,
HTMLColoring = chk_Coloring.Checked,
- KeywordStandardization = chk_EnableKeywordStandardization.Checked
- });
+ KeywordStandardization = chk_EnableKeywordStandardization.Checked,
+ NewStatementLineBreaks = int.Parse(txt_StatementBreaks.Text),
+ NewClauseLineBreaks = int.Parse(txt_ClauseBreaks.Text)
+ });
}
else if (radio_Formatting_Identity.Checked)
innerFormatter = new PoorMansTSqlFormatterLib.Formatters.TSqlIdentityFormatter(chk_IdentityColoring.Checked);
View
198 PoorMansTSqlFormatterDemo/MainForm.resx
@@ -175,7 +175,7 @@
<value>txt_Input</value>
</data>
<data name="&gt;&gt;txt_Input.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.SelectableTextBox, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.SelectableTextBox, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;txt_Input.Parent" xml:space="preserve">
<value>groupBox1</value>
@@ -271,7 +271,7 @@
<value>txt_TokenizedSql</value>
</data>
<data name="&gt;&gt;txt_TokenizedSql.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.SelectableTextBox, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.SelectableTextBox, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;txt_TokenizedSql.Parent" xml:space="preserve">
<value>groupBox2</value>
@@ -355,7 +355,7 @@
<value>txt_ParsedXml</value>
</data>
<data name="&gt;&gt;txt_ParsedXml.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.SelectableTextBox, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.SelectableTextBox, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;txt_ParsedXml.Parent" xml:space="preserve">
<value>groupBox3</value>
@@ -511,7 +511,7 @@
<value>webBrowser_OutputSql</value>
</data>
<data name="&gt;&gt;webBrowser_OutputSql.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.CustomContentWebBrowser, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.CustomContentWebBrowser, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;webBrowser_OutputSql.Parent" xml:space="preserve">
<value>panel1</value>
@@ -604,7 +604,7 @@
<value>True</value>
</data>
<data name="radio_Formatting_Identity.Location" type="System.Drawing.Point, System.Drawing">
- <value>4, 447</value>
+ <value>4, 507</value>
</data>
<data name="radio_Formatting_Identity.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -664,7 +664,7 @@
<value>True</value>
</data>
<data name="chk_BreakJoinOnSections.Location" type="System.Drawing.Point, System.Drawing">
- <value>7, 288</value>
+ <value>11, 346</value>
</data>
<data name="chk_BreakJoinOnSections.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -697,7 +697,7 @@
<value>NoControl</value>
</data>
<data name="chk_ExpandInLists.Location" type="System.Drawing.Point, System.Drawing">
- <value>7, 259</value>
+ <value>11, 317</value>
</data>
<data name="chk_ExpandInLists.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -727,7 +727,7 @@
<value>True</value>
</data>
<data name="chk_EnableKeywordStandardization.Location" type="System.Drawing.Point, System.Drawing">
- <value>7, 373</value>
+ <value>11, 431</value>
</data>
<data name="chk_EnableKeywordStandardization.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -753,6 +753,126 @@
<data name="&gt;&gt;chk_EnableKeywordStandardization.ZOrder" xml:space="preserve">
<value>2</value>
</data>
+ <data name="txt_ClauseBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>154, 117</value>
+ </data>
+ <data name="txt_ClauseBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 4, 4, 4</value>
+ </data>
+ <data name="txt_ClauseBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>50, 22</value>
+ </data>
+ <data name="txt_ClauseBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>16</value>
+ </data>
+ <data name="txt_ClauseBreaks.Text" xml:space="preserve">
+ <value>1</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.Name" xml:space="preserve">
+ <value>txt_ClauseBreaks</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.Parent" xml:space="preserve">
+ <value>grp_Options</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.ZOrder" xml:space="preserve">
+ <value>3</value>
+ </data>
+ <data name="lbl_ClauseBreaks.AutoSize" type="System.Boolean, mscorlib">
+ <value>True</value>
+ </data>
+ <data name="lbl_ClauseBreaks.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+ <value>NoControl</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>9, 120</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 0, 4, 0</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>103, 17</value>
+ </data>
+ <data name="lbl_ClauseBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>15</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Text" xml:space="preserve">
+ <value>Clause Breaks:</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.Name" xml:space="preserve">
+ <value>lbl_ClauseBreaks</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.Parent" xml:space="preserve">
+ <value>grp_Options</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.ZOrder" xml:space="preserve">
+ <value>4</value>
+ </data>
+ <data name="txt_StatementBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>154, 87</value>
+ </data>
+ <data name="txt_StatementBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 4, 4, 4</value>
+ </data>
+ <data name="txt_StatementBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>50, 22</value>
+ </data>
+ <data name="txt_StatementBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>16</value>
+ </data>
+ <data name="txt_StatementBreaks.Text" xml:space="preserve">
+ <value>2</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.Name" xml:space="preserve">
+ <value>txt_StatementBreaks</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.Parent" xml:space="preserve">
+ <value>grp_Options</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.ZOrder" xml:space="preserve">
+ <value>5</value>
+ </data>
+ <data name="lbl_StatementBreaks.AutoSize" type="System.Boolean, mscorlib">
+ <value>True</value>
+ </data>
+ <data name="lbl_StatementBreaks.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+ <value>NoControl</value>
+ </data>
+ <data name="lbl_StatementBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>9, 90</value>
+ </data>
+ <data name="lbl_StatementBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 0, 4, 0</value>
+ </data>
+ <data name="lbl_StatementBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>124, 17</value>
+ </data>
+ <data name="lbl_StatementBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>15</value>
+ </data>
+ <data name="lbl_StatementBreaks.Text" xml:space="preserve">
+ <value>Statement Breaks:</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.Name" xml:space="preserve">
+ <value>lbl_StatementBreaks</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.Parent" xml:space="preserve">
+ <value>grp_Options</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.ZOrder" xml:space="preserve">
+ <value>6</value>
+ </data>
<data name="txt_MaxWidth.Location" type="System.Drawing.Point, System.Drawing">
<value>103, 57</value>
</data>
@@ -778,7 +898,7 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;txt_MaxWidth.ZOrder" xml:space="preserve">
- <value>3</value>
+ <value>7</value>
</data>
<data name="lbl_MaxWidth.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -808,7 +928,7 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;lbl_MaxWidth.ZOrder" xml:space="preserve">
- <value>4</value>
+ <value>8</value>
</data>
<data name="txt_IndentWidth.Location" type="System.Drawing.Point, System.Drawing">
<value>213, 25</value>
@@ -835,7 +955,7 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;txt_IndentWidth.ZOrder" xml:space="preserve">
- <value>5</value>
+ <value>9</value>
</data>
<data name="lbl_IndentWidth.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -865,7 +985,7 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;lbl_IndentWidth.ZOrder" xml:space="preserve">
- <value>6</value>
+ <value>10</value>
</data>
<data name="txt_Indent.Location" type="System.Drawing.Point, System.Drawing">
<value>63, 25</value>
@@ -892,7 +1012,7 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;txt_Indent.ZOrder" xml:space="preserve">
- <value>7</value>
+ <value>11</value>
</data>
<data name="lbl_Indent.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -922,13 +1042,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;lbl_Indent.ZOrder" xml:space="preserve">
- <value>8</value>
+ <value>12</value>
</data>
<data name="chk_ExpandBetweenConditions.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_ExpandBetweenConditions.Location" type="System.Drawing.Point, System.Drawing">
- <value>8, 230</value>
+ <value>12, 288</value>
</data>
<data name="chk_ExpandBetweenConditions.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -952,13 +1072,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_ExpandBetweenConditions.ZOrder" xml:space="preserve">
- <value>9</value>
+ <value>13</value>
</data>
<data name="chk_SpaceAfterComma.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_SpaceAfterComma.Location" type="System.Drawing.Point, System.Drawing">
- <value>52, 145</value>
+ <value>56, 203</value>
</data>
<data name="chk_SpaceAfterComma.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -982,13 +1102,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_SpaceAfterComma.ZOrder" xml:space="preserve">
- <value>10</value>
+ <value>14</value>
</data>
<data name="chk_Coloring.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_Coloring.Location" type="System.Drawing.Point, System.Drawing">
- <value>7, 344</value>
+ <value>11, 402</value>
</data>
<data name="chk_Coloring.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1012,13 +1132,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_Coloring.ZOrder" xml:space="preserve">
- <value>11</value>
+ <value>15</value>
</data>
<data name="chk_UppercaseKeywords.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_UppercaseKeywords.Location" type="System.Drawing.Point, System.Drawing">
- <value>7, 316</value>
+ <value>11, 374</value>
</data>
<data name="chk_UppercaseKeywords.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1042,13 +1162,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_UppercaseKeywords.ZOrder" xml:space="preserve">
- <value>12</value>
+ <value>16</value>
</data>
<data name="chk_ExpandCaseStatements.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_ExpandCaseStatements.Location" type="System.Drawing.Point, System.Drawing">
- <value>8, 202</value>
+ <value>12, 260</value>
</data>
<data name="chk_ExpandCaseStatements.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1072,13 +1192,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_ExpandCaseStatements.ZOrder" xml:space="preserve">
- <value>13</value>
+ <value>17</value>
</data>
<data name="chk_ExpandBooleanExpressions.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_ExpandBooleanExpressions.Location" type="System.Drawing.Point, System.Drawing">
- <value>8, 174</value>
+ <value>12, 232</value>
</data>
<data name="chk_ExpandBooleanExpressions.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1102,13 +1222,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_ExpandBooleanExpressions.ZOrder" xml:space="preserve">
- <value>14</value>
+ <value>18</value>
</data>
<data name="chk_TrailingCommas.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_TrailingCommas.Location" type="System.Drawing.Point, System.Drawing">
- <value>52, 117</value>
+ <value>56, 175</value>
</data>
<data name="chk_TrailingCommas.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1132,13 +1252,13 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_TrailingCommas.ZOrder" xml:space="preserve">
- <value>15</value>
+ <value>19</value>
</data>
<data name="chk_ExpandCommaLists.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="chk_ExpandCommaLists.Location" type="System.Drawing.Point, System.Drawing">
- <value>8, 89</value>
+ <value>12, 147</value>
</data>
<data name="chk_ExpandCommaLists.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1162,7 +1282,7 @@
<value>grp_Options</value>
</data>
<data name="&gt;&gt;chk_ExpandCommaLists.ZOrder" xml:space="preserve">
- <value>16</value>
+ <value>20</value>
</data>
<data name="grp_Options.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
@@ -1177,7 +1297,7 @@
<value>4, 4, 4, 4</value>
</data>
<data name="grp_Options.Size" type="System.Drawing.Size, System.Drawing">
- <value>282, 404</value>
+ <value>282, 464</value>
</data>
<data name="grp_Options.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
@@ -1228,7 +1348,7 @@
<value>0</value>
</data>
<data name="grp_IdentityFormattingOptions.Location" type="System.Drawing.Point, System.Drawing">
- <value>57, 478</value>
+ <value>57, 538</value>
</data>
<data name="grp_IdentityFormattingOptions.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1261,7 +1381,7 @@
<value>True</value>
</data>
<data name="radio_Formatting_Obfuscate.Location" type="System.Drawing.Point, System.Drawing">
- <value>4, 538</value>
+ <value>4, 598</value>
</data>
<data name="radio_Formatting_Obfuscate.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1438,7 +1558,7 @@
<value>4</value>
</data>
<data name="grp_ObfuscationOptions.Location" type="System.Drawing.Point, System.Drawing">
- <value>57, 566</value>
+ <value>57, 626</value>
</data>
<data name="grp_ObfuscationOptions.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -1447,7 +1567,7 @@
<value>4, 4, 4, 4</value>
</data>
<data name="grp_ObfuscationOptions.Size" type="System.Drawing.Size, System.Drawing">
- <value>267, 144</value>
+ <value>267, 84</value>
</data>
<data name="grp_ObfuscationOptions.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
@@ -1498,7 +1618,7 @@
<value>0</value>
</data>
<data name="tableLayoutPanel2.LayoutSettings" type="System.Windows.Forms.TableLayoutSettings, System.Windows.Forms">
- <value>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TableLayoutSettings&gt;&lt;Controls&gt;&lt;Control Name="radio_Formatting_Identity" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /&gt;&lt;Control Name="radio_Formatting_Standard" Row="0" RowSpan="1" Column="0" ColumnSpan="2" /&gt;&lt;Control Name="grp_Options" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;Control Name="grp_IdentityFormattingOptions" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;Control Name="radio_Formatting_Obfuscate" Row="4" RowSpan="1" Column="0" ColumnSpan="2" /&gt;&lt;Control Name="grp_ObfuscationOptions" Row="5" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;/Controls&gt;&lt;Columns Styles="Absolute,53,Percent,100" /&gt;&lt;Rows Styles="Absolute,31,Absolute,412,Absolute,31,Absolute,60,Absolute,28,Absolute,12" /&gt;&lt;/TableLayoutSettings&gt;</value>
+ <value>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TableLayoutSettings&gt;&lt;Controls&gt;&lt;Control Name="radio_Formatting_Identity" Row="2" RowSpan="1" Column="0" ColumnSpan="2" /&gt;&lt;Control Name="radio_Formatting_Standard" Row="0" RowSpan="1" Column="0" ColumnSpan="2" /&gt;&lt;Control Name="grp_Options" Row="1" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;Control Name="grp_IdentityFormattingOptions" Row="3" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;Control Name="radio_Formatting_Obfuscate" Row="4" RowSpan="1" Column="0" ColumnSpan="2" /&gt;&lt;Control Name="grp_ObfuscationOptions" Row="5" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;/Controls&gt;&lt;Columns Styles="Absolute,53,Percent,100" /&gt;&lt;Rows Styles="Absolute,31,Absolute,472,Absolute,31,Absolute,60,Absolute,28,Absolute,12" /&gt;&lt;/TableLayoutSettings&gt;</value>
</data>
<data name="groupBox5.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Top</value>
@@ -1750,19 +1870,19 @@
<value>englishToolStripMenuItem</value>
</data>
<data name="&gt;&gt;englishToolStripMenuItem.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;frenchToolStripMenuItem.Name" xml:space="preserve">
<value>frenchToolStripMenuItem</value>
</data>
<data name="&gt;&gt;frenchToolStripMenuItem.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;spanishToolStripMenuItem.Name" xml:space="preserve">
<value>spanishToolStripMenuItem</value>
</data>
<data name="&gt;&gt;spanishToolStripMenuItem.Type" xml:space="preserve">
- <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem, PoorMansTSqlFormatterDemo, Version=1.4.3.26690, Culture=neutral, PublicKeyToken=null</value>
+ <value>PoorMansTSqlFormatterDemo.FrameworkClassReplacements.RadioToolStripMenuItem, PoorMansTSqlFormatterDemo, Version=1.4.3.27437, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;aboutToolStripMenuItem.Name" xml:space="preserve">
<value>aboutToolStripMenuItem</value>
View
24 PoorMansTSqlFormatterDemo/Properties/Settings.Designer.cs
@@ -334,5 +334,29 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
this["ExpandInLists"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("2")]
+ public int NewStatementLineBreaks {
+ get {
+ return ((int)(this["NewStatementLineBreaks"]));
+ }
+ set {
+ this["NewStatementLineBreaks"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("1")]
+ public int NewClauseLineBreaks {
+ get {
+ return ((int)(this["NewClauseLineBreaks"]));
+ }
+ set {
+ this["NewClauseLineBreaks"] = value;
+ }
+ }
}
}
View
6 PoorMansTSqlFormatterDemo/Properties/Settings.settings
@@ -80,5 +80,11 @@
<Setting Name="ExpandInLists" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
+ <Setting Name="NewStatementLineBreaks" Type="System.Int32" Scope="User">
+ <Value Profile="(Default)">2</Value>
+ </Setting>
+ <Setting Name="NewClauseLineBreaks" Type="System.Int32" Scope="User">
+ <Value Profile="(Default)">1</Value>
+ </Setting>
</Settings>
</SettingsFile>
View
6 PoorMansTSqlFormatterDemo/app.config
@@ -85,6 +85,12 @@
<setting name="ExpandInLists" serializeAs="String">
<value>True</value>
</setting>
+ <setting name="NewStatementLineBreaks" serializeAs="String">
+ <value>2</value>
+ </setting>
+ <setting name="NewClauseLineBreaks" serializeAs="String">
+ <value>1</value>
+ </setting>
</PoorMansTSqlFormatterDemo.Properties.Settings>
</userSettings>
</configuration>
View
59 PoorMansTSqlFormatterLib/Formatters/TSqlStandardFormatter.cs
@@ -161,7 +161,10 @@ private void ProcessSqlNode(XmlElement contentElement, TSqlStandardFormattingSta
state.UnIndentInitialBreak = true;
ProcessSqlNodeList(contentElement.SelectNodes("*"), state.IncrementIndent());
state.DecrementIndent();
- state.BreakExpected = true;
+ if (Options.NewClauseLineBreaks > 0)
+ state.BreakExpected = true;
+ if (Options.NewClauseLineBreaks > 1)
+ state.AdditionalBreaksExpected = Options.NewClauseLineBreaks - 1;
break;
case SqlXmlConstants.ENAME_SET_OPERATOR_CLAUSE:
@@ -170,7 +173,7 @@ private void ProcessSqlNode(XmlElement contentElement, TSqlStandardFormattingSta
state.WhiteSpace_BreakToNextLine(); //this is the one we additionally want to apply
ProcessSqlNodeList(contentElement.SelectNodes("*"), state.IncrementIndent());
state.BreakExpected = true;
- state.AdditionalBreakExpected = true;
+ state.AdditionalBreaksExpected = 1;
break;
case SqlXmlConstants.ENAME_BATCH_SEPARATOR:
@@ -762,25 +765,33 @@ private void WhiteSpace_SeparateStatements(XmlElement contentElement, TSqlStanda
{
//check whether this is a DECLARE/SET clause with similar precedent, and therefore exempt from double-linebreak.
XmlElement thisClauseStarter = FirstSemanticElementChild(contentElement);
- if (!(thisClauseStarter != null
- && thisClauseStarter.Name.Equals(SqlXmlConstants.ENAME_OTHERKEYWORD)
- && state.GetRecentKeyword() != null
- && ((thisClauseStarter.InnerXml.ToUpperInvariant().Equals("SET")
- && state.GetRecentKeyword().Equals("SET")
- )
- || (thisClauseStarter.InnerXml.ToUpperInvariant().Equals("DECLARE")
- && state.GetRecentKeyword().Equals("DECLARE")
- )
- || (thisClauseStarter.InnerXml.ToUpperInvariant().Equals("PRINT")
- && state.GetRecentKeyword().Equals("PRINT")
- )
- )
- ))
- state.AddOutputLineBreak();
+ if (!(thisClauseStarter != null
+ && thisClauseStarter.Name.Equals(SqlXmlConstants.ENAME_OTHERKEYWORD)
+ && state.GetRecentKeyword() != null
+ && ((thisClauseStarter.InnerXml.ToUpperInvariant().Equals("SET")
+ && state.GetRecentKeyword().Equals("SET")
+ )
+ || (thisClauseStarter.InnerXml.ToUpperInvariant().Equals("DECLARE")
+ && state.GetRecentKeyword().Equals("DECLARE")
+ )
+ || (thisClauseStarter.InnerXml.ToUpperInvariant().Equals("PRINT")
+ && state.GetRecentKeyword().Equals("PRINT")
+ )
+ )
+ ))
+ {
+ for (int i = Options.NewStatementLineBreaks; i > 0; i--)
+ state.AddOutputLineBreak();
+ }
+ else
+ {
+ for (int i = Options.NewClauseLineBreaks; i > 0; i--)
+ state.AddOutputLineBreak();
+ }
- state.AddOutputLineBreak();
state.Indent(state.IndentLevel);
state.BreakExpected = false;
+ state.AdditionalBreaksExpected = 0;
state.SourceBreakPending = false;
state.StatementBreakExpected = false;
state.WordSeparatorExpected = false;
@@ -815,7 +826,7 @@ private XmlElement FirstSemanticElementChild(XmlElement contentElement)
private void WhiteSpace_SeparateWords(TSqlStandardFormattingState state)
{
- if (state.BreakExpected || state.AdditionalBreakExpected)
+ if (state.BreakExpected || state.AdditionalBreaksExpected > 0)
{
bool wasUnIndent = state.UnIndentInitialBreak;
if (wasUnIndent) state.DecrementIndent();
@@ -848,10 +859,10 @@ private void WhiteSpace_BreakAsExpected(TSqlStandardFormattingState state)
{
if (state.BreakExpected)
state.WhiteSpace_BreakToNextLine();
- if (state.AdditionalBreakExpected)
+ while (state.AdditionalBreaksExpected > 0)
{
state.WhiteSpace_BreakToNextLine();
- state.AdditionalBreakExpected = false;
+ state.AdditionalBreaksExpected--;
}
}
@@ -864,7 +875,7 @@ public TSqlStandardFormattingState(bool htmlOutput, string indentString, int spa
IndentLevel = initialIndentLevel;
HtmlOutput = htmlOutput;
IndentString = indentString;
- MaxLineWidth = maxLineWidth;
+ MaxLineWidth = maxLineWidth;
int tabCount = indentString.Split('\t').Length - 1;
int tabExtraCharacters = tabCount * (spacesPerTab - 1);
@@ -880,7 +891,7 @@ public TSqlStandardFormattingState(TSqlStandardFormattingState sourceState)
IndentString = sourceState.IndentString;
IndentLength = sourceState.IndentLength;
MaxLineWidth = sourceState.MaxLineWidth;
- //TODO: find a way out of the cross-dependent wrapping maze...
+ //TODO: find a way out of the cross-dependent wrapping maze...
//CurrentLineLength = sourceState.CurrentLineLength;
CurrentLineLength = IndentLevel * IndentLength;
CurrentLineHasContent = sourceState.CurrentLineHasContent;
@@ -894,7 +905,7 @@ public TSqlStandardFormattingState(TSqlStandardFormattingState sourceState)
public bool BreakExpected { get; set; }
public bool WordSeparatorExpected { get; set; }
public bool SourceBreakPending { get; set; }
- public bool AdditionalBreakExpected { get; set; }
+ public int AdditionalBreaksExpected { get; set; }
public bool UnIndentInitialBreak { get; set; }
public int IndentLevel { get; private set; }
View
13 PoorMansTSqlFormatterLib/Formatters/TSqlStandardFormatterOptions.cs
@@ -45,6 +45,8 @@ public TSqlStandardFormatterOptions()
HTMLColoring = false;
KeywordStandardization = false;
ExpandInLists = true;
+ NewClauseLineBreaks = 1;
+ NewStatementLineBreaks = 2;
}
//Doesn't particularly need to be lazy-loaded, and doesn't need to be threadsafe.
@@ -77,7 +79,9 @@ public TSqlStandardFormatterOptions()
else if (key == "BreakJoinOnSections") BreakJoinOnSections = Convert.ToBoolean(value);
else if (key == "HTMLColoring") HTMLColoring = Convert.ToBoolean(value);
else if (key == "KeywordStandardization") KeywordStandardization = Convert.ToBoolean(value);
- else if (key == "ExpandInExpressions") ExpandInLists = Convert.ToBoolean(value);
+ 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);
}
@@ -103,7 +107,10 @@ public string ToSerializedString()
if (BreakJoinOnSections != _defaultOptions.BreakJoinOnSections) overrides.Add("BreakJoinOnSections", BreakJoinOnSections.ToString());
if (HTMLColoring != _defaultOptions.HTMLColoring) overrides.Add("HTMLColoring", HTMLColoring.ToString());
if (KeywordStandardization != _defaultOptions.KeywordStandardization) overrides.Add("KeywordStandardization", KeywordStandardization.ToString());
- if (ExpandInLists != _defaultOptions.ExpandInLists) overrides.Add("ExpandInExpressions", ExpandInLists.ToString());
+ if (ExpandInLists != _defaultOptions.ExpandInLists) overrides.Add("ExpandInLists", ExpandInLists.ToString());
+ if (NewClauseLineBreaks != _defaultOptions.NewClauseLineBreaks) overrides.Add("NewClauseLineBreaks", NewClauseLineBreaks.ToString());
+ if (NewStatementLineBreaks != _defaultOptions.NewStatementLineBreaks) overrides.Add("NewStatementLineBreaks", NewStatementLineBreaks.ToString());
+ NewStatementLineBreaks = 2;
if (overrides.Count == 0) return string.Empty;
return string.Join(",", overrides.Select((kvp) => kvp.Key + "=" + kvp.Value).ToArray());
@@ -136,6 +143,8 @@ public string IndentString
public bool HTMLColoring { get; set; }
public bool KeywordStandardization { get; set; }
public bool ExpandInLists { get; set; }
+ public int NewClauseLineBreaks { get; set; }
+ public int NewStatementLineBreaks { get; set; }
}
}
View
44 PoorMansTSqlFormatterPluginShared/SettingsForm.Designer.cs
@@ -57,6 +57,7 @@ private void InitializeComponent()
this.chk_ExpandBooleanExpressions = new System.Windows.Forms.CheckBox();
this.chk_ExpandCaseStatements = new System.Windows.Forms.CheckBox();
this.chk_ExpandBetweenConditions = new System.Windows.Forms.CheckBox();
+ this.chk_ExpandInLists = new System.Windows.Forms.CheckBox();
this.chk_UppercaseKeywords = new System.Windows.Forms.CheckBox();
this.chk_SpaceAfterExpandedComma = new System.Windows.Forms.CheckBox();
this.chk_BreakJoinOnSections = new System.Windows.Forms.CheckBox();
@@ -74,7 +75,10 @@ private void InitializeComponent()
this.lbl_SpacesPerTab = new System.Windows.Forms.Label();
this.lbl_SpacesPerTab_Extra = new System.Windows.Forms.Label();
this.lbl_MaxLineWidth = new System.Windows.Forms.Label();
- this.chk_ExpandInLists = new System.Windows.Forms.CheckBox();
+ this.txt_StatementBreaks = new System.Windows.Forms.TextBox();
+ this.lbl_StatementBreaks = new System.Windows.Forms.Label();
+ this.txt_ClauseBreaks = new System.Windows.Forms.TextBox();
+ this.lbl_ClauseBreaks = new System.Windows.Forms.Label();
this.flowLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
@@ -138,6 +142,12 @@ private void InitializeComponent()
this.chk_ExpandBetweenConditions.Name = "chk_ExpandBetweenConditions";
this.chk_ExpandBetweenConditions.UseVisualStyleBackColor = true;
//
+ // chk_ExpandInLists
+ //
+ resources.ApplyResources(this.chk_ExpandInLists, "chk_ExpandInLists");
+ this.chk_ExpandInLists.Name = "chk_ExpandInLists";
+ this.chk_ExpandInLists.UseVisualStyleBackColor = true;
+ //
// chk_UppercaseKeywords
//
resources.ApplyResources(this.chk_UppercaseKeywords, "chk_UppercaseKeywords");
@@ -234,11 +244,25 @@ private void InitializeComponent()
resources.ApplyResources(this.lbl_MaxLineWidth, "lbl_MaxLineWidth");
this.lbl_MaxLineWidth.Name = "lbl_MaxLineWidth";
//
- // chk_ExpandInLists
+ // txt_StatementBreaks
//
- resources.ApplyResources(this.chk_ExpandInLists, "chk_ExpandInLists");
- this.chk_ExpandInLists.Name = "chk_ExpandInLists";
- this.chk_ExpandInLists.UseVisualStyleBackColor = true;
+ resources.ApplyResources(this.txt_StatementBreaks, "txt_StatementBreaks");
+ this.txt_StatementBreaks.Name = "txt_StatementBreaks";
+ //
+ // lbl_StatementBreaks
+ //
+ resources.ApplyResources(this.lbl_StatementBreaks, "lbl_StatementBreaks");
+ this.lbl_StatementBreaks.Name = "lbl_StatementBreaks";
+ //
+ // txt_ClauseBreaks
+ //
+ resources.ApplyResources(this.txt_ClauseBreaks, "txt_ClauseBreaks");
+ this.txt_ClauseBreaks.Name = "txt_ClauseBreaks";
+ //
+ // lbl_ClauseBreaks
+ //
+ resources.ApplyResources(this.lbl_ClauseBreaks, "lbl_ClauseBreaks");
+ this.lbl_ClauseBreaks.Name = "lbl_ClauseBreaks";
//
// SettingsForm
//
@@ -248,8 +272,12 @@ private void InitializeComponent()
this.CancelButton = this.btn_Cancel;
this.Controls.Add(this.lbl_MaxLineWidth);
this.Controls.Add(this.lbl_SpacesPerTab_Extra);
+ this.Controls.Add(this.lbl_ClauseBreaks);
+ this.Controls.Add(this.lbl_StatementBreaks);
this.Controls.Add(this.lbl_SpacesPerTab);
this.Controls.Add(this.txt_MaxLineWidth);
+ this.Controls.Add(this.txt_ClauseBreaks);
+ this.Controls.Add(this.txt_StatementBreaks);
this.Controls.Add(this.txt_SpacesPerTab);
this.Controls.Add(this.btn_Reset);
this.Controls.Add(this.btn_About);
@@ -298,6 +326,10 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox chk_SpaceAfterExpandedComma;
private System.Windows.Forms.CheckBox chk_StandardizeKeywords;
private System.Windows.Forms.CheckBox chk_BreakJoinOnSections;
- private System.Windows.Forms.CheckBox chk_ExpandInLists;
+ private System.Windows.Forms.CheckBox chk_ExpandInLists;
+ private System.Windows.Forms.TextBox txt_StatementBreaks;
+ private System.Windows.Forms.Label lbl_StatementBreaks;
+ private System.Windows.Forms.TextBox txt_ClauseBreaks;
+ private System.Windows.Forms.Label lbl_ClauseBreaks;
}
}
View
14 PoorMansTSqlFormatterPluginShared/SettingsForm.cs
@@ -1,7 +1,7 @@
/*
Poor Man's T-SQL Formatter - a small free Transact-SQL formatting
library for .Net 2.0, written in C#.
-Copyright (C) 2011 Tao Klerks
+Copyright (C) 2011-2013 Tao Klerks
Additional Contributors:
* Timothy Klenke, 2012
@@ -95,8 +95,10 @@ private void LoadControlValuesFromSettings()
txt_IndentString.Text = options.IndentString.Replace("\t","\\t").Replace(" ","\\s");
txt_MaxLineWidth.Text = options.MaxLineWidth.ToString();
- txt_SpacesPerTab.Text = options.SpacesPerTab.ToString();
- chk_ExpandBetweenConditions.Checked = options.ExpandBetweenConditions;
+ txt_SpacesPerTab.Text = options.SpacesPerTab.ToString();
+ txt_StatementBreaks.Text = options.NewStatementLineBreaks.ToString();
+ txt_ClauseBreaks.Text = options.NewClauseLineBreaks.ToString();
+ chk_ExpandBetweenConditions.Checked = options.ExpandBetweenConditions;
chk_ExpandBooleanExpressions.Checked = options.ExpandBooleanExpressions;
chk_ExpandCaseStatements.Checked = options.ExpandCaseStatements;
chk_ExpandCommaLists.Checked = options.ExpandCommaLists;
@@ -115,8 +117,10 @@ private void SetSettingsFromControlValues()
_settings.Options = new PoorMansTSqlFormatterLib.Formatters.TSqlStandardFormatterOptions() {
IndentString = txt_IndentString.Text,
MaxLineWidth = int.Parse(txt_MaxLineWidth.Text),
- SpacesPerTab = int.Parse(txt_SpacesPerTab.Text),
- SpaceAfterExpandedComma = chk_SpaceAfterExpandedComma.Checked,
+ SpacesPerTab = int.Parse(txt_SpacesPerTab.Text),
+ NewStatementLineBreaks = int.Parse(txt_StatementBreaks.Text),
+ NewClauseLineBreaks = int.Parse(txt_ClauseBreaks.Text),
+ SpaceAfterExpandedComma = chk_SpaceAfterExpandedComma.Checked,
ExpandBetweenConditions = chk_ExpandBetweenConditions.Checked,
ExpandBooleanExpressions = chk_ExpandBooleanExpressions.Checked,
ExpandCaseStatements = chk_ExpandCaseStatements.Checked,
View
172 PoorMansTSqlFormatterPluginShared/SettingsForm.resx
@@ -123,7 +123,7 @@
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="btn_Save.Location" type="System.Drawing.Point, System.Drawing">
- <value>289, 313</value>
+ <value>289, 368</value>
</data>
<data name="btn_Save.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -148,13 +148,13 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btn_Save.ZOrder" xml:space="preserve">
- <value>14</value>
+ <value>18</value>
</data>
<data name="btn_Cancel.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value>
</data>
<data name="btn_Cancel.Location" type="System.Drawing.Point, System.Drawing">
- <value>397, 313</value>
+ <value>397, 368</value>
</data>
<data name="btn_Cancel.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -178,7 +178,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btn_Cancel.ZOrder" xml:space="preserve">
- <value>13</value>
+ <value>17</value>
</data>
<data name="flowLayoutPanel1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value>
@@ -487,13 +487,13 @@
<value>9</value>
</data>
<data name="flowLayoutPanel1.Location" type="System.Drawing.Point, System.Drawing">
- <value>16, 151</value>
+ <value>16, 205</value>
</data>
<data name="flowLayoutPanel1.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data>
<data name="flowLayoutPanel1.Size" type="System.Drawing.Size, System.Drawing">
- <value>481, 154</value>
+ <value>481, 155</value>
</data>
<data name="flowLayoutPanel1.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
@@ -508,16 +508,16 @@
<value>$this</value>
</data>
<data name="&gt;&gt;flowLayoutPanel1.ZOrder" xml:space="preserve">
- <value>12</value>
+ <value>16</value>
</data>
<data name="txt_IndentString.Location" type="System.Drawing.Point, System.Drawing">
- <value>132, 15</value>
+ <value>150, 15</value>
</data>
<data name="txt_IndentString.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data>
<data name="txt_IndentString.Size" type="System.Drawing.Size, System.Drawing">
- <value>169, 22</value>
+ <value>151, 22</value>
</data>
<data name="txt_IndentString.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
@@ -532,7 +532,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;txt_IndentString.ZOrder" xml:space="preserve">
- <value>10</value>
+ <value>14</value>
</data>
<data name="lbl_IndentString.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -562,7 +562,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lbl_IndentString.ZOrder" xml:space="preserve">
- <value>11</value>
+ <value>15</value>
</data>
<data name="lbl_IndentHint.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -592,16 +592,16 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lbl_IndentHint.ZOrder" xml:space="preserve">
- <value>9</value>
+ <value>13</value>
</data>
<data name="txt_Hotkey.Location" type="System.Drawing.Point, System.Drawing">
- <value>132, 47</value>
+ <value>150, 47</value>
</data>
<data name="txt_Hotkey.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data>
<data name="txt_Hotkey.Size" type="System.Drawing.Size, System.Drawing">
- <value>169, 22</value>
+ <value>151, 22</value>
</data>
<data name="txt_Hotkey.TabIndex" type="System.Int32, mscorlib">
<value>9</value>
@@ -616,7 +616,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;txt_Hotkey.ZOrder" xml:space="preserve">
- <value>15</value>
+ <value>19</value>
</data>
<data name="lbl_Hotkey.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -646,7 +646,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lbl_Hotkey.ZOrder" xml:space="preserve">
- <value>8</value>
+ <value>12</value>
</data>
<data name="lbl_HotkeyHint.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -679,13 +679,13 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lbl_HotkeyHint.ZOrder" xml:space="preserve">
- <value>7</value>
+ <value>11</value>
</data>
<data name="btn_About.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="btn_About.Location" type="System.Drawing.Point, System.Drawing">
- <value>16, 313</value>
+ <value>16, 368</value>
</data>
<data name="btn_About.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -709,13 +709,13 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btn_About.ZOrder" xml:space="preserve">
- <value>6</value>
+ <value>10</value>
</data>
<data name="btn_Reset.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left</value>
</data>
<data name="btn_Reset.Location" type="System.Drawing.Point, System.Drawing">
- <value>124, 313</value>
+ <value>124, 368</value>
</data>
<data name="btn_Reset.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
@@ -739,16 +739,16 @@
<value>$this</value>
</data>
<data name="&gt;&gt;btn_Reset.ZOrder" xml:space="preserve">
- <value>5</value>
+ <value>9</value>
</data>
<data name="txt_SpacesPerTab.Location" type="System.Drawing.Point, System.Drawing">
- <value>132, 111</value>
+ <value>150, 111</value>
</data>
<data name="txt_SpacesPerTab.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data>
<data name="txt_SpacesPerTab.Size" type="System.Drawing.Size, System.Drawing">
- <value>169, 22</value>
+ <value>151, 22</value>
</data>
<data name="txt_SpacesPerTab.TabIndex" type="System.Int32, mscorlib">
<value>14</value>
@@ -763,16 +763,16 @@
<value>$this</value>
</data>
<data name="&gt;&gt;txt_SpacesPerTab.ZOrder" xml:space="preserve">
- <value>4</value>
+ <value>8</value>
</data>
<data name="txt_MaxLineWidth.Location" type="System.Drawing.Point, System.Drawing">
- <value>132, 79</value>
+ <value>150, 79</value>
</data>
<data name="txt_MaxLineWidth.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data>
<data name="txt_MaxLineWidth.Size" type="System.Drawing.Size, System.Drawing">
- <value>169, 22</value>
+ <value>151, 22</value>
</data>
<data name="txt_MaxLineWidth.TabIndex" type="System.Int32, mscorlib">
<value>15</value>
@@ -787,7 +787,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;txt_MaxLineWidth.ZOrder" xml:space="preserve">
- <value>3</value>
+ <value>5</value>
</data>
<data name="lbl_SpacesPerTab.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -817,7 +817,7 @@
<value>$this</value>
</data>
<data name="&gt;&gt;lbl_SpacesPerTab.ZOrder" xml:space="preserve">
- <value>2</value>
+ <value>4</value>
</data>
<data name="lbl_SpacesPerTab_Extra.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
@@ -879,14 +879,128 @@
<data name="&gt;&gt;lbl_MaxLineWidth.ZOrder" xml:space="preserve">
<value>0</value>
</data>
+ <data name="txt_StatementBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>150, 141</value>
+ </data>
+ <data name="txt_StatementBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 4, 4, 4</value>
+ </data>
+ <data name="txt_StatementBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>151, 22</value>
+ </data>
+ <data name="txt_StatementBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>14</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.Name" xml:space="preserve">
+ <value>txt_StatementBreaks</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.Parent" xml:space="preserve">
+ <value>$this</value>
+ </data>
+ <data name="&gt;&gt;txt_StatementBreaks.ZOrder" xml:space="preserve">
+ <value>7</value>
+ </data>
+ <data name="lbl_StatementBreaks.AutoSize" type="System.Boolean, mscorlib">
+ <value>True</value>
+ </data>
+ <data name="lbl_StatementBreaks.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+ <value>NoControl</value>
+ </data>
+ <data name="lbl_StatementBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>16, 144</value>
+ </data>
+ <data name="lbl_StatementBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 0, 4, 0</value>
+ </data>
+ <data name="lbl_StatementBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>124, 17</value>
+ </data>
+ <data name="lbl_StatementBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>16</value>
+ </data>
+ <data name="lbl_StatementBreaks.Text" xml:space="preserve">
+ <value>Statement Breaks:</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.Name" xml:space="preserve">
+ <value>lbl_StatementBreaks</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.Parent" xml:space="preserve">
+ <value>$this</value>
+ </data>
+ <data name="&gt;&gt;lbl_StatementBreaks.ZOrder" xml:space="preserve">
+ <value>3</value>
+ </data>
+ <data name="txt_ClauseBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>150, 171</value>
+ </data>
+ <data name="txt_ClauseBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 4, 4, 4</value>
+ </data>
+ <data name="txt_ClauseBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>151, 22</value>
+ </data>
+ <data name="txt_ClauseBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>14</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.Name" xml:space="preserve">
+ <value>txt_ClauseBreaks</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.Parent" xml:space="preserve">
+ <value>$this</value>
+ </data>
+ <data name="&gt;&gt;txt_ClauseBreaks.ZOrder" xml:space="preserve">
+ <value>6</value>
+ </data>
+ <data name="lbl_ClauseBreaks.AutoSize" type="System.Boolean, mscorlib">
+ <value>True</value>
+ </data>
+ <data name="lbl_ClauseBreaks.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+ <value>NoControl</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Location" type="System.Drawing.Point, System.Drawing">
+ <value>16, 174</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
+ <value>4, 0, 4, 0</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Size" type="System.Drawing.Size, System.Drawing">
+ <value>103, 17</value>
+ </data>
+ <data name="lbl_ClauseBreaks.TabIndex" type="System.Int32, mscorlib">
+ <value>16</value>
+ </data>
+ <data name="lbl_ClauseBreaks.Text" xml:space="preserve">
+ <value>Clause Breaks:</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.Name" xml:space="preserve">
+ <value>lbl_ClauseBreaks</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.Type" xml:space="preserve">
+ <value>System.Windows.Forms.Label, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.Parent" xml:space="preserve">
+ <value>$this</value>
+ </data>
+ <data name="&gt;&gt;lbl_ClauseBreaks.ZOrder" xml:space="preserve">
+ <value>2</value>
+ </data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>8, 16</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
- <value>513, 356</value>
+ <value>513, 411</value>
</data>
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
View
514 .../Data/StandardFormatSql/05_ComplexDDL(NewClauseLineBreaks=2,NewStatementLineBreaks=3).txt
@@ -0,0 +1,514 @@
+USE master
+
+GO
+
+
+IF EXISTS (
+ SELECT 1
+
+ FROM sysobjects
+
+ WHERE NAME = 'sp_ScriptTable'
+ )
+ DROP PROCEDURE sp_ScriptTable
+
+GO
+
+
+CREATE PROCEDURE sp_ScriptTable (
+ @TableName SYSNAME
+ ,@IncludeConstraints BIT = 1
+ ,@IncludeIndexes BIT = 1
+ ,@IncludeIdentity BIT = 1
+ ,@NewTableName SYSNAME = NULL
+ ,@UseSystemDataTypes BIT = 0
+ )
+AS
+BEGIN
+ /*
+
+Script taken from http://blogs.techrepublic.com.com/datacenter/?p=431&tag=content;leftCol
+Originally by Tim Chapman, August 18th, 2008.
+
+Known Issues (from blog comments, not yet fixed here):
+ - Unique indexes are missing the "Unique" keyword.
+ - VarChar(Max) is not supported
+ - Decimal fields are output with incorrect precision and scale
+
+Known Limitations:
+ - This script uses DMVs, so only works on SQL Server 2005 and later.
+
+Modifications:
+ - MarkLoew (online comment), 09/06/2009:
+ - corrected join to support same object in different schemas
+ - Tao Klerks, 2010-01-15:
+ - Changed "@MainDefinition" and "@Definition" to store NVarChar (because SQL Server does support extended characters in object names)
+ - Changed "@MainDefinition" and "@Definition" to support longer object names (2000 characters instead of 200 per line), eg indexes
+ - Changed "@ShowFields" to support longer object names (up to 255 characters rather than 100), and extended characters
+ - Added "@IncludeIdentity" to allow for removing identity columns (useful when you want to create an almost-identical table in another DB, for archiving)
+ - Added error-raising when table does not exist (result returned was slightly perplexing)
+ - Corrected NText handling to not output a data size. (even though the data size was correct, the T-SQL for table definition did not accept it, presumaly because you cannot secify a max data size for an NText column?)
+ - Added Collation Name output
+
+*/
+ DECLARE @MainDefinition TABLE (FieldValue NVARCHAR(2000))
+
+ DECLARE @DBName SYSNAME
+
+ DECLARE @ClusteredPK BIT
+
+ DECLARE @TableSchema NVARCHAR(255)
+
+
+ SET @DBName = DB_NAME(DB_ID())
+
+
+ SELECT @TableName = NAME
+
+ FROM sysobjects
+
+ WHERE id = OBJECT_ID(@TableName)
+
+
+ DECLARE @ShowFields TABLE (
+ FieldID INT IDENTITY(1, 1)
+ ,DatabaseName NVARCHAR(255)
+ ,TableOwner NVARCHAR(255)
+ ,TableName NVARCHAR(255)
+ ,FieldName NVARCHAR(255)
+ ,ColumnPosition INT
+ ,ColumnDefaultValue NVARCHAR(255)
+ ,ColumnDefaultName NVARCHAR(255)
+ ,IsNullable BIT
+ ,DataType NVARCHAR(255)
+ ,MaxLength INT
+ ,NumericPrecision INT
+ ,NumericScale INT
+ ,DomainName NVARCHAR(255)
+ ,FieldListingName NVARCHAR(255)
+ ,FieldDefinition CHAR(1)
+ ,IdentityColumn BIT
+ ,IdentitySeed INT
+ ,IdentityIncrement INT
+ ,CollationName NVARCHAR(255)
+ ,IsCharColumn BIT
+ ,IsLobColumn BIT
+ )
+
+ DECLARE @HoldingArea TABLE (
+ FldID SMALLINT IDENTITY(1, 1)
+ ,Flds VARCHAR(4000)
+ ,FldValue CHAR(1) DEFAULT(0)
+ )
+
+ DECLARE @PKObjectID TABLE (ObjectID INT)
+
+ DECLARE @Uniques TABLE (ObjectID INT)
+
+ DECLARE @HoldingAreaValues TABLE (
+ FldID SMALLINT IDENTITY(1, 1)
+ ,Flds VARCHAR(4000)
+ ,FldValue CHAR(1) DEFAULT(0)
+ )
+
+ DECLARE @Definition TABLE (
+ DefinitionID SMALLINT IDENTITY(1, 1)
+ ,FieldValue NVARCHAR(2000)
+ )
+
+
+ INSERT INTO @ShowFields (
+ DatabaseName
+ ,TableOwner
+ ,TableName
+ ,FieldName
+ ,ColumnPosition
+ ,ColumnDefaultValue
+ ,ColumnDefaultName
+ ,IsNullable
+ ,DataType
+ ,MaxLength
+ ,NumericPrecision
+ ,NumericScale
+ ,DomainName
+ ,FieldListingName
+ ,FieldDefinition
+ ,IdentityColumn
+ ,IdentitySeed
+ ,IdentityIncrement
+ ,CollationName
+ ,IsCharColumn
+ ,IsLobColumn
+ )
+
+ SELECT DB_NAME()
+ ,TABLE_SCHEMA
+ ,TABLE_NAME
+ ,COLUMN_NAME
+ ,CAST(ORDINAL_POSITION AS INT)
+ ,COLUMN_DEFAULT
+ ,dobj.NAME AS ColumnDefaultName
+ ,CASE
+ WHEN c.IS_NULLABLE = 'YES'
+ THEN 1
+ ELSE 0
+ END
+ ,DATA_TYPE
+ ,CAST(CHARACTER_MAXIMUM_LENGTH AS INT)
+ ,CAST(NUMERIC_PRECISION AS INT)
+ ,CAST(NUMERIC_SCALE AS INT)
+ ,DOMAIN_NAME
+ ,COLUMN_NAME + ','
+ ,'' AS FieldDefinition
+ ,CASE
+ WHEN ic.object_id IS NULL
+ THEN 0
+ ELSE 1
+ END AS IdentityColumn
+ ,CAST(ISNULL(ic.seed_value, 0) AS INT) AS IdentitySeed
+ ,CAST(ISNULL(ic.increment_value, 0) AS INT) AS IdentityIncrement
+ ,st.collation_name AS CollationName
+ ,CASE
+ WHEN st.collation_name IS NOT NULL
+ THEN 1
+ ELSE 0
+ END AS IsCharColumn
+ ,CASE
+ WHEN DATA_TYPE IN (
+ 'NTEXT'
+ ,'TEXT'
+ ,'IMAGE'
+ )
+ THEN 1
+ ELSE 0
+ END AS IsLobColumn
+
+ FROM INFORMATION_SCHEMA.COLUMNS c
+
+ JOIN sys.columns sc ON OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME) = sc.object_id
+ AND c.COLUMN_NAME = sc.NAME
+
+ LEFT JOIN sys.identity_columns ic ON OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME) = ic.object_id
+ AND c.COLUMN_NAME = ic.NAME
+
+ JOIN sys.types st ON COALESCE(c.DOMAIN_NAME, c.DATA_TYPE) = st.NAME
+
+ LEFT OUTER JOIN sys.objects dobj ON dobj.object_id = sc.default_object_id
+ AND dobj.type = 'D'
+
+ WHERE c.TABLE_NAME = @TableName
+
+ ORDER BY c.TABLE_NAME
+ ,c.ORDINAL_POSITION
+
+
+ IF EXISTS (
+ SELECT 1
+
+ FROM @ShowFields
+ )
+ BEGIN
+ SELECT TOP 1 @TableSchema = TableOwner
+
+ FROM @ShowFields
+
+
+ INSERT INTO @HoldingArea (Flds)
+
+ VALUES ('(')
+
+
+ INSERT INTO @Definition (FieldValue)
+
+ VALUES (
+ 'CREATE TABLE ' + CASE
+ WHEN @NewTableName IS NOT NULL
+ THEN @NewTableName
+ ELSE @DBName + '.' + @TableSchema + '.' + @TableName
+ END
+ )
+
+
+ INSERT INTO @Definition (FieldValue)
+
+ VALUES ('(')
+
+
+ INSERT INTO @Definition (FieldValue)
+
+ SELECT CHAR(10) + FieldName + ' ' + CASE
+ WHEN DomainName IS NOT NULL
+ AND @UseSystemDataTypes = 0
+ THEN DomainName + CASE
+ WHEN IsNullable = 1
+ THEN ' NULL '
+ ELSE ' NOT NULL '
+ END
+ ELSE UPPER(DataType) + CASE
+ WHEN IsCharColumn = 1
+ AND IsLobColumn = 0
+ THEN '(' + CAST(MaxLength AS VARCHAR(10)) + ')'
+ ELSE ''
+ END + CASE
+ WHEN IsCharColumn = 1
+ THEN ' COLLATE ' + CollationName + ' '
+ ELSE ''
+ END + CASE
+ WHEN IdentityColumn = 1
+ AND @IncludeIdentity = 1
+ THEN ' IDENTITY(' + CAST(IdentitySeed AS VARCHAR(5)) + ',' + CAST(IdentityIncrement AS VARCHAR(5)) + ')'
+ ELSE ''
+ END + CASE
+ WHEN IsNullable = 1
+ THEN ' NULL '
+ ELSE ' NOT NULL '
+ END + CASE
+ WHEN ColumnDefaultName IS NOT NULL
+ AND @IncludeConstraints = 1
+ THEN 'CONSTRAINT [' + ColumnDefaultName + '] DEFAULT' + UPPER(ColumnDefaultValue)
+ ELSE ''
+ END
+ END + CASE
+ WHEN FieldID = (
+ SELECT MAX(FieldID)
+
+ FROM @ShowFields
+ )
+ THEN ''
+ ELSE ','
+ END
+
+ FROM @ShowFields
+
+
+ IF @IncludeConstraints = 1
+ BEGIN
+ INSERT INTO @Definition (FieldValue)
+
+ SELECT ',CONSTRAINT [' + NAME + '] FOREIGN KEY (' + ParentColumns + ') REFERENCES [' + ReferencedObject + '](' + ReferencedColumns + ')'
+
+ FROM (
+ SELECT ReferencedObject = OBJECT_NAME(fk.referenced_object_id)
+ ,ParentObject = OBJECT_NAME(parent_object_id)
+ ,fk.NAME
+ ,REVERSE(SUBSTRING(REVERSE((
+ SELECT cp.NAME + ','
+
+ FROM sys.foreign_key_columns fkc
+
+ JOIN sys.columns cp ON fkc.parent_object_id = cp.object_id
+ AND fkc.parent_column_id = cp.column_id
+
+ WHERE fkc.constraint_object_id = fk.object_id
+
+ FOR XML PATH('')
+ )), 2, 8000)) ParentColumns
+ ,REVERSE(SUBSTRING(REVERSE((
+ SELECT cr.NAME + ','
+
+ FROM sys.foreign_key_columns fkc
+
+ JOIN sys.columns cr ON fkc.referenced_object_id = cr.object_id
+ AND fkc.referenced_column_id = cr.column_id
+
+ WHERE fkc.constraint_object_id = fk.object_id
+
+ FOR XML PATH('')
+ )), 2, 8000)) ReferencedColumns
+
+ FROM sys.foreign_keys fk
+ ) a
+
+ WHERE ParentObject = @TableName
+
+
+ INSERT INTO @Definition (FieldValue)
+
+ SELECT ',CONSTRAINT [' + NAME + '] CHECK ' + DEFINITION
+
+ FROM sys.check_constraints
+
+ WHERE OBJECT_NAME(parent_object_id) = @TableName
+
+
+ INSERT INTO @PKObjectID (ObjectID)
+
+ SELECT DISTINCT PKObject = cco.object_id
+
+ FROM sys.key_constraints cco
+
+ JOIN sys.index_columns cc ON cco.parent_object_id = cc.object_id
+ AND cco.unique_index_id = cc.index_id
+
+ JOIN sys.indexes i ON cc.object_id = i.object_id
+ AND cc.index_id = i.index_id
+
+ WHERE OBJECT_NAME(parent_object_id) = @TableName
+ AND i.type = 1
+ AND is_primary_key = 1
+
+
+ INSERT INTO @Uniques (ObjectID)
+
+ SELECT DISTINCT PKObject = cco.object_id
+
+ FROM sys.key_constraints cco
+
+ JOIN sys.index_columns cc ON cco.parent_object_id = cc.object_id
+ AND cco.unique_index_id = cc.index_id
+
+ JOIN sys.indexes i ON cc.object_id = i.object_id
+ AND cc.index_id = i.index_id
+
+ WHERE OBJECT_NAME(parent_object_id) = @TableName
+ AND i.type = 2
+ AND is_primary_key = 0
+ AND is_unique_constraint = 1
+
+
+ SET @ClusteredPK = CASE
+ WHEN @@ROWCOUNT > 0
+ THEN 1
+ ELSE 0
+ END
+
+
+ INSERT INTO @Definition (FieldValue)
+
+ SELECT ',CONSTRAINT ' + NAME + CASE type
+ WHEN 'PK'
+ THEN ' PRIMARY KEY ' + CASE
+ WHEN pk.ObjectID IS NULL
+ THEN ' NONCLUSTERED '
+ ELSE ' CLUSTERED '
+ END
+ WHEN 'UQ'
+ THEN ' UNIQUE '
+ END + CASE
+ WHEN u.ObjectID IS NOT NULL
+ THEN ' NONCLUSTERED '
+ ELSE ''
+ END + '(' + REVERSE(SUBSTRING(REVERSE((
+ SELECT c.NAME + + CASE
+ WHEN cc.is_descending_key = 1
+ THEN ' DESC'
+ ELSE ' ASC'
+ END + ','
+
+ FROM sys.key_constraints ccok
+
+ LEFT JOIN sys.index_columns cc ON ccok.parent_object_id = cc.object_id
+ AND cco.unique_index_id = cc.index_id
+
+ LEFT JOIN sys.columns c ON cc.object_id = c.object_id
+ AND cc.column_id = c.column_id
+
+ LEFT JOIN sys.indexes i ON cc.object_id = i.object_id
+ AND cc.index_id = i.index_id
+
+ WHERE i.object_id = ccok.parent_object_id
+ AND ccok.object_id = cco.object_id
+
+ FOR XML PATH('')
+ )), 2, 8000)) + ')'
+
+ FROM sys.key_constraints cco
+
+ LEFT JOIN @PKObjectID pk ON cco.object_id = pk.ObjectID
+
+ LEFT JOIN @Uniques u ON cco.object_id = u.objectID
+
+ WHERE OBJECT_NAME(cco.parent_object_id) = @TableName
+
+ END
+
+
+ INSERT INTO @Definition (FieldValue)
+
+ VALUES (')')
+
+
+ IF @IncludeIndexes = 1
+ BEGIN
+ INSERT INTO @Definition (FieldValue)
+
+ SELECT 'CREATE ' + type_desc + ' INDEX [' + [name] COLLATE SQL_Latin1_General_CP1_CI_AS + '] ON [' + OBJECT_NAME(object_id) + '] (' + REVERSE(SUBSTRING(REVERSE((
+ SELECT NAME + CASE
+ WHEN sc.is_descending_key = 1
+ THEN ' DESC'
+ ELSE ' ASC'
+ END + ','
+
+ FROM sys.index_columns sc
+
+ JOIN sys.columns c ON sc.object_id = c.object_id
+ AND sc.column_id = c.column_id
+
+ WHERE OBJECT_NAME(sc.object_id) = @TableName
+ AND sc.object_id = i.object_id
+ AND sc.index_id = i.index_id
+
+ ORDER BY index_column_id ASC
+
+ FOR XML PATH('')
+ )), 2, 8000)) + ')'
+
+ FROM sys.indexes i
+
+ WHERE OBJECT_NAME(object_id) = @TableName
+ AND CASE
+ WHEN @ClusteredPK = 1
+ AND is_primary_key = 1
+ AND type = 1
+ THEN 0
+ ELSE 1
+ END = 1
+ AND is_unique_constraint = 0
+ AND is_primary_key = 0
+
+ END
+
+
+ INSERT INTO @MainDefinition (FieldValue)
+
+ SELECT FieldValue
+
+ FROM @Definition
+
+ ORDER BY DefinitionID ASC
+
+
+ SELECT *
+
+ FROM @MainDefinition
+
+ END
+
+ ELSE
+ BEGIN
+ RAISERROR (
+ 'The provided table does not exist in this database'
+ ,16
+ ,1
+ )
+
+
+ RETURN - 1
+
+ END
+
+END
+
+GO
+
+
+EXECUTE sp_MS_marksystemobject 'sp_ScriptTable'
+
+GO
+
+
+CREATE PROCEDURE AnotherTest @FirstValue INT
+ ,@TestValue BIT = 0 OUTPUT
+AS
+SELECT 0
+
View
1 PoorMansTSqlFormatterTest/PoorMansTSqlFormatterTests.csproj
@@ -153,6 +153,7 @@
<Content Include="Data\StandardFormatSql\14_CommentPositioning%28TrailingCommas=True%29.txt" />
<Content Include="Data\StandardFormatSql\27_OtherSqlFlavourSupport.txt" />
<Content Include="Data\StandardFormatSql\24_InsertsAndOutputs%28KeywordStandardization=true,ExpandCommaLists=false%29.txt" />
+ <Content Include="Data\StandardFormatSql\05_ComplexDDL%28NewClauseLineBreaks=2,NewStatementLineBreaks=3%29.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PoorMansTSqlFormatterLib\PoorMansTSqlFormatterLib.csproj">
View
16 PoorMansTSqlFormatterWebDemo/FormatterService.asmx.cs
@@ -44,7 +44,9 @@ public string FormatTSql(string inputString)
true,
"\t",
4,
- 999,
+ 999,
+ 2,
+ 1,
true,
false,
false,
@@ -71,9 +73,11 @@ public string FormatTSql(string inputString)
string inputString,
bool reFormat,
string indent,
- int spacesPerTab,
- int maxLineWidth,
- bool expandCommaLists,
+ int spacesPerTab,
+ int maxLineWidth,
+ int statementBreaks,
+ int clauseBreaks,
+ bool expandCommaLists,
bool trailingCommas,
bool spaceAfterExpandedComma,
bool expandBooleanExpressions,
@@ -101,7 +105,9 @@ bool expandInLists
IndentString = indent,
SpacesPerTab = spacesPerTab,
MaxLineWidth = maxLineWidth,
- ExpandCommaLists = expandCommaLists,
+ NewStatementLineBreaks = statementBreaks,
+ NewClauseLineBreaks = clauseBreaks,
+ ExpandCommaLists = expandCommaLists,
TrailingCommas = trailingCommas,
SpaceAfterExpandedComma = spaceAfterExpandedComma,
ExpandBooleanExpressions = expandBooleanExpressions,

0 comments on commit 65d6853

Please sign in to comment.
Something went wrong with that request. Please try again.