Fix | Write DateOnly instances to sql_variant columns of table-valued parameters as date values#4439
Open
edwardneal wants to merge 1 commit into
Open
Fix | Write DateOnly instances to sql_variant columns of table-valued parameters as date values#4439edwardneal wants to merge 1 commit into
edwardneal wants to merge 1 commit into
Conversation
Instances of DateOnly stored within a SqlDataRecord field of type Variant will now be sent as dates, not datetimes. By extension: sending DateOnly instances with values outside the acceptable range for a datetime will no longer throw overflow exceptions.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This builds on #4294, and handles the only other issue I saw while investigating #3934.
If a user-defined table type exists with a column of type
sql_variant, client applications can insert aDateOnlyinstance into this. It's supposed to be sent with a type ofdate, but is actually sent as adatetime.Besides a point around correctness, it presents an issue when sending
DateOnlyinstances which are valid values fordatebut not fordatetime: these values overflow.This PR fixes the issue, transporting all
DateOnlyinstances with thedatetype on modern .NET. On .NET Framework, there's noDateOnlytype - and thus there's no way for the client to encapsulate adatevalue within asql_variantcolumn.@ErikEJ, this covers the only other way to write
DateOnlyinstances to SQL Server and should hopefully completely close #3934. SqlClient will continue to readDateTimeinstances by default, but this is needed for backwards compatibility purposes.NB: similar issues also exist with
TimeOnlyinstances. TdsParser assumes that onlyTimeSpaninstances will be written as times, so there are failures to cast in a few different places.Issues
Builds on #4294. Possible resolution to #3934.
Testing
#4294 added the relevant tests, with an exemption carved out for this use case. I've removed the exemption and verified that it covers the test case.