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

Fixes multiple issue in stored proc mapping from a .dacpac #2873

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -68,6 +68,8 @@ private static RoutineModel GetStoredProcedures(string dacpacPath, ModuleModelFa
{
if (options.FullModel)
{
procedure.HasValidResultSet = true;

procedure.Parameters = GetStoredProcedureParameters(proc);

if (options.MappedModules?.ContainsKey(key) ?? false)
Expand All @@ -78,10 +80,11 @@ private static RoutineModel GetStoredProcedures(string dacpacPath, ModuleModelFa
#pragma warning disable CA1031 // Do not catch general exception types
try
{
procedure.Results.Add(GetStoredProcedureResultElements(proc));
procedure.Results.AddRange(GetStoredProcedureResultElements(proc));
}
catch (Exception ex)
{
procedure.HasValidResultSet = false;
errors.Add($"Unable to get result set shape for {procedure.Schema}.{procedure.Name}" + Environment.NewLine + ex.ToString());
}
#pragma warning restore CA1031 // Do not catch general exception types
Expand Down Expand Up @@ -135,7 +138,7 @@ private static List<ModuleParameter> GetStoredProcedureParameters(TSqlProcedure

var newParameter = new ModuleParameter()
{
Length = parameter.Length,
Length = parameter.IsMax ? -1 : parameter.Length,
Name = parameter.Name.Parts[2].Trim('@'),
Output = parameter.IsOutput,
Precision = parameter.Precision,
Expand All @@ -161,9 +164,9 @@ private static List<ModuleParameter> GetStoredProcedureParameters(TSqlProcedure
return result;
}

private static List<ModuleResultElement> GetStoredProcedureResultElements(TSqlProcedure proc)
private static List<List<ModuleResultElement>> GetStoredProcedureResultElements(TSqlProcedure proc)
{
var result = new List<ModuleResultElement>();
var result = new List<List<ModuleResultElement>>();
var metaProc = new SqlSharpener.Model.Procedure(proc.Element);

if (metaProc.Selects == null || !metaProc.Selects.Any())
Expand All @@ -176,12 +179,15 @@ private static List<ModuleResultElement> GetStoredProcedureResultElements(TSqlPr
{
if (column.DataTypes != null)
{
result.Add(new ModuleResultElement
result.Add(new List<ModuleResultElement>
{
Name = column.Name,
Nullable = column.IsNullable,
StoreType = column.DataTypes[SqlSharpener.TypeFormat.SqlServerDbType],
Ordinal = ordinal++,
new ModuleResultElement
{
Name = column.Name,
Nullable = column.IsNullable,
StoreType = column.DataTypes[SqlSharpener.TypeFormat.SqlServerDbType],
Ordinal = ordinal++,
},
});
}
}
Expand Down