Fix | Build DataTypes table in code, add json data type#3858
Conversation
SqlClient cannot connect to SQL Server 2000 instances, so the minimum server version is 9.0. * Remove data type entries with a maximum version below this. * Remove the minimum version constraint where this constraint will always be true.
This enables the JSON tests to run against SQL Server 2025. Also correct a comment in LoadDataTypesDataTables.
There was a problem hiding this comment.
Pull request overview
This PR refactors the DataTypes schema metadata population from an XML-based approach to a code-based approach, and adds support for the json data type. It introduces a new IsJsonSupported property to consolidate SQL Server version detection for JSON features and updates all JSON-related tests to use this unified check.
Key Changes
- Replaced XML deserialization for the DataTypes metadata table with programmatic population using MetaType introspection
- Added the
jsondata type to the schema with appropriate metadata (minimum version 17.00.000.0, long type, not best match) - Introduced
DataTestUtility.IsJsonSupportedproperty to centralize JSON support detection across tests
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
JsonTest.cs |
Updated conditional test attributes to use IsJsonSupported instead of Azure-specific checks |
JsonStreamTest.cs |
Updated conditional test attributes to use IsJsonSupported |
JsonBulkCopyTest.cs |
Updated conditional test attributes to use IsJsonSupported |
ConnectionSchemaTest.cs |
Added new test to verify DataTypes schema and validate json type presence based on server support |
DataTestUtility.cs |
Added IsJsonSupported property and IsTypePresent helper method for SQL Server feature detection |
SqlMetaData.xml |
Removed DataTypesTable XML section (695 lines) |
SqlMetaDataFactory.cs |
Updated to call new code-based DataTypes population instead of XML deserialization |
SqlMetaDataFactory.DataTypes.cs |
New file containing all DataTypes table population logic with helper methods for different type categories |
Microsoft.Data.SqlClient.csproj (netfx/netcore) |
Added reference to new SqlMetaDataFactory.DataTypes.cs file |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
This pull request has been marked as stale due to inactivity for more than 30 days. If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days. |
|
This PR is not stale. |
|
/azp run |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
Thanks @paulmedynski and @apoorvdeshmukh. I think my comment may be a bit redundant, but... I've just merged! |
apoorvdeshmukh
left a comment
There was a problem hiding this comment.
@edwardneal There are some test failures. Check the testcase TestJsonWithMARS
This was manually constructing a connection string, which didn't work on one CI leg.
Head branch was pushed to by a user without write access
|
I see the problem, thanks @apoorvdeshmukh. That test was manually building up a connection string to enable MARS, but didn't include the terminator. I've swapped the approach out for a more standard |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3858 +/- ##
==========================================
- Coverage 65.96% 64.82% -1.15%
==========================================
Files 275 271 -4
Lines 42993 66065 +23072
==========================================
+ Hits 28361 42826 +14465
- Misses 14632 23239 +8607
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
This PR makes two related changes: it populates the
DataTypestable returned bySqlConnection.GetSchemain code rather than by deserializing an embedded XML resource, and then adds thejsondata type to this table.In the process of adding tests, I also noticed that there wasn't a coherent view of whether or not the
jsondata type was present, so added one. This also led me to notice that we're not running JSON-based tests on SQL 2025, so I changed their test criteria to make sure this happens. This is essentially the same situation as #3794, and I'm expecting some degree of conflicts depending upon the order they're merged in.It should be possible to move commit-by-commit, but 2f907ed is probably the bulkiest. This commit populates the fields in the
DataTypestable based on the value of fields in theMetaTypeinstances for each type.Issues
Contributes to #3833.
Contributes to #3372.
I'm conscious that #3833 refers to the
jsonand thevectortypes. I've not included the vector type because I don't know whether we should treatvector({0}[, float32])andvector({0}, float16)as two different data types. There's also a little extra plumbing to deal with withinSqlVector<float>and in the tests (which #3794 introduces.)Testing
I've manually verified that all fields for all existing data types are identical between main and this branch. I've also added a new test to prove that no data types have been omitted.