Skip to content

Commit

Permalink
Fixes multiple issue in stored proc mapping from a .dacpac
Browse files Browse the repository at this point in the history
fixes #2870
  • Loading branch information
ErikEJ committed Feb 21, 2025
1 parent 64b189d commit a60fd2b
Showing 1 changed file with 16 additions and 10 deletions.
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

0 comments on commit a60fd2b

Please sign in to comment.