Skip to content

Commit 0e03843

Browse files
support explicitly set scale of zero for datetime2, datetimeoffset and time
1 parent 78e8ebc commit 0e03843

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlParameter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ internal byte ScaleInternal
577577
}
578578
}
579579

580-
private bool ShouldSerializeScale() => _scale != 0; // V1.0 compat, ignore _hasScale
580+
private bool ShouldSerializeScale() => _scale != 0 || (GetMetaTypeOnly().IsVarTime && HasFlag(SqlParameterFlags.HasScale));
581581

582582
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlParameter.xml' path='docs/members[@name="SqlParameter"]/SqlDbType/*' />
583583
[
@@ -1445,8 +1445,7 @@ internal byte GetActualScale()
14451445
return ScaleInternal;
14461446
}
14471447

1448-
// issue: how could a user specify 0 as the actual scale?
1449-
if (GetMetaTypeOnly().IsVarTime)
1448+
if (GetMetaTypeOnly().IsVarTime && !HasFlag(SqlParameterFlags.HasScale))
14501449
{
14511450
return TdsEnums.DEFAULT_VARTIME_SCALE;
14521451
}

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlParameter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ internal byte ScaleInternal
560560
}
561561
}
562562

563-
private bool ShouldSerializeScale() => _scale != 0; // V1.0 compat, ignore _hasScale
563+
private bool ShouldSerializeScale() => _scale != 0 || (GetMetaTypeOnly().IsVarTime && HasFlag(SqlParameterFlags.HasScale));
564564

565565
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlParameter.xml' path='docs/members[@name="SqlParameter"]/SqlDbType/*' />
566566
[
@@ -1437,8 +1437,7 @@ internal byte GetActualScale()
14371437
return ScaleInternal;
14381438
}
14391439

1440-
// issue: how could a user specify 0 as the actual scale?
1441-
if (GetMetaTypeOnly().IsVarTime)
1440+
if (GetMetaTypeOnly().IsVarTime && !HasFlag(SqlParameterFlags.HasScale))
14421441
{
14431442
return TdsEnums.DEFAULT_VARTIME_SCALE;
14441443
}

0 commit comments

Comments
 (0)