@@ -29,6 +29,19 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
29
29
30
30
let cache = new MemoryCache( name = this.GetType() .Name)
31
31
let methodsCache = new MemoryCache( name = this.GetType() .Name)
32
+
33
+ let splitKeyVal ( s : string ) =
34
+ match s.Split( ':' ) with
35
+ | [| key; value|] -> ( key.Trim() .ToLower(), value)
36
+ |_ -> invalidArg " s" " parameter must be of type key:value"
37
+
38
+ let mapFromString ( s : string ) =
39
+ match s with
40
+ | " " -> Map.empty
41
+ | x ->
42
+ x.Split( '|' )
43
+ |> Array.map splitKeyVal
44
+ |> Map.ofArray
32
45
33
46
do
34
47
this.Disposing.Add <| fun _ ->
@@ -44,10 +57,11 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
44
57
ProvidedStaticParameter( " ConfigFile" , typeof< string>, " " )
45
58
ProvidedStaticParameter( " DataDirectory" , typeof< string>, " " )
46
59
ProvidedStaticParameter( " UseReturnValue" , typeof< bool>, false )
47
- ProvidedStaticParameter( " ResultType" , typeof< ResultType>, ResultType.Records)
60
+ ProvidedStaticParameter( " ResultType" , typeof< ResultType>, ResultType.Records)
61
+ ProvidedStaticParameter( " ProcResultSets" , typeof< string>, " " )
48
62
],
49
63
instantiationFunction = ( fun typeName args ->
50
- let root = lazy this.CreateRootType( typeName, unbox args.[ 0 ], unbox args.[ 1 ], unbox args.[ 2 ], unbox args.[ 3 ], unbox args.[ 4 ])
64
+ let root = lazy this.CreateRootType( typeName, unbox args.[ 0 ], unbox args.[ 1 ], unbox args.[ 2 ], unbox args.[ 3 ], unbox args.[ 4 ], unbox args .[ 5 ] |> mapFromString )
51
65
cache.GetOrAdd( typeName, root)
52
66
)
53
67
)
@@ -59,6 +73,7 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
59
73
<param name='DataDirectory'>The name of the data directory that replaces |DataDirectory| in connection strings. The default value is the project or script directory.</param>
60
74
<param name='UseReturnValue'>To be documented.</param>
61
75
<param name='ResultType'>A value that defines structure of result: Records, Tuples, DataTable, or SqlDataReader, this affects only Stored Procedures.</param>
76
+ <param name='ProcResultSets'>String defining a dictionary using the format key1:value1|key2:value2|...</param>
62
77
"""
63
78
64
79
this.AddNamespace( nameSpace, [ providerType ])
@@ -70,7 +85,7 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
70
85
|> defaultArg
71
86
<| base .ResolveAssembly args
72
87
73
- member internal this.CreateRootType ( typeName , connectionStringOrName , configFile , dataDirectory , useReturnValue , resultType ) =
88
+ member internal this.CreateRootType ( typeName , connectionStringOrName , configFile , dataDirectory , useReturnValue , resultType , procResultSets ) =
74
89
if String.IsNullOrWhiteSpace connectionStringOrName then invalidArg " ConnectionStringOrName" " Value is empty!"
75
90
76
91
let designTimeConnectionString = DesignTimeConnectionString.Parse( connectionStringOrName, config.ResolutionFolder, configFile)
@@ -124,7 +139,7 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
124
139
125
140
schemaType.AddMembersDelayed <| fun () ->
126
141
[
127
- let routines = this.Routines( conn, schemaType.Name, udttsPerSchema, resultType, designTimeConnectionString, useReturnValue, uomPerSchema)
142
+ let routines = this.Routines( conn, schemaType.Name, udttsPerSchema, resultType, designTimeConnectionString, useReturnValue, uomPerSchema, procResultSets )
128
143
routines |> List.iter tagProvidedType
129
144
yield ! routines
130
145
@@ -159,11 +174,16 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
159
174
yield units
160
175
]
161
176
162
- member internal __.Routines ( conn , schema , uddtsPerSchema , resultType , designTimeConnectionString , useReturnValue , unitsOfMeasurePerSchema ) =
177
+ member internal __.Routines ( conn , schema , uddtsPerSchema , resultType , designTimeConnectionString , useReturnValue , unitsOfMeasurePerSchema , procResultSets : Map < string , string > ) =
163
178
[
164
179
use _ = conn.UseLocally()
165
180
let isSqlAzure = conn.IsSqlAzure
166
181
let routines = conn.GetRoutines( schema, isSqlAzure)
182
+
183
+ let appendResultSet ( commandText : string ) =
184
+ commandText + " " + defaultArg ( procResultSets.TryFind ( commandText.ToLower()) ) " "
185
+
186
+
167
187
for routine in routines do
168
188
169
189
let cmdProvidedType = ProvidedTypeDefinition( snd routine.TwoPartName, Some typeof< `` ISqlCommand Implementation `` >, HideObjectMethods = true )
@@ -176,7 +196,12 @@ type SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
176
196
use __ = conn.UseLocally()
177
197
let parameters = conn.GetParameters( routine, isSqlAzure, useReturnValue)
178
198
179
- let commandText = routine.ToCommantText( parameters)
199
+ // there is a typo in function name `ToCommantText` should be Command instead of Commant
200
+ let commandText =
201
+ if not routine.IsStoredProc
202
+ then routine.ToCommantText( parameters)
203
+ else routine.ToCommantText( parameters) |> appendResultSet
204
+
180
205
let outputColumns = DesignTime.GetOutputColumns( conn, commandText, parameters, routine.IsStoredProc)
181
206
let rank = if routine.Type = ScalarValuedFunction then ResultRank.ScalarValue else ResultRank.Sequence
182
207
0 commit comments