Skip to content

Commit

Permalink
Merge pull request #325 from panesofglass/bugfix/fixed-length-tvp
Browse files Browse the repository at this point in the history
Fix exception when using TVP parameter with fixed length string
  • Loading branch information
vasily-kirichenko authored Jan 17, 2019
2 parents dabf2cb + 0a6c64b commit 2ef6c06
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/SqlClient.DesignTime/SqlClientExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ let internal providerTypes =
"time", (SqlDbType.Time, "System.TimeSpan", true)

// character strings
"char", (SqlDbType.Char, "System.String", true)
"char", (SqlDbType.Char, "System.String", false)
"text", (SqlDbType.Text, "System.String", false)
"varchar", (SqlDbType.VarChar, "System.String", false)

// unicode character strings
"nchar", (SqlDbType.NChar, "System.String", true)
"nchar", (SqlDbType.NChar, "System.String", false)
"ntext", (SqlDbType.NText, "System.String", false)
"nvarchar", (SqlDbType.NVarChar, "System.String", false)
"sysname", (SqlDbType.NVarChar, "System.String", false)
Expand Down
20 changes: 20 additions & 0 deletions tests/SqlClient.Tests/TVPTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,23 @@ let UsingMappedTVPInQuery() =
|> Seq.toList

Assert.Equal<_ list>(expected, actual)

type MappedTVPFixed =
SqlCommandProvider<"
SELECT myId, myName from @input
", ConnectionStrings.AdventureWorksLiteral, TableVarMapping = "@input=dbo.MyTableTypeFixed">
[<Fact>]
let UsingMappedTVPFixedInQuery() =
printfn "%s" ConnectionStrings.AdventureWorksLiteral
use cmd = new MappedTVPFixed(ConnectionStrings.AdventureWorksLiteral)
let expected = [
1, Some "monkey"
2, Some "donkey"
]

let actual =
cmd.Execute(input = [ for id, name in expected -> MappedTVPFixed.MyTableTypeFixed(id, name) ])
|> Seq.map(fun x -> x.myId, x.myName |> Option.map (fun s -> s.Trim()))
|> Seq.toList

Assert.Equal<_ list>(expected, actual)
6 changes: 6 additions & 0 deletions tests/SqlClient.Tests/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ GO
IF TYPE_ID(N'Person.MyTableType') IS NOT NULL
DROP TYPE Person.MyTableType
GO
IF TYPE_ID(N'dbo.MyTableTypeFixed') IS NOT NULL
DROP TYPE dbo.MyTableTypeFixed
GO
IF TYPE_ID(N'dbo.u_int64') IS NOT NULL
DROP TYPE dbo.u_int64
GO
Expand All @@ -112,6 +115,9 @@ GO
CREATE TYPE Person.MyTableType AS TABLE (myId int not null, myName nvarchar(30) null)
GO

CREATE TYPE dbo.MyTableTypeFixed AS TABLE (myId int not null, myName nchar(30) null)
GO

CREATE TYPE dbo.SingleElementType AS TABLE (myId int not null)
GO

Expand Down

0 comments on commit 2ef6c06

Please sign in to comment.