Visitar URL original
Sync Repos: Release 180.102.0 (#230) · microsoft/SqlScriptDOM@b583737 · GitHub
Skip to content

Commit b583737

Browse files
allancascanteAllan Cascante
andauthored
Sync Repos: Release 180.102.0 (#230)
* Fix INSERT VALUES alignment * Add configurable batch newline options * Fix CREATE DATABASE COLLATE option ordering * Add multiline WITH and OPTION formatting * Add Fabric DW GROUP BY ALL and ORDER BY ALL support * Fix SPARSE before MASKED column parsing (#216) * Add block statement terminator option * Add trailing GO preservation option * Add built-in function casing option * Add multiline query clause formatting options * Add configurable leading comma spacing * Fix nested function formatting with parameter comments * Adding release notes for 180.102.0 --------- Co-authored-by: Allan Cascante <acascante@microsoft.com>
1 parent 01aa17b commit b583737

102 files changed

Lines changed: 7004 additions & 1139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎SqlScriptDom/Parser/TSql/Ast.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,6 +3550,8 @@
35503550
</Class>
35513551
<Class Name="OrderByClause" Summary="Represents the order by clause that can be used in statements like select.">
35523552
<Member Name="OrderByElements" Type="ExpressionWithSortOrder" Collection="true" Summary="The items."/>
3553+
<Member Name="All" Type="bool" Summary="True if the ORDER BY ALL shorthand is used, which orders by every column in the select list. When true, OrderByElements is empty."/>
3554+
<Member Name="AllSortOrder" Type="SortOrder" GenerateUpdatePositionInfoCall="false" Summary="The sort order (ASC/DESC) applied to ORDER BY ALL. Only meaningful when All is true."/>
35533555
</Class>
35543556
<Class Name="JoinTableReference" Base="TableReference" Abstract="true" Summary="Base class for JOIN table references">
35553557
<Member Name="FirstTableReference" Type="TableReference" Summary="The first table reference."/>
@@ -4046,6 +4048,7 @@
40464048
</Class>
40474049
<Class Name="TSqlScript" Summary="Represents a TSql sript.">
40484050
<Member Name="Batches" Type="TSqlBatch" Collection ="true" Summary="Batches in the script."/>
4051+
<Member Name="TrailingGoCount" Type="int" Summary="The number of consecutive trailing GO batch separators at the end of the script (0 if none)."/>
40494052
</Class>
40504053
<Class Name="TSqlBatch" Summary="Represents a batch in T-SQL script." >
40514054
<Member Name="Statements" Type="TSqlStatement" Collection="true" Summary="A list of statements, possibly empty."/>

‎SqlScriptDom/Parser/TSql/OptionsHelper.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public OptionType Value
6767
{
6868
get { return _optionValue; }
6969
}
70+
71+
public string Identifier
72+
{
73+
get { return _identifier; }
74+
}
7075
}
7176

7277
private Dictionary<OptionType, OptionInfo> _optionToOptionInfo = new Dictionary<OptionType, OptionInfo>();
@@ -208,6 +213,21 @@ internal bool TryGenerateSourceForOption(ScriptWriter writer, OptionType option)
208213
return false;
209214
}
210215

216+
// Exposes the literal source text of identifier-backed options so callers can apply their own
217+
// casing; returns false for token-backed options, whose text comes from the token table.
218+
internal bool TryGetOptionIdentifier(OptionType option, out string identifier)
219+
{
220+
OptionInfo optionInfo;
221+
if (_optionToOptionInfo.TryGetValue(option, out optionInfo) && optionInfo.Identifier != null)
222+
{
223+
identifier = optionInfo.Identifier;
224+
return true;
225+
}
226+
227+
identifier = null;
228+
return false;
229+
}
230+
211231
internal void GenerateCommaSeparatedFlagOptions(ScriptWriter writer, OptionType options)
212232
{
213233
bool first = true;

‎SqlScriptDom/Parser/TSql/TSql100.g‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*

‎SqlScriptDom/Parser/TSql/TSql110.g‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -2677,6 +2681,10 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
26772681
vResult.DatabaseName = vIdentifier;
26782682
ThrowPartialAstIfPhaseOne(vResult);
26792683
}
2684+
// NOTE: Unlike TSql120+, azureOptions and the collationOpt branch here are mutually-exclusive
2685+
// alternatives, so COLLATE and Azure edition options cannot coexist in either order. The
2686+
// COLLATE-before-options fix applied to TSql120-180/FabricDW is intentionally NOT ported here:
2687+
// it would require restructuring these alternatives into sequential optionals (a larger change).
26802688
(
26812689
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2)}?
26822690
azureOptions[vResult, vResult.Options]

