Skip to content

Commit b2a6bd2

Browse files
author
Chai Natan
committed
Issue 420: restored TVP column ordering to, expected, column_id
1 parent 66c3613 commit b2a6bd2

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/SqlClient.DesignTime/SqlClientExtensions.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,11 @@ from
525525
select
526526
c.name, c.system_type_id, c.user_type_id, c.is_nullable, c.max_length, c.is_identity, c.is_computed, tt.user_type_id table_type_user_type_id, c.[precision], c.scale
527527
from sys.table_types as tt
528-
inner join sys.columns as c on tt.type_table_object_id = c.object_id
529-
order by
530-
tt.user_type_id
531-
, c.user_type_id
532-
, c.column_id
528+
inner join sys.columns as c on tt.type_table_object_id = c.object_id
529+
order by
530+
c.column_id
531+
, tt.user_type_id
532+
, c.user_type_id
533533
"""
534534
, this)
535535
use reader = cmd.ExecuteReader()

tests/SqlClient.Tests/TVPTests.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,20 @@ let ``Using Fixed Length Binary TVP``() =
222222
]
223223
|> Seq.map (fun d -> FixedLengthBinaryTVP.FixedLengthBinaryTVPTest (Some d))
224224
|> cmd.Execute
225+
|> ignore
226+
227+
228+
type TestTVPColumnOrder = SqlCommandProvider<"EXEC [dbo].[TestTVPColumnOrder] @tvp", ConnectionStrings.AdventureWorksLiteral>
229+
[<Fact>]
230+
let ``User Defined Table Types should list columns orderd by Column Id (i.e. the order in which they appear in the declared type)`` () =
231+
use cmd = new TestTVPColumnOrder(ConnectionStrings.AdventureWorksLiteral)
232+
233+
[
234+
(1, "some string", true)
235+
(2, "some other string", false)
236+
(3, "yet another string", true)
237+
]
238+
|> Seq.map (fun (i, s, b) -> TestTVPColumnOrder.TVPColumnOrder(i, s, b))
239+
|> Seq.toList
240+
|> cmd.Execute
225241
|> ignore

tests/SqlClient.Tests/extensions.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ GO
6161
IF OBJECT_ID('dbo.FixedLengthBinaryTVPTestProc') IS NOT NULL
6262
DROP PROCEDURE [dbo].[FixedLengthBinaryTVPTestProc]
6363
GO
64+
IF OBJECT_ID('dbo.TestTVPColumnOrder') IS NOT NULL
65+
DROP PROCEDURE [dbo].[TestTVPColumnOrder]
66+
GO
6467
IF OBJECT_ID('Sales.GetUKSalesOrders') IS NOT NULL
6568
DROP FUNCTION Sales.GetUKSalesOrders;
6669
GO
@@ -127,6 +130,10 @@ IF TYPE_ID(N'dbo.FixedLengthBinaryTVPTest') IS NOT NULL
127130
DROP TYPE [dbo].[FixedLengthBinaryTVPTest]
128131
GO
129132

133+
IF TYPE_ID(N'dbo.TVPColumnOrder') IS NOT NULL
134+
DROP TYPE [dbo].[TVPColumnOrder]
135+
GO
136+
130137

131138
CREATE TYPE dbo.MyTableType AS TABLE (myId int not null, myName nvarchar(30) null)
132139
GO
@@ -154,6 +161,13 @@ CREATE TYPE [dbo].[FixedLengthBinaryTVPTest] AS TABLE (
154161
)
155162
GO
156163

164+
CREATE TYPE [dbo].[TVPColumnOrder] AS TABLE(
165+
[Param1] INT NOT NULL,
166+
[Param2] NVARCHAR(100) NOT NULL,
167+
[Param3] BIT NOT NULL
168+
)
169+
GO
170+
157171
--TABLES
158172

159173
CREATE TABLE dbo.TableHavingColumnNamesWithSpaces (
@@ -269,6 +283,14 @@ BEGIN
269283
END
270284
GO
271285

286+
CREATE PROCEDURE [dbo].[TestTVPColumnOrder](
287+
@tvpColumnOrder [dbo].[TVPColumnOrder] READONLY
288+
)
289+
AS
290+
SELECT *
291+
FROM @tvpColumnOrder
292+
GO
293+
272294

273295
CREATE FUNCTION dbo.ufnGetStock2(@ProductID [int] = NULL)
274296
RETURNS [int]

0 commit comments

Comments
 (0)