Skip to content

Commit

Permalink
Merge pull request #418 from suou-ryuu/binaryTVPFix
Browse files Browse the repository at this point in the history
Fix for fixed length binary table valued parameters
  • Loading branch information
smoothdeveloper authored Apr 18, 2022
2 parents ab772d4 + 06d6fba commit 66c3613
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/SqlClient.DesignTime/SqlClientExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ let internal providerTypes =
"sysname", (SqlDbType.NVarChar, "System.String", false)

// binary
"binary", (SqlDbType.Binary, "System.Byte[]", true)
"binary", (SqlDbType.Binary, "System.Byte[]", false)
"image", (SqlDbType.Image, "System.Byte[]", false)
"varbinary", (SqlDbType.VarBinary, "System.Byte[]", false)

Expand Down
17 changes: 16 additions & 1 deletion tests/SqlClient.Tests/TVPTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,19 @@ let ``issue #393 troubleshoot if datetimeoffset raises an exception`` () =
let tvp = [AdventureWorks.dbo.``User-Defined Table Types``.datetimeoffset_test_tvp(value)]
use cmd = new AdventureWorks.dbo.datetimeoffset_test(ConnectionStrings.AdventureWorksLiteral)
let resultvalue = cmd.Execute(tvp) |> Seq.head
Assert.Equal(value, resultvalue)
Assert.Equal(value, resultvalue)

type FixedLengthBinaryTVP = SqlCommandProvider<"EXEC [dbo].[FixedLengthBinaryTVPTestProc] @fixedLengthBinaryTests", ConnectionStrings.AdventureWorksLiteral>
[<Fact>]
let ``Using Fixed Length Binary TVP``() =
printfn "%s" ConnectionStrings.AdventureWorksLiteral
use cmd = new FixedLengthBinaryTVP(ConnectionStrings.AdventureWorksLiteral)

[
[|1uy;2uy;3uy|]
[|4uy;5uy;6uy|]
[|7uy;8uy;9uy|]
]
|> Seq.map (fun d -> FixedLengthBinaryTVP.FixedLengthBinaryTVPTest (Some d))
|> cmd.Execute
|> ignore
34 changes: 33 additions & 1 deletion tests/SqlClient.Tests/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ GO
IF OBJECT_ID('dbo.TestPhoto') IS NOT NULL
DROP PROCEDURE dbo.TestPhoto;
GO
IF OBJECT_ID('dbo.FixedLengthBinaryTVPTestProc') IS NOT NULL
DROP PROCEDURE [dbo].[FixedLengthBinaryTVPTestProc]
GO
IF OBJECT_ID('Sales.GetUKSalesOrders') IS NOT NULL
DROP FUNCTION Sales.GetUKSalesOrders;
GO
Expand All @@ -72,6 +75,10 @@ IF OBJECT_ID(N'Sales.UnitedKingdomOrders') IS NOT NULL
DROP TABLE Sales.UnitedKingdomOrders
GO

IF OBJECT_ID(N'[dbo].[FixedLengthBinaryTVPTestTable]') IS NOT NULL
DROP TABLE [dbo].[FixedLengthBinaryTVPTestTable]
GO

--TRIGGERS
IF OBJECT_ID(N'Production.tr_Location_Slow') IS NOT NULL
DROP TRIGGER Production.tr_Location_Slow
Expand Down Expand Up @@ -116,6 +123,10 @@ IF TYPE_ID(N'Sales.<USD>') IS NOT NULL
DROP TYPE Sales.[<USD>]
GO

IF TYPE_ID(N'dbo.FixedLengthBinaryTVPTest') IS NOT NULL
DROP TYPE [dbo].[FixedLengthBinaryTVPTest]
GO


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

CREATE TYPE [dbo].[FixedLengthBinaryTVPTest] AS TABLE (
[BinaryCol] BINARY(50)
)
GO

--TABLES

CREATE TABLE dbo.TableHavingColumnNamesWithSpaces (
Expand All @@ -150,7 +166,13 @@ CREATE TABLE Sales.UnitedKingdomOrders(
[SalesOrderID] [int] NOT NULL,
[TotalDue] [Sales].[<GBP>] NOT NULL
)
GO
GO

CREATE TABLE [dbo].[FixedLengthBinaryTVPTestTable] (
ID INT IDENTITY (1, 1) NOT NULL,
FixedLengthBinaryTVPTest BINARY(50) NOT NULL
)
GO

INSERT INTO Sales.UnitedKingdomOrders
SELECT SalesOrderID, TotalDue
Expand Down Expand Up @@ -237,6 +259,16 @@ WHERE
SpatialLocation.STDistance(@SpatialLocation) = 0;
GO

CREATE PROCEDURE [dbo].[FixedLengthBinaryTVPTestProc]
@fixedLengthBinaryTests [dbo].[FixedLengthBinaryTVPTest] READONLY
AS
BEGIN
INSERT INTO [dbo].[FixedLengthBinaryTVPTestTable]
SELECT [BinaryCol]
FROM @fixedLengthBinaryTests
END
GO


CREATE FUNCTION dbo.ufnGetStock2(@ProductID [int] = NULL)
RETURNS [int]
Expand Down

0 comments on commit 66c3613

Please sign in to comment.