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

Add user defined function call support for MSSQL #781

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
70 changes: 37 additions & 33 deletions src/SQLProvider.Runtime/Providers.MsSqlServer.Ssdt.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ module MSSqlServerSsdt =
sb.AppendLine(s.FullName) |> ignore
failwith (sb.ToString())


/// Tries to parse a schema model from the given .dacpac file path.
let parseDacpac = findDacPacFile >> extractModelXml >> parseXml

Expand Down Expand Up @@ -367,38 +366,43 @@ type internal MSSqlServerProviderSsdt(tableNames: string, ssdtPath: string) =
)

member __.GetSprocs(con) =
ssdtSchema.Value.StoredProcs
|> List.map (fun sp ->
let inParams =
sp.Parameters
|> List.mapi (fun idx p ->
{ Name = p.Name
TypeMapping = MSSqlServerSsdt.tryFindMappingOrVariant (ssdtSchema.Value.UserDefinedDataTypes) p.DataType
Direction = if p.IsOutput then ParameterDirection.InputOutput else ParameterDirection.Input
Length = p.Length
Ordinal = idx }
)
let outParams =
sp.Parameters
|> List.filter (fun p -> p.IsOutput)
|> List.mapi (fun idx p ->
{ Name = p.Name
TypeMapping = MSSqlServerSsdt.tryFindMappingOrVariant (ssdtSchema.Value.UserDefinedDataTypes) p.DataType
Direction = ParameterDirection.InputOutput
Length = p.Length
Ordinal = idx }
)

// If no outParams, add a "ResultSet" property (see issue #706)
let outParams =
match outParams with
| [] -> [ sprocReturnParam 0 ]
| _ -> outParams

let spName = { ProcName = sp.Name; Owner = sp.Schema; PackageName = sp.Schema; }

Root("Procedures", Sproc({ Name = spName; Params = (fun con -> inParams); ReturnColumns = (fun con sparams -> outParams) }))
)
let convertExecutable type' elems =
elems
|> List.map (fun sp ->
let inParams =
sp.Parameters
|> List.mapi (fun idx p ->
{ Name = p.Name
TypeMapping = MSSqlServerSsdt.tryFindMappingOrVariant (ssdtSchema.Value.UserDefinedDataTypes) p.DataType
Direction = if p.IsOutput then ParameterDirection.InputOutput else ParameterDirection.Input
Length = p.Length
Ordinal = idx }
)
let outParams =
sp.Parameters
|> List.filter (fun p -> p.IsOutput)
|> List.mapi (fun idx p ->
{ Name = p.Name
TypeMapping = MSSqlServerSsdt.tryFindMappingOrVariant (ssdtSchema.Value.UserDefinedDataTypes) p.DataType
Direction = ParameterDirection.InputOutput
Length = p.Length
Ordinal = idx }
)

// If no outParams, add a "ResultSet" property (see issue #706)
let outParams =
match outParams with
| [] -> [ sprocReturnParam 0 ]
| _ -> outParams

let spName = { ProcName = sp.Name; Owner = sp.Schema; PackageName = sp.Schema; }

Root(type', Sproc({ Name = spName; Params = (fun con -> inParams); ReturnColumns = (fun con sparams -> outParams) }))
)
let sprocs = convertExecutable "Procedures" ssdtSchema.Value.StoredProcs
let funcs = convertExecutable "Functions" ssdtSchema.Value.Functions
List.append sprocs funcs

member __.GetIndividualsQueryText(table,amount) = String.Empty // Not implemented for SSDT
member __.GetIndividualQueryText(table,column) = String.Empty // Not implemented for SSDT

Expand Down
14 changes: 13 additions & 1 deletion src/SQLProvider.Runtime/Ssdt.DacpacParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type SsdtSchema = {
Relationships: SsdtRelationship list
Descriptions: SsdtDescriptionItem list
UserDefinedDataTypes: SsdtUserDefinedDataType
Functions: SsdtStoredProc list
}
and SsdtTable = {
FullName: string
Expand Down Expand Up @@ -412,6 +413,16 @@ let parseXml(xml: string) =
|> Seq.map parseUserDefinedDataType
|> Map.ofSeq

let functions =
let filterPredicate elem =
(att "Type" elem) = "SqlScalarFunction"
|| (att "Type" elem) = "SqlInlineTableValuedFunction"
model
|> nodes "x:Element"
|> Seq.filter filterPredicate
|> Seq.map parseStoredProc
|> Seq.toList

let storedProcs =
model
|> nodes "x:Element"
Expand Down Expand Up @@ -492,4 +503,5 @@ let parseXml(xml: string) =
TryGetTableByName = fun nm -> tablesAndViews |> (List.tryFind (fun t -> t.Name = nm) >> function Some x -> ValueSome x | None -> ValueNone)
Relationships = relationships
Descriptions = descriptions
UserDefinedDataTypes = userDefinedDataTypes } : SsdtSchema
UserDefinedDataTypes = userDefinedDataTypes
Functions = functions } : SsdtSchema