Skip to content

Commit 001a22f

Browse files
Merge branch 'master' into try-designtime-netstandard-support
2 parents 6a97e2b + f58b26e commit 001a22f

9 files changed

Lines changed: 66 additions & 14 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ local.properties
4646
*.suo
4747
*.user
4848
*.sln.docstates
49-
49+
launchSettings.json
5050
# Build results
5151

5252
[Dd]ebug/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ More information can be found in the [documentation](http://fsprojects.github.io
103103

104104
The default maintainer account for projects under "fsprojects" is [@fsprojectsgit](https://github.com/fsprojectsgit) - F# Community Project Incubation Space (repo management)
105105

106+
Thanks Jetbrains for their open source license program and providing their tool.

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#### 2.0.4 May 27, 2019
2+
3+
* Issue #340 Some primitive types such as Guid weren't supported as output parameters.
4+
5+
Contributor(s): Jérémie Chassaing (https://github.com/thinkbeforecoding)
6+
17
#### 2.0.3 April 15, 2019
28
* Issue #332 Invalidate SqlFile type when referenced SQL file is modified.
39

src/SqlClient.DesignTime/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ open System.Runtime.CompilerServices
66
[<assembly: AssemblyTitleAttribute("SqlClient.DesignTime")>]
77
[<assembly: AssemblyProductAttribute("FSharp.Data.SqlClient.DesignTime")>]
88
[<assembly: AssemblyDescriptionAttribute("SqlClient F# type providers")>]
9-
[<assembly: AssemblyVersionAttribute("2.0.3")>]
10-
[<assembly: AssemblyFileVersionAttribute("2.0.3")>]
9+
[<assembly: AssemblyVersionAttribute("2.0.4")>]
10+
[<assembly: AssemblyFileVersionAttribute("2.0.4")>]
1111
[<assembly: InternalsVisibleToAttribute("SqlClient.Tests")>]
1212
do ()
1313

1414
module internal AssemblyVersionInformation =
1515
let [<Literal>] AssemblyTitle = "SqlClient.DesignTime"
1616
let [<Literal>] AssemblyProduct = "FSharp.Data.SqlClient.DesignTime"
1717
let [<Literal>] AssemblyDescription = "SqlClient F# type providers"
18-
let [<Literal>] AssemblyVersion = "2.0.3"
19-
let [<Literal>] AssemblyFileVersion = "2.0.3"
18+
let [<Literal>] AssemblyVersion = "2.0.4"
19+
let [<Literal>] AssemblyFileVersion = "2.0.4"
2020
let [<Literal>] InternalsVisibleTo = "SqlClient.Tests"

src/SqlClient.DesignTime/DesignTime.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ type DesignTime private() =
7878

7979
if t.IsArray
8080
then Expr.Value(Array.CreateInstance(t.GetElementType(), param.Size))
81-
else Expr.Value(Activator.CreateInstance(t), t)
81+
elif t.IsPrimitive then
82+
Expr.Value(Activator.CreateInstance(t), t)
83+
else
84+
Expr.DefaultValue(t)
8285

8386
<@@ (%%Expr.Value(param.Name) : string), %%Expr.Coerce(value, typeof<obj>) @@>
8487
)
@@ -100,9 +103,10 @@ type DesignTime private() =
100103
if sqlParam.Direction.HasFlag( ParameterDirection.Output)
101104
then
102105
let mi =
103-
typeof<Mapper>
104-
.GetMethod("SetRef")
105-
.MakeGenericMethod( sqlParam.TypeInfo.ClrType)
106+
ProvidedTypeBuilder.MakeGenericMethod(
107+
typeof<Mapper>
108+
.GetMethod("SetRef"),
109+
[sqlParam.TypeInfo.ClrType])
106110
Expr.Call(mi, [ argExpr; Expr.Var arr; Expr.Value index ]) |> Some
107111
else
108112
None

src/SqlClient/AssemblyInfo.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ open System.Runtime.CompilerServices
66
[<assembly: AssemblyTitleAttribute("SqlClient")>]
77
[<assembly: AssemblyProductAttribute("FSharp.Data.SqlClient")>]
88
[<assembly: AssemblyDescriptionAttribute("SqlClient F# type providers")>]
9-
[<assembly: AssemblyVersionAttribute("2.0.3")>]
10-
[<assembly: AssemblyFileVersionAttribute("2.0.3")>]
9+
[<assembly: AssemblyVersionAttribute("2.0.4")>]
10+
[<assembly: AssemblyFileVersionAttribute("2.0.4")>]
1111
[<assembly: InternalsVisibleToAttribute("SqlClient.Tests")>]
1212
do ()
1313

1414
module internal AssemblyVersionInformation =
1515
let [<Literal>] AssemblyTitle = "SqlClient"
1616
let [<Literal>] AssemblyProduct = "FSharp.Data.SqlClient"
1717
let [<Literal>] AssemblyDescription = "SqlClient F# type providers"
18-
let [<Literal>] AssemblyVersion = "2.0.3"
19-
let [<Literal>] AssemblyFileVersion = "2.0.3"
18+
let [<Literal>] AssemblyVersion = "2.0.4"
19+
let [<Literal>] AssemblyFileVersion = "2.0.4"
2020
let [<Literal>] InternalsVisibleTo = "SqlClient.Tests"

src/SqlClient/Shared.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ type Mapper private() =
3535
mapper values
3636

3737
static member SetRef<'t>(r : byref<'t>, arr: (string * obj)[], i) =
38-
r <- arr.[i] |> snd |> unbox
38+
let value = arr.[i] |> snd
39+
r <-
40+
match value with
41+
| :? 't as v -> v
42+
| _ (* dbnull *) -> Unchecked.defaultof<'t>
3943

4044
type Column = {
4145
Name: string

tests/SqlClient.Tests/ProgrammabilityTests.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ let ResultSetAndOutParam() =
232232
Assert.Equal<_ list>([ Some "donkey" ], [ for x in result -> x.myName ] )
233233
Assert.Equal(2L, !total)
234234

235+
// Fix #340:
236+
// The type provider cannot use Expr.Value(Activator.CreateInstance(t),t) for
237+
// non primitive types, like System.Guid.
238+
// It now use Expr.DefaultValue(t) for non primite types.
239+
// The PassGuid SP copies the input guid to the output parameter when the boolean
240+
// parameter is true, and let the out parameter uninitialized when false
241+
[<Fact>]
242+
let NonPrimitiveOutParam() =
243+
let guid = Guid.NewGuid()
244+
let cmd = new AdventureWorks.dbo.PassGuid()
245+
let _,result = cmd.Execute(guid, true)
246+
Assert.Equal(guid, result)
247+
248+
// Fix #340:
249+
// When an output parameter has not been set, its value is DBNull which cannot
250+
// be unboxed. The fix sets the parameter to defaultOf<'t>.
251+
// The PassGuid SP copies the input guid to the output parameter when the boolean
252+
// parameter is true, and let the out parameter uninitialized when false
253+
[<Fact>]
254+
let NonPrimitiveNullOutParam() =
255+
let guid = Guid.NewGuid()
256+
let cmd = new AdventureWorks.dbo.PassGuid()
257+
let _,result = cmd.Execute(guid, false)
258+
Assert.Equal(Guid.Empty, result)
235259

236260
[<Fact>]
237261
let PassingImageAsParamDoesntGetCut() =

tests/SqlClient.Tests/extensions.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ USE AdventureWorks2012
77
IF OBJECT_ID('dbo.AddRef') IS NOT NULL
88
DROP PROCEDURE dbo.AddRef;
99
GO
10+
IF OBJECT_ID('dbo.PassGuid') IS NOT NULL
11+
DROP PROCEDURE dbo.PassGuid;
12+
GO
1013
IF OBJECT_ID('dbo.MyProc') IS NOT NULL
1114
DROP PROCEDURE dbo.MyProc;
1215
GO
@@ -169,6 +172,16 @@ BEGIN
169172
END
170173
GO
171174

175+
CREATE PROCEDURE dbo.PassGuid @x AS UNIQUEIDENTIFIER, @b AS BIT, @result AS UNIQUEIDENTIFIER OUTPUT
176+
AS
177+
BEGIN
178+
IF (@b = 1)
179+
BEGIN
180+
SET @result = @x
181+
END
182+
END
183+
GO
184+
172185
CREATE PROCEDURE dbo.MyProc @p1 dbo.MyTableType readonly AS
173186
BEGIN
174187
SELECT * from @p1 p

0 commit comments

Comments
 (0)