Skip to content

Commit 7369781

Browse files
committed
Add -ReplaceVariablesInComments switch to Expand-SqlCmdDirectives.
1 parent b8adefc commit 7369781

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Most lines should begin with one of these words:
1313
- Change `Cmdlet`, renaming to `PSqlCmdlet`.
1414
- Remove `IConsole`, replacing it with a simpler `ISqlMessageLogger`.
1515
- Update Microsoft.Data.SqlClient to [5.2.2](https://github.com/dotnet/SqlClient/blob/main/release-notes/5.2/5.2.2.md)
16+
- Add `-ReplaceVariablesInComments` switch to `Expand-SqlCmdDirectives`.
1617
- Add retries on transient failures.
1718
- Fix `EncryptionMode.Default` requiring certificate validation for local
1819
connections.

PSql.Engine/SqlCmdPreprocessor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public SqlCmdPreprocessor()
1919
_preprocessor = new();
2020
}
2121

22+
/// <inheritdoc cref="Prequel.SqlCmdPreprocessor.EnableVariableReplacementInComments"/>
23+
public bool EnableVariableReplacementInComments
24+
{
25+
get => _preprocessor.EnableVariableReplacementInComments;
26+
set => _preprocessor.EnableVariableReplacementInComments = value;
27+
}
28+
2229
/// <summary>
2330
/// Defines the specified <c>sqlcmd</c> variables.
2431
/// </summary>

PSql/Commands/ExpandSqlCmdDirectivesCommand.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ public class ExpandSqlCmdDirectivesCommand : PSqlCmdlet
2727
[Parameter(Position = 1)]
2828
public Hashtable? Define { get; set; }
2929

30+
/// <summary>
31+
/// <b>-ReplaceVariablesInComments</b>
32+
/// Perform SQLCMD variable replacement inside SQL comments.
33+
/// </summary>
34+
[Parameter]
35+
public SwitchParameter ReplaceVariablesInComments
36+
{
37+
get => _preprocessor.EnableVariableReplacementInComments;
38+
set => _preprocessor.EnableVariableReplacementInComments = value;
39+
}
40+
3041
private readonly E.SqlCmdPreprocessor _preprocessor;
3142

3243
/// <summary>

PSql/en-US/PSql.dll-help.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
<maml:name>Define</maml:name>
223223
<command:parameterValue required="true">hashtable</command:parameterValue>
224224
</command:parameter>
225+
<command:parameter required="false" position="named" pipelineInput="False" globbing="false">
226+
<maml:name>ReplaceVariablesInComments</maml:name>
227+
</command:parameter>
225228
</command:syntaxItem>
226229
</command:syntax>
227230

@@ -251,6 +254,18 @@
251254
<dev:defaultValue>None</dev:defaultValue>
252255
</command:parameter>
253256

257+
<command:parameter required="false" position="named" pipelineInput="False" globbing="false" aliases="none">
258+
<maml:name>ReplaceVariablesInComments</maml:name>
259+
<maml:description>
260+
<maml:para>Perform SQLCMD variable replacement inside SQL comments.</maml:para>
261+
</maml:description>
262+
<command:parameterValue required="false">SwitchParameter</command:parameterValue>
263+
<dev:type>
264+
<maml:name>System.Management.Automation.SwitchParameter</maml:name>
265+
</dev:type>
266+
<dev:defaultValue>False</dev:defaultValue>
267+
</command:parameter>
268+
254269
</command:parameters>
255270

256271
<command:inputTypes>

0 commit comments

Comments
 (0)