Skip to content

Commit 31877ce

Browse files
properly carry the precision and scale from table type columns
1 parent 31b3920 commit 31877ce

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/SqlClient.DesignTime/SqlClientExtensions.fs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ type internal SqlTypeEntry = {
192192
scale : int16
193193
}
194194
type internal TableVariableEntry = {
195-
name : string
196-
system_type_id : byte
197-
user_type_id : int
198-
is_nullable : bool
199-
max_length : int16
200-
is_identity : bool
201-
is_computed : bool
202-
table_type_user_type_id: int
195+
name : string
196+
system_type_id : byte
197+
user_type_id : int
198+
is_nullable : bool
199+
max_length : int16
200+
is_identity : bool
201+
is_computed : bool
202+
table_type_user_type_id : int
203+
precision : byte
204+
scale : byte
203205
}
204206

205207
type SqlConnection with
@@ -554,13 +556,15 @@ order by
554556
table_type_user_type_id
555557
, {
556558
table_type_user_type_id = table_type_user_type_id
557-
name = string reader.["name"]
559+
name = string reader.["name"]
558560
system_type_id = unbox<byte> reader.["system_type_id"]
559561
is_nullable = unbox reader.["is_nullable"]
560562
max_length = unbox<int16> reader.["max_length"]
561563
is_identity = unbox reader.["is_identity"]
562564
is_computed = unbox reader.["is_computed"]
563565
user_type_id = unbox<int> reader.["user_type_id"]
566+
precision = unbox<byte> reader.["precision"]
567+
scale = unbox<byte> reader.["scale"]
564568
}
565569
|]
566570
|> Array.groupBy fst
@@ -588,7 +592,11 @@ order by
588592
let getProvidedTypeForSqlTypeEntry (x:SqlTypeEntry) = getProvidedType x.name x.is_user_defined x.is_table_type x.system_type_id x.user_type_id
589593

590594
let rec makeColumn column =
591-
let sqlTypeEntry = sqlEngineTypes.[column.system_type_id, column.user_type_id]
595+
let sqlTypeEntry =
596+
{ sqlEngineTypes.[column.system_type_id, column.user_type_id] with
597+
// important: retrieve the precision / scale from the table variable column entry itself
598+
precision = int16 column.precision
599+
scale = int16 column.scale }
592600
{ Column.Name = column.name
593601
TypeInfo = Option.get (makeTypeInfo sqlTypeEntry)
594602
Nullable = column.is_nullable
@@ -649,6 +657,9 @@ order by
649657
columns
650658
|> Array.map (fun column ->
651659
let sqlTypeInfo, typeInfo = typeInfosForTableTypes.[user_type_id]
660+
// important: retrieve the precision / scale from the table variable column entry itself
661+
let precision = int16 column.precision
662+
let scale = int16 column.scale
652663
{
653664
Column.Name = column.name
654665
TypeInfo = typeInfo
@@ -659,8 +670,8 @@ order by
659670
PartOfUniqueKey = false
660671
DefaultConstraint = null
661672
Description = null
662-
Precision = sqlTypeInfo.precision
663-
Scale = sqlTypeInfo.scale
673+
Precision = precision
674+
Scale = scale
664675
})
665676
else
666677
Array.empty

0 commit comments

Comments
 (0)