Skip to content

Commit 50230b3

Browse files
Fixes and features
* Fixed max length of Text Box in first tab to be large; * Addded Merge options: insert only, use star in CTE, use intesect; * Added skipping identity and primary keys in Merge in insert and intersect; * Added options in Insert: values, include default columns, not already exists;
1 parent ae69900 commit 50230b3

5 files changed

+308
-21
lines changed

SQL Format/FormSQLFormat.Designer.cs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SQL Format/SQLFormat.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1414
<Deterministic>true</Deterministic>
1515
<IsWebBootstrapper>false</IsWebBootstrapper>
16-
<PublishUrl>publish\</PublishUrl>
16+
<PublishUrl>c:\batch\</PublishUrl>
1717
<Install>true</Install>
1818
<InstallFrom>Disk</InstallFrom>
1919
<UpdateEnabled>false</UpdateEnabled>
@@ -23,8 +23,8 @@
2323
<UpdatePeriodically>false</UpdatePeriodically>
2424
<UpdateRequired>false</UpdateRequired>
2525
<MapFileExtensions>true</MapFileExtensions>
26-
<ApplicationRevision>3</ApplicationRevision>
27-
<ApplicationVersion>1.3.0.%2a</ApplicationVersion>
26+
<ApplicationRevision>7</ApplicationRevision>
27+
<ApplicationVersion>1.4.0.%2a</ApplicationVersion>
2828
<UseApplicationTrust>false</UseApplicationTrust>
2929
<PublishWizardCompleted>true</PublishWizardCompleted>
3030
<BootstrapperEnabled>true</BootstrapperEnabled>

SQL Format/SQLTranslatorInsert.cs

+96
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ public override void SetupOptionsContent(Control Parent, EventHandler changedHan
6969
Parent.Controls.Add(checkBox);
7070
}
7171

72+
{
73+
CheckBox checkBox = new CheckBox();
74+
checkBox.Text = "values";
75+
checkBox.Name = "option_values";
76+
checkBox.CheckedChanged += changedHandler;
77+
Parent.Controls.Add(checkBox);
78+
}
79+
80+
{
81+
CheckBox checkBox = new CheckBox();
82+
checkBox.Text = "include default columns";
83+
checkBox.Name = "option_default";
84+
checkBox.Checked = true;
85+
checkBox.CheckedChanged += changedHandler;
86+
Parent.Controls.Add(checkBox);
87+
}
88+
89+
{
90+
CheckBox checkBox = new CheckBox();
91+
checkBox.Text = "not already exists";
92+
checkBox.Name = "option_notalready";
93+
checkBox.Checked = false;
94+
checkBox.CheckedChanged += changedHandler;
95+
Parent.Controls.Add(checkBox);
96+
}
97+
7298
}
7399

74100
public override string TranslateExt(CreateTableStatement createTableStatement, object options)
@@ -115,6 +141,36 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
115141
}
116142
}
117143

144+
bool bOptionValues = false;
145+
if (options is Control)
146+
{
147+
var r = ((Control)options).Controls.Find("option_values", true);
148+
if (r.Length > 0)
149+
{
150+
bOptionValues = (r[0] as CheckBox).Checked;
151+
}
152+
}
153+
154+
bool bOptionDefault = true;
155+
if (options is Control)
156+
{
157+
var r = ((Control)options).Controls.Find("option_default", true);
158+
if (r.Length > 0)
159+
{
160+
bOptionDefault = (r[0] as CheckBox).Checked;
161+
}
162+
}
163+
164+
bool bNotAlready = false;
165+
if (options is Control)
166+
{
167+
var r = ((Control)options).Controls.Find("option_notalready", true);
168+
if (r.Length > 0)
169+
{
170+
bNotAlready = (r[0] as CheckBox).Checked;
171+
}
172+
}
173+
118174
string keywordSep = bOptionInline ? " " : Environment.NewLine;
119175
string optionAllias = optionAllias0;
120176
string optionAlliasDest = optionAlliasDest0;
@@ -132,6 +188,7 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
132188
sep = null;
133189
foreach (ColumnDefinition columnDefinition in tableDefinition.ColumnDefinitions)
134190
{
191+
if (!bOptionDefault && TSQLHelper.ColumnIsDefault(columnDefinition)) continue;
135192
string ident = TSQLHelper.Identifier2Value(columnDefinition.ColumnIdentifier);
136193
//if (!bOptionInline)
137194
result.Append($"{columnIdent}{sep}{ident}{sColumnSeparator}");
@@ -140,12 +197,32 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
140197
}
141198
result.Append($"){Environment.NewLine}");
142199
}
200+
201+
if (bOptionValues)
202+
{
203+
result.Append($"values(");
204+
sep = null;
205+
foreach (ColumnDefinition columnDefinition in tableDefinition.ColumnDefinitions)
206+
{
207+
if (!bOptionDefault && TSQLHelper.ColumnIsDefault(columnDefinition)) continue;
208+
string ident = TSQLHelper.Identifier2Value(columnDefinition.ColumnIdentifier);
209+
if (bOptionExplicitNames)
210+
{
211+
result.Append($"{columnIdent}{sep}{optionAllias}{ident} /*{ident}*/{sColumnSeparator}");
212+
}
213+
else result.Append($"{columnIdent}{sep}{optionAllias}{ident}{sColumnSeparator}");
214+
if (String.IsNullOrEmpty(sep)) sep = ", ";
215+
}
216+
result.Append($"){Environment.NewLine}");
217+
}
218+
else
143219
// select
144220
{
145221
result.Append($"select{keywordSep}");
146222
sep = null;
147223
foreach (ColumnDefinition columnDefinition in tableDefinition.ColumnDefinitions)
148224
{
225+
if (!bOptionDefault && TSQLHelper.ColumnIsDefault(columnDefinition)) continue;
149226
string ident = TSQLHelper.Identifier2Value(columnDefinition.ColumnIdentifier);
150227
if (bOptionExplicitNames)
151228
{
@@ -159,6 +236,25 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
159236

160237
result.Append($"{keywordSep}from {optionAllias0}{Environment.NewLine}");
161238
}
239+
240+
241+
if (bNotAlready)
242+
{
243+
result.Append($"where not exists(select 1 from {tableName} t with (nolock) where");
244+
int i = 0;
245+
foreach (ColumnDefinition columnDefinition in tableDefinition.ColumnDefinitions)
246+
{
247+
i++;
248+
if (!bOptionDefault && TSQLHelper.ColumnIsDefault(columnDefinition)) continue;
249+
string ident = TSQLHelper.Identifier2Value(columnDefinition.ColumnIdentifier);
250+
if (i > 1)
251+
result.Append($" and");
252+
result.Append($" t.{ident} = {optionAllias}{ident}");
253+
}
254+
result.Append($")");
255+
}
256+
257+
result.Append($";");
162258
return result.ToString();
163259
}
164260
}

0 commit comments

Comments
 (0)