Skip to content

Cleanup | Merge SqlDataRecord and remove context connection remnants #3454

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

edwardneal
Copy link
Contributor

Description

This picks up where #3438 left off. With SmiEventSink_Default removed, almost all of the code in SqlDataRecord.netfx.cs and SqlDataRecord.netcore.cs is identical and can be removed. We do so.

The SmiRecordBuffer class is also removed, since this isn't doing anything meaningful. I'm not pleased with the overall type hierarchy here, but I want to think through the consequences of changing them in the wider context of ValueUtilsSmi.

With that work done, we just remove the now-unused resource strings and exception methods from SqlUtil, AdapterUtil and the string resources. There are other unused strings and exception methods here, for anyone interested in picking up a bulky commit.

Closes #2838.

Issues

Follows #3438.
Resolves #2838.
Contributes to #1261.

Testing

Local unit tests for SqlDataRecord pass.

@edwardneal edwardneal requested a review from a team as a code owner June 27, 2025 17:19
@benrr101
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

benrr101
benrr101 previously approved these changes Jun 30, 2025
Copy link
Contributor

@benrr101 benrr101 left a comment

Choose a reason for hiding this comment

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

We do so 🫡

(one small request, but overall it's great)

SqlMetaData md = GetSqlMetaData(ordinal);

#if NETFRAMEWORK
if (md.SqlDbType == SqlDbType.Udt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this check only applies to netframework and will return, let's avoid the braces for netcore

#if NETFRAMEWORK
if (md.SqlDbType == SqlDbType.Udt)
{
    return md.Type;
}
#endif

return MetaType.GetMetaTypeFromSqlDbType(md.SqlDbType, false).ClassType;

Copy link
Contributor

Choose a reason for hiding this comment

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

Also tiny request, can we get an argument label for the false here? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - done!

@apoorvdeshmukh
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

codecov bot commented Jul 2, 2025

Codecov Report

Attention: Patch coverage is 77.96610% with 13 lines in your changes missing coverage. Please review.

Project coverage is 58.82%. Comparing base (fc950e8) to head (e136b03).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...c/Microsoft/Data/SqlClient/Server/SqlDataRecord.cs 83.01% 9 Missing ⚠️
...rosoft/Data/SqlClient/Server/MemoryRecordBuffer.cs 0.00% 2 Missing ⚠️
...c/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs 33.33% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (fc950e8) and HEAD (e136b03). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (fc950e8) HEAD (e136b03)
addons 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3454      +/-   ##
==========================================
- Coverage   64.55%   58.82%   -5.73%     
==========================================
  Files         281      271      -10     
  Lines       62519    61984     -535     
==========================================
- Hits        40358    36464    -3894     
- Misses      22161    25520    +3359     
Flag Coverage Δ
addons ?
netcore 63.32% <78.57%> (-3.62%) ⬇️
netfx 60.48% <77.58%> (-7.47%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

paulmedynski
paulmedynski previously approved these changes Jul 2, 2025
}

// Allow values array longer than FieldCount, just ignore the extra cells.
int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can do some early exit optimization here if (copyLength == 0) return 0;

}

// Now move the data (it'll only throw if someone plays with the values array between
// the validation loop and here, or if an invalid UDT was sent).
Copy link
Contributor

Choose a reason for hiding this comment

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

We can make a shallow copy of the portion of array to be used

object[] stableValues = new object[copyLength];
Array.Copy(values, stableValues, copyLength);

then use stableValues[i] in both loops, guaranteeing stability of inputs between validation and writing phase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing actually tampers with the values array so I don't think we need to make a defensive copy. I'll adjust the comment accordingly.

Exit early if we have no fields to set.
Clarify comment.
@paulmedynski
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET Framework SQLCLR support
5 participants