Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialise scale for vartime SqlParameter types that have been explicitly set by the user to zero #2411

Merged
merged 17 commits into from
Oct 22, 2024

Conversation

EamonHetherton
Copy link
Contributor

@EamonHetherton EamonHetherton commented Mar 17, 2024

The pull requests addresses #1380 by introducing and opt-in context switch "Switch.Microsoft.Data.SqlClient.LegacyVarTimeZeroScaleBehaviour" to change the existing behaviour and actually emit a zero scale parameter when the users has set the scale-0

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 18, 2024

It wasn't stuck in limbo it was decided against, see #1380 (comment)

The only way you're going to get the change implemented is with an appcontext opt-in, if you include that then it might be includable. You'll need to add tests. You'll need to change the documentation.

@EamonHetherton
Copy link
Contributor Author

It wasn't stuck in limbo it was decided against, see #1380 (comment)

The only way you're going to get the change implemented is with an appcontext opt-in, if you include that then it might be includable. You'll need to add tests. You'll need to change the documentation.

Apologies, I'd assumed that this was blocked based on this #1381 (comment)

I'm really out of options for how to mitigate the performance impact of this short of moving off MSSQL or forking this library. I really don't want to do either :(

I'll chip away and attempt to make this change based on an app context switch, try to get some testing around it and update the docs and then and see if I can get some traction.

Also, it looks like the failed checks are unrelated to this pull request as best that I can tell, I'm really not sure how to get the checks to pass.

@EamonHetherton
Copy link
Contributor Author

EamonHetherton commented Mar 18, 2024

It looks like the explicit calling out of this behaviour in the docs for the previous library System.Data.SqlClient as referred to here: #1380 (comment) are no longer in the docs for Microsoft.Data.SqlClient. Therefore I don't think there are any doc changes to make as part of this pull request. Still working on tests :)

@EamonHetherton
Copy link
Contributor Author

@Wraith2 pull request updated with context switch and tests. I don't believe there are documentation updates required for the Scale parameter itself as noted above, but the existing context switches do appear in documentation here: https://learn.microsoft.com/en-us/sql/connect/ado-net/appcontext-switches?view=sql-server-ver16 but I'm not sure where that lives. Any guidance would be appreciated.

@EamonHetherton
Copy link
Contributor Author

@Wraith2 Incidentally I noticed that the UseMinimumLoginTimeout context switch changed default behaviour in the last refactor of LocalAppContextSwitches in November 2023 and now returns a default value of "false" though the triple slash summary still says it should have a default of "true". The documentation @ https://learn.microsoft.com/en-us/sql/connect/ado-net/appcontext-switches?view=sql-server-ver16 does not give any guidance on default value but it looks to me like this default value change was unintended, but I think you would be better placed to determine that.

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 18, 2024

Can you open a new issue with the details on that default so it can be reviewed please.

@EamonHetherton
Copy link
Contributor Author

Can you open a new issue with the details on that default so it can be reviewed please.

issue #2415 with fix in #2416

@EamonHetherton EamonHetherton changed the title serialise scale for vartime has been explicitly set by the user to zero Serialise scale for vartime type that have been explicitly set by the user to zero Mar 19, 2024
@EamonHetherton EamonHetherton changed the title Serialise scale for vartime type that have been explicitly set by the user to zero Serialise scale for vartime SqlParameter types that have been explicitly set by the user to zero Mar 19, 2024
@EamonHetherton
Copy link
Contributor Author

Is there anything more I can do to move this along? failing that is there anywhere for me to get access to the pull request nuget package that was built "Microsoft.Data.SqlClient.6.0.0-pull.107808"?

@Wraith2
Copy link
Contributor

Wraith2 commented Mar 31, 2024

No. You just wait for the team to get to it.

Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.70%. Comparing base (c33bde2) to head (ab11ffc).

❗ Current head ab11ffc differs from pull request most recent head 546c10a. Consider uploading reports for the commit 546c10a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2411      +/-   ##
==========================================
+ Coverage   72.66%   72.70%   +0.04%     
==========================================
  Files         313      313              
  Lines       61737    61747      +10     
==========================================
+ Hits        44861    44895      +34     
+ Misses      16876    16852      -24     
Flag Coverage Δ
addons 92.88% <ø> (ø)
netcore 76.99% <100.00%> (+<0.01%) ⬆️
netfx 70.42% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EamonHetherton
Copy link
Contributor Author

EamonHetherton commented Oct 7, 2024

6 months later this is still waiting to be reviewed/approved....

@cheenamalhotra cheenamalhotra added this to the 6.0-preview2 milestone Oct 8, 2024
Copy link
Member

@cheenamalhotra cheenamalhotra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update PR description to include the behavior change and introduction of new App Context switch for documentation purposes.

…arameter.cs

Co-authored-by: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com>
@EamonHetherton
Copy link
Contributor Author

suggested documentation for new AppContext switch to update this

Allow explicit zero scale for VarTime parameter types

[!INCLUDE appliesto-netfx-netcore-netst-md]

(Available starting with version 6.0.0)

When using parameters with VarTime datatypes (DateTime2, DateTimeOffset, Time), the library will only emit the scale if it is non-zero regardless of the user explicitly setting the Scale=0. See https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlparameter.scale?view=netframework-4.8.1#remarks

In order to emit a zero scale, you can now set the following AppContext switch to false:

AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.LegacyVarTimeZeroScaleBehaviour", false);

and then explicitly set the parameter scale to zero

var parameter = new SqlParameter
{
    ParameterName = "@p1",
    DbType = DbType.DateTime2,
    Scale = 0
};

which will emit the equivalent SQL parameter as

DECLARE @p1 datetime2(0)

@cheenamalhotra cheenamalhotra added the 🆕 Public API Issues/PRs that introduce new APIs to the driver. label Oct 22, 2024
@cheenamalhotra cheenamalhotra merged commit b556bb3 into dotnet:main Oct 22, 2024
128 of 130 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 Public API Issues/PRs that introduce new APIs to the driver.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants