Skip to content

Commit 2ef6c06

Browse files
Merge pull request #325 from panesofglass/bugfix/fixed-length-tvp
Fix exception when using TVP parameter with fixed length string
2 parents dabf2cb + 0a6c64b commit 2ef6c06

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/SqlClient.DesignTime/SqlClientExtensions.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ let internal providerTypes =
106106
"time", (SqlDbType.Time, "System.TimeSpan", true)
107107

108108
// character strings
109-
"char", (SqlDbType.Char, "System.String", true)
109+
"char", (SqlDbType.Char, "System.String", false)
110110
"text", (SqlDbType.Text, "System.String", false)
111111
"varchar", (SqlDbType.VarChar, "System.String", false)
112112

113113
// unicode character strings
114-
"nchar", (SqlDbType.NChar, "System.String", true)
114+
"nchar", (SqlDbType.NChar, "System.String", false)
115115
"ntext", (SqlDbType.NText, "System.String", false)
116116
"nvarchar", (SqlDbType.NVarChar, "System.String", false)
117117
"sysname", (SqlDbType.NVarChar, "System.String", false)

tests/SqlClient.Tests/TVPTests.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,23 @@ let UsingMappedTVPInQuery() =
165165
|> Seq.toList
166166

167167
Assert.Equal<_ list>(expected, actual)
168+
169+
type MappedTVPFixed =
170+
SqlCommandProvider<"
171+
SELECT myId, myName from @input
172+
", ConnectionStrings.AdventureWorksLiteral, TableVarMapping = "@input=dbo.MyTableTypeFixed">
173+
[<Fact>]
174+
let UsingMappedTVPFixedInQuery() =
175+
printfn "%s" ConnectionStrings.AdventureWorksLiteral
176+
use cmd = new MappedTVPFixed(ConnectionStrings.AdventureWorksLiteral)
177+
let expected = [
178+
1, Some "monkey"
179+
2, Some "donkey"
180+
]
181+
182+
let actual =
183+
cmd.Execute(input = [ for id, name in expected -> MappedTVPFixed.MyTableTypeFixed(id, name) ])
184+
|> Seq.map(fun x -> x.myId, x.myName |> Option.map (fun s -> s.Trim()))
185+
|> Seq.toList
186+
187+
Assert.Equal<_ list>(expected, actual)

tests/SqlClient.Tests/extensions.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ GO
9090
IF TYPE_ID(N'Person.MyTableType') IS NOT NULL
9191
DROP TYPE Person.MyTableType
9292
GO
93+
IF TYPE_ID(N'dbo.MyTableTypeFixed') IS NOT NULL
94+
DROP TYPE dbo.MyTableTypeFixed
95+
GO
9396
IF TYPE_ID(N'dbo.u_int64') IS NOT NULL
9497
DROP TYPE dbo.u_int64
9598
GO
@@ -112,6 +115,9 @@ GO
112115
CREATE TYPE Person.MyTableType AS TABLE (myId int not null, myName nvarchar(30) null)
113116
GO
114117

118+
CREATE TYPE dbo.MyTableTypeFixed AS TABLE (myId int not null, myName nchar(30) null)
119+
GO
120+
115121
CREATE TYPE dbo.SingleElementType AS TABLE (myId int not null)
116122
GO
117123

0 commit comments

Comments
 (0)