Skip to content

Commit 06d6fba

Browse files
author
Chai Natan
committed
Fix for binary table valued parameters
1 parent eb45a54 commit 06d6fba

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/SqlClient.DesignTime/SqlClientExtensions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let internal providerTypes =
159159
"sysname", (SqlDbType.NVarChar, "System.String", false)
160160

161161
// binary
162-
"binary", (SqlDbType.Binary, "System.Byte[]", true)
162+
"binary", (SqlDbType.Binary, "System.Byte[]", false)
163163
"image", (SqlDbType.Image, "System.Byte[]", false)
164164
"varbinary", (SqlDbType.VarBinary, "System.Byte[]", false)
165165

tests/SqlClient.Tests/TVPTests.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,19 @@ let ``issue #393 troubleshoot if datetimeoffset raises an exception`` () =
207207
let tvp = [AdventureWorks.dbo.``User-Defined Table Types``.datetimeoffset_test_tvp(value)]
208208
use cmd = new AdventureWorks.dbo.datetimeoffset_test(ConnectionStrings.AdventureWorksLiteral)
209209
let resultvalue = cmd.Execute(tvp) |> Seq.head
210-
Assert.Equal(value, resultvalue)
210+
Assert.Equal(value, resultvalue)
211+
212+
type FixedLengthBinaryTVP = SqlCommandProvider<"EXEC [dbo].[FixedLengthBinaryTVPTestProc] @fixedLengthBinaryTests", ConnectionStrings.AdventureWorksLiteral>
213+
[<Fact>]
214+
let ``Using Fixed Length Binary TVP``() =
215+
printfn "%s" ConnectionStrings.AdventureWorksLiteral
216+
use cmd = new FixedLengthBinaryTVP(ConnectionStrings.AdventureWorksLiteral)
217+
218+
[
219+
[|1uy;2uy;3uy|]
220+
[|4uy;5uy;6uy|]
221+
[|7uy;8uy;9uy|]
222+
]
223+
|> Seq.map (fun d -> FixedLengthBinaryTVP.FixedLengthBinaryTVPTest (Some d))
224+
|> cmd.Execute
225+
|> ignore

tests/SqlClient.Tests/extensions.sql

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ GO
5858
IF OBJECT_ID('dbo.TestPhoto') IS NOT NULL
5959
DROP PROCEDURE dbo.TestPhoto;
6060
GO
61+
IF OBJECT_ID('dbo.FixedLengthBinaryTVPTestProc') IS NOT NULL
62+
DROP PROCEDURE [dbo].[FixedLengthBinaryTVPTestProc]
63+
GO
6164
IF OBJECT_ID('Sales.GetUKSalesOrders') IS NOT NULL
6265
DROP FUNCTION Sales.GetUKSalesOrders;
6366
GO
@@ -72,6 +75,10 @@ IF OBJECT_ID(N'Sales.UnitedKingdomOrders') IS NOT NULL
7275
DROP TABLE Sales.UnitedKingdomOrders
7376
GO
7477

78+
IF OBJECT_ID(N'[dbo].[FixedLengthBinaryTVPTestTable]') IS NOT NULL
79+
DROP TABLE [dbo].[FixedLengthBinaryTVPTestTable]
80+
GO
81+
7582
--TRIGGERS
7683
IF OBJECT_ID(N'Production.tr_Location_Slow') IS NOT NULL
7784
DROP TRIGGER Production.tr_Location_Slow
@@ -116,6 +123,10 @@ IF TYPE_ID(N'Sales.<USD>') IS NOT NULL
116123
DROP TYPE Sales.[<USD>]
117124
GO
118125

126+
IF TYPE_ID(N'dbo.FixedLengthBinaryTVPTest') IS NOT NULL
127+
DROP TYPE [dbo].[FixedLengthBinaryTVPTest]
128+
GO
129+
119130

120131
CREATE TYPE dbo.MyTableType AS TABLE (myId int not null, myName nvarchar(30) null)
121132
GO
@@ -138,6 +149,11 @@ GO
138149
CREATE TYPE Sales.[<USD>] FROM MONEY NOT NULL
139150
GO
140151

152+
CREATE TYPE [dbo].[FixedLengthBinaryTVPTest] AS TABLE (
153+
[BinaryCol] BINARY(50)
154+
)
155+
GO
156+
141157
--TABLES
142158

143159
CREATE TABLE dbo.TableHavingColumnNamesWithSpaces (
@@ -150,7 +166,13 @@ CREATE TABLE Sales.UnitedKingdomOrders(
150166
[SalesOrderID] [int] NOT NULL,
151167
[TotalDue] [Sales].[<GBP>] NOT NULL
152168
)
153-
GO
169+
GO
170+
171+
CREATE TABLE [dbo].[FixedLengthBinaryTVPTestTable] (
172+
ID INT IDENTITY (1, 1) NOT NULL,
173+
FixedLengthBinaryTVPTest BINARY(50) NOT NULL
174+
)
175+
GO
154176

155177
INSERT INTO Sales.UnitedKingdomOrders
156178
SELECT SalesOrderID, TotalDue
@@ -237,6 +259,16 @@ WHERE
237259
SpatialLocation.STDistance(@SpatialLocation) = 0;
238260
GO
239261

262+
CREATE PROCEDURE [dbo].[FixedLengthBinaryTVPTestProc]
263+
@fixedLengthBinaryTests [dbo].[FixedLengthBinaryTVPTest] READONLY
264+
AS
265+
BEGIN
266+
INSERT INTO [dbo].[FixedLengthBinaryTVPTestTable]
267+
SELECT [BinaryCol]
268+
FROM @fixedLengthBinaryTests
269+
END
270+
GO
271+
240272

241273
CREATE FUNCTION dbo.ufnGetStock2(@ProductID [int] = NULL)
242274
RETURNS [int]

0 commit comments

Comments
 (0)