Handling datetime types - #1636
Merged
Merged
Conversation
… supportTimeSpan
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
seantleonard
approved these changes
Dec 5, 2023
aaronburtle
reviewed
Dec 6, 2023
aaronburtle
reviewed
Dec 6, 2023
aaronburtle
reviewed
Dec 6, 2023
aaronburtle
reviewed
Dec 6, 2023
aaronburtle
approved these changes
Dec 6, 2023
aaronburtle
left a comment
Contributor
There was a problem hiding this comment.
Looks good just a few nits before merging if possible.
abhishekkumams
approved these changes
Dec 6, 2023
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Contributor
|
@microsoft-github-policy-service rerun |
Contributor
Author
|
Ignoring the failing test for DwSql FindByDateTimePKTest(). @rohkhann will take a look. Not a blocker. |
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.
Why make this change?
Currently, we are incorrectly handling the datetime datatypes. A snippet from
BaseSqlQueryStructureclass:As evident from the highlighted portion, even for
DateTime.NET type, we are parsing it withDateTimeOffsetwhich is wrong. Just for an example, if you execute a GET request on thestocks_pricetable which has(categoryid,pieceid,instant)as PK, you would not get any result back even when the record exists for that PK in the table. Why? Because even though instant is adatetimecolumn, it gets parsed asdatetimeoffsetcolumn. This is shown in the next 2 images.Also, the existing tests (like the ones fixed in
MsSqlGraphQLPaginationTestsandGraphQLSupportedTypesTestsBase) were wrongly written, in which values in the range ofdatetime2were supplied fordatetimecolumn.What is this change?
Correctly return value using
DateTimefield of theDateTimeOffsetparsed value inBaseSqlQueryStructureclass,Populate the DbType of the datetime parameters when they are sent to the database so that the database knows the exact type of the parameter. Eg. by default, if you send a
datetime2param without a DbType, it is assumed to be adatetimeand an exception is thrown incorrectly by the database. This is done using the mapTypeHelper._timeSqlDbTypeToDbType.It should be noted 4 sql server types -
date,smalldatetime,datetime,datetime2map to the same .NET system typeSystem.DateTime. The existingTypeHelper._systemTypeToDbTypeMapwould not be of any use to us because it has mapping from system type to DbType and all the above 3 sql server types have the same system type. So, we need to rely on the actual mapping from sql server type to DbType which is:datetime -> DbType.DateTime, smalldatetime -> DbType.DateTime, datetime2 -> DbType.DateTime2date -> DbType.DateFix the existing tests.
How was this tested?
datetimecolumn as a PK column toFindApiTestBase.GraphQLSupportedTypesTestsBase.QueryTypeColumnFilterAndOrderByDateTimeandGraphQLSupportedTypesTestsBase.InsertIntoTypeColumnfor datetime types -datetime2,smalldatetime,date.Sample Request(s)