Skip to content

Commit 4a26d87

Browse files
keramsdsevastianov
authored andcommitted
Support binary and timestamp output parameters
1 parent 8936d89 commit 4a26d87

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/SqlClient.Tests/SpReturnValueTests.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,17 @@ open Xunit
4444
Assert.Equal<_ list>( [ 2, Some "donkey" ], [ for x in result -> x.myId, x.myName ] )
4545
Assert.Equal(2L, total)
4646
Assert.Equal(0, returnValue) //default return value
47+
48+
[<Fact>]
49+
let BinaryOutput() =
50+
let cmd = new AdventureWorks.dbo.BinaryOutput()
51+
let _, out, returnValue = cmd.Execute()
52+
Assert.Equal<byte []>([| 0uy; 0uy; 0uy; 0uy; 42uy |], out)
53+
Assert.Equal(0, returnValue)
54+
55+
[<Fact>]
56+
let TimestampOutput() =
57+
let cmd = new AdventureWorks.dbo.TimestampOutput()
58+
let _, timestamp, returnValue = cmd.Execute()
59+
Assert.Equal<byte []>([| 0uy; 0uy; 0uy; 0uy; 0uy; 0uy; 0uy; 42uy; |], timestamp)
60+
Assert.Equal(0, returnValue)

src/SqlClient.Tests/extensions.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ GO
4646
IF OBJECT_ID('dbo.HowManyRows') IS NOT NULL
4747
DROP PROCEDURE dbo.HowManyRows;
4848
GO
49+
IF OBJECT_ID('dbo.BinaryOutput') IS NOT NULL
50+
DROP PROCEDURE dbo.BinaryOutput;
51+
GO
52+
IF OBJECT_ID('dbo.TimestampOutput') IS NOT NULL
53+
DROP PROCEDURE dbo.TimestampOutput;
54+
GO
4955
IF OBJECT_ID('dbo.TestPhoto') IS NOT NULL
5056
DROP PROCEDURE dbo.TestPhoto;
5157
GO
@@ -253,6 +259,20 @@ END
253259

254260
GO
255261

262+
CREATE PROCEDURE dbo.BinaryOutput @out AS BINARY(5) OUTPUT AS
263+
BEGIN
264+
SELECT @out = CAST(42 AS BINARY(5));
265+
END
266+
267+
GO
268+
269+
CREATE PROCEDURE dbo.TimestampOutput @timestamp TIMESTAMP OUTPUT AS
270+
BEGIN
271+
SELECT @timestamp = CAST(42 AS TIMESTAMP);
272+
END
273+
274+
GO
275+
256276
CREATE PROCEDURE dbo.TestPhoto
257277
-- Add the parameters for the stored procedure here
258278
@id int

src/SqlClient/DesignTime.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ type DesignTime private() =
5151
expr
5252
else
5353
let t = param.TypeInfo.ClrType
54-
Expr.Value(Activator.CreateInstance(t), t)
54+
55+
if t.IsArray
56+
then Expr.Value(Array.CreateInstance(t.GetElementType(), param.Size))
57+
else Expr.Value(Activator.CreateInstance(t), t)
5558

5659
<@@ (%%Expr.Value(param.Name) : string), %%Expr.Coerce(value, typeof<obj>) @@>
5760
)

src/SqlClient/ISqlCommand.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
191191
//done via reflection because not implemented on Mono
192192
let sqlDataRecordType = typeof<SqlCommand>.Assembly.GetType("Microsoft.SqlServer.Server.SqlDataRecord", throwOnError = true)
193193
p.Value <- typeof<Linq.Enumerable>.GetMethod("Cast").MakeGenericMethod(sqlDataRecordType).Invoke(null, [| value |])
194+
elif p.Direction.HasFlag(ParameterDirection.Output) && value :? Array
195+
then
196+
p.Size <- (value :?> Array).Length
194197

195198
//Execute/AsyncExecute versions
196199

0 commit comments

Comments
 (0)