Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlCmdVariable DefaultValue should not be written to .dacpac as per docs #656

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/DacpacTool/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
outputMessageBuilder.Append(args.TextSpan.iStartIndex);
outputMessageBuilder.Append("):");
outputMessageBuilder.Append("error ");

Check warning on line 31 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (args.Exception != null)
{
outputMessageBuilder.Append(args.Message);
Expand All @@ -40,7 +40,7 @@
outputMessageBuilder.Append(": ");
outputMessageBuilder.Append(args.Error.Message);
}

Check warning on line 43 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
return outputMessageBuilder.ToString();
}

Expand All @@ -56,7 +56,7 @@
outputMessageBuilder.Append(args.TextSpan.iStartIndex);
outputMessageBuilder.Append("): ");
outputMessageBuilder.Append("error: ");

Check warning on line 59 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
if (args.Exception != null)
{
outputMessageBuilder.Append(args.Message);
Expand All @@ -74,7 +74,7 @@
outputMessageBuilder.Append(' ');
outputMessageBuilder.Append(args.Description);
}

Check warning on line 77 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
return outputMessageBuilder.ToString();
}

Expand Down Expand Up @@ -153,7 +153,7 @@
var parts = ParseExternalParts(externalParts);
if (!string.IsNullOrEmpty(parts))
{
setMetadataMethod.Invoke(customData, new object[] {"ExternalParts", parts});

Check warning on line 156 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check warning on line 156 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@
return null;

//if either literal and variable specified for database (that is wrong situation), literal has the priority
return (string.IsNullOrEmpty(serverVariableName) ? "" : serverVariableName + ".") +

Check warning on line 200 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
(string.IsNullOrEmpty(databaseVariableLiteralValue) ? databaseVariableName : databaseVariableLiteralValue);
}

Expand All @@ -213,7 +213,7 @@
if (_ensureIsDelimitedMethod == null)
{
_ensureIsDelimitedMethod = Type.GetType("Microsoft.Data.Tools.Schema.Common.FileUtils, Microsoft.Data.Tools.Utilities")
.GetMethod("EnsureIsDelimited", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, new[]{ typeof(string) }, null);

Check warning on line 216 in src/DacpacTool/Extensions.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
}

return (string)_ensureIsDelimitedMethod.Invoke(null, new object[]{ name });
Expand Down Expand Up @@ -260,18 +260,11 @@
{
var varWithValue = variable.Split('=', 2);
var variableName = varWithValue[0];
string variableDefaultValue = string.Empty;

if (varWithValue.Length > 1 && !string.IsNullOrEmpty(varWithValue[1]))
{
variableDefaultValue = varWithValue[1];
Console.WriteLine($"Adding SqlCmd variable {variableName} with default value {variableDefaultValue}");
}
else
Console.WriteLine($"Adding SqlCmd variable {variableName}");
Console.WriteLine($"Adding SqlCmd variable {variableName}");

var setMetadataMethod = customData.GetType().GetMethod("SetMetadata", BindingFlags.Public | BindingFlags.Instance);
setMetadataMethod.Invoke(customData, new object[] { variableName, variableDefaultValue });
setMetadataMethod.Invoke(customData, new object[] { variableName, string.Empty });
}

AddCustomData(dataSchemaModel, customData);
Expand Down
1 change: 1 addition & 0 deletions test/DacpacTool.Tests/DacpacTool.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AssemblyName>MSBuild.Sdk.SqlProj.DacpacTool.Tests</AssemblyName>
<RootNamespace>MSBuild.Sdk.SqlProj.DacpacTool.Tests</RootNamespace>
<LangVersion>9.0</LangVersion>
<NuGetAudit>false</NuGetAudit>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions test/DacpacTool.Tests/PackageBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reflection;
using Microsoft.SqlServer.Dac;
using Microsoft.SqlServer.Dac.Model;
using Microsoft.SqlServer.Management.HadrModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;

Expand Down Expand Up @@ -264,15 +265,15 @@ public void AddSqlCmdvariableWithDefaultValue()
&& d.Type == "SqlCmdVariable")
.SelectMany(d => d.Items)
.Where(i => i.Name == "DbReader"
&& i.Value == "dbReaderValue")
&& i.Value == string.Empty)
.ToList().Count.ShouldBe(1);

headerParser.GetCustomData()
.Where(d => d.Category == "SqlCmdVariables"
&& d.Type == "SqlCmdVariable")
.SelectMany(d => d.Items)
.Where(i => i.Name == "DbWriter"
&& i.Value == "dbWriterValue")
&& i.Value == string.Empty)
.ToList().Count.ShouldBe(1);

// Cleanup
Expand Down
Loading