‎SqlScriptDom/Parser/TSql/TSql120.g‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -2771,6 +2775,13 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
27712775
)?
27722776
recoveryUnitList[vResult]
27732777
collationOpt[vResult]
2778+
(
2779+
// Azure SQL: parenthesized edition options may follow COLLATE.
2780+
// Limitation: each azureOptions invocation checks SQL46049 duplicates only within its own
2781+
// group, so an option repeated across the pre- and post-COLLATE groups is not flagged.
2782+
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2) || NextTokenMatches(CodeGenerationSupporter.ServiceObjective,2)}?
2783+
azureOptions[vResult, vResult.Options]
2784+
)?
27742785
(
27752786
dbAddendums[vResult]
27762787
)?

‎SqlScriptDom/Parser/TSql/TSql130.g‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -3530,6 +3534,13 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
35303534
)?
35313535
recoveryUnitList[vResult]
35323536
collationOpt[vResult]
3537+
(
3538+
// Azure SQL: parenthesized edition options may follow COLLATE.
3539+
// Limitation: each azureOptions invocation checks SQL46049 duplicates only within its own
3540+
// group, so an option repeated across the pre- and post-COLLATE groups is not flagged.
3541+
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2) || NextTokenMatches(CodeGenerationSupporter.ServiceObjective,2)}?
3542+
azureOptions[vResult, vResult.Options]
3543+
)?
35333544
(
35343545
dbAddendums[vResult]
35353546
)?
@@ -26975,6 +26986,11 @@ regularColumnBody [IndexAffectingStatement statementType, ColumnDefinition vPare
2697526986
vParent.StorageOptions = vStorageOptions;
2697626987
}
2697726988
)?
26989+
// MASKED WITH may follow the storage options (documented SPARSE-before-MASKED order)
26990+
(
26991+
{NextTokenMatches(CodeGenerationSupporter.Masked)}?
26992+
maskedClause[vParent]
26993+
)?
2697826994
)?
2697926995
{
2698026996
VerifyColumnDataType(vParent);

‎SqlScriptDom/Parser/TSql/TSql140.g‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -3904,6 +3908,13 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
39043908
)?
39053909
recoveryUnitList[vResult]
39063910
collationOpt[vResult]
3911+
(
3912+
// Azure SQL: parenthesized edition options may follow COLLATE.
3913+
// Limitation: each azureOptions invocation checks SQL46049 duplicates only within its own
3914+
// group, so an option repeated across the pre- and post-COLLATE groups is not flagged.
3915+
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2) || NextTokenMatches(CodeGenerationSupporter.ServiceObjective,2)}?
3916+
azureOptions[vResult, vResult.Options]
3917+
)?
39073918
(
39083919
dbAddendums[vResult]
39093920
)?
@@ -27713,6 +27724,11 @@ regularColumnBody [IndexAffectingStatement statementType, ColumnDefinition vPare
2771327724
vParent.StorageOptions = vStorageOptions;
2771427725
}
2771527726
)?
27727+
// MASKED WITH may follow the storage options (documented SPARSE-before-MASKED order)
27728+
(
27729+
{NextTokenMatches(CodeGenerationSupporter.Masked)}?
27730+
maskedClause[vParent]
27731+
)?
2771627732
)?
2771727733
(
2771827734
{NextTokenMatches(CodeGenerationSupporter.Hidden)}?

‎SqlScriptDom/Parser/TSql/TSql150.g‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -4427,6 +4431,13 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
44274431
)?
44284432
recoveryUnitList[vResult]
44294433
collationOpt[vResult]
4434+
(
4435+
// Azure SQL: parenthesized edition options may follow COLLATE.
4436+
// Limitation: each azureOptions invocation checks SQL46049 duplicates only within its own
4437+
// group, so an option repeated across the pre- and post-COLLATE groups is not flagged.
4438+
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2) || NextTokenMatches(CodeGenerationSupporter.ServiceObjective,2)}?
4439+
azureOptions[vResult, vResult.Options]
4440+
)?
44304441
(
44314442
dbAddendums[vResult]
44324443
)?
@@ -28553,6 +28564,11 @@ regularColumnBody [IndexAffectingStatement statementType, ColumnDefinition vPare
2855328564
vParent.StorageOptions = vStorageOptions;
2855428565
}
2855528566
)?
28567+
// MASKED WITH may follow the storage options (documented SPARSE-before-MASKED order)
28568+
(
28569+
{NextTokenMatches(CodeGenerationSupporter.Masked)}?
28570+
maskedClause[vParent]
28571+
)?
2855628572
)?
2855728573
(
2855828574
{NextTokenMatches(CodeGenerationSupporter.Hidden)}?

‎SqlScriptDom/Parser/TSql/TSql160.g‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -4447,6 +4451,13 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
44474451
)?
44484452
recoveryUnitList[vResult]
44494453
collationOpt[vResult]
4454+
(
4455+
// Azure SQL: parenthesized edition options may follow COLLATE.
4456+
// Limitation: each azureOptions invocation checks SQL46049 duplicates only within its own
4457+
// group, so an option repeated across the pre- and post-COLLATE groups is not flagged.
4458+
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2) || NextTokenMatches(CodeGenerationSupporter.ServiceObjective,2)}?
4459+
azureOptions[vResult, vResult.Options]
4460+
)?
44504461
(
44514462
dbAddendums[vResult]
44524463
)?
@@ -29033,6 +29044,11 @@ regularColumnBody [IndexAffectingStatement statementType, ColumnDefinition vPare
2903329044
vParent.StorageOptions = vStorageOptions;
2903429045
}
2903529046
)?
29047+
// MASKED WITH may follow the storage options (documented SPARSE-before-MASKED order)
29048+
(
29049+
{NextTokenMatches(CodeGenerationSupporter.Masked)}?
29050+
maskedClause[vParent]
29051+
)?
2903629052
)?
2903729053
(
2903829054
{NextTokenMatches(CodeGenerationSupporter.Hidden)}?

‎SqlScriptDom/Parser/TSql/TSql170.g‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ script returns [TSqlScript vResult = this.FragmentFactory.CreateFragment<TSqlScr
133133
(
134134
Go
135135
{
136+
vResult.TrailingGoCount++;
136137
ResetQuotedIdentifiersSettingToInitial();
137138
ThrowPartialAstIfPhaseOne(null);
138139
}
139140
vCurrentBatch = batch
140141
{
141142
if (vCurrentBatch != null)
143+
{
142144
AddAndUpdateTokenInfo(vResult, vResult.Batches, vCurrentBatch);
145+
vResult.TrailingGoCount = 0;
146+
}
143147
}
144148

145149
)*
@@ -4496,6 +4500,13 @@ createDatabase returns [CreateDatabaseStatement vResult = FragmentFactory.Create
44964500
)?
44974501
recoveryUnitList[vResult]
44984502
collationOpt[vResult]
4503+
(
4504+
// Azure SQL: parenthesized edition options may follow COLLATE.
4505+
// Limitation: each azureOptions invocation checks SQL46049 duplicates only within its own
4506+
// group, so an option repeated across the pre- and post-COLLATE groups is not flagged.
4507+
{NextTokenMatches(CodeGenerationSupporter.MaxSize,2) || NextTokenMatches(CodeGenerationSupporter.Edition,2) || NextTokenMatches(CodeGenerationSupporter.ServiceObjective,2)}?
4508+
azureOptions[vResult, vResult.Options]
4509+
)?
44994510
(
45004511
dbAddendums[vResult]
45014512
)?
@@ -29729,6 +29740,11 @@ regularColumnBody [IndexAffectingStatement statementType, ColumnDefinition vPare
2972929740
vParent.StorageOptions = vStorageOptions;
2973029741
}
2973129742
)?
29743+
// MASKED WITH may follow the storage options (documented SPARSE-before-MASKED order)
29744+
(
29745+
{NextTokenMatches(CodeGenerationSupporter.Masked)}?
29746+
maskedClause[vParent]
29747+
)?
2973229748
)?
2973329749
(
2973429750
{NextTokenMatches(CodeGenerationSupporter.Hidden)}?

0 commit comments

Comments
 (0)