-
Notifications
You must be signed in to change notification settings - Fork 300
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
JSON datatype support in SqlClient #2622
Labels
Area\Json
Issues that are targeted for the Json feature in the driver.
💡 Enhancement
Issues that are feature requests for the drivers we maintain.
Comments
5 tasks
Adding GetFieldValue(Async) adds a hard dependency on the System.Text.Json library. |
@Wraith2 System.Text.Json is part of .NET in modern versions, so a package reference is only needed on old TFMs. Even for those old TFMs, a system dependency such as System.Text.Json is generally not a problem. |
Yup, it's just missing from the dependencies list in the first post is all. |
@Wraith2 oh I see, thanks! |
This was referenced Jul 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Area\Json
Issues that are targeted for the Json feature in the driver.
💡 Enhancement
Issues that are feature requests for the drivers we maintain.
The support for the JSON data type is in preview in Azure SQL DB https://techcommunity.microsoft.com/t5/azure-sql-blog/native-json-type-amp-json-aggregates-are-now-in-private-preview/ba-p/3830753
To enable applications to leverage JSON effectively, the SqlClient driver will require changes as well.
When it comes to the APIs of the JSON support, the fundamental APIs which are foundational are
SqlDbType.Json
enum.SqlJson
.System.Data.SqlDbType
ships with dotnet/runtime, and changes to SqlDbType will be made in the runtime repo. There is an issue open in dotnet/runtime at dotnet/runtime#103925SqlJson
unlike other SqlTypes will ship in Microsoft.Data.SqlClient.Related EF issue at dotnet/efcore#32150
APIs
The APIs that have been identified for modification are
SqlDataReader.GetFieldValue<string>()
-> Returns a JSON string.SqlDataReader.GetFieldValue<JsonDocument>()
-> Returns a System.Text.JsonDocument.SqlDataReader.GetFieldValueAsync<T>()
async equivalents as well.SqlDbType.Json
: This would allow the SqlParameters to be qualified as Json types.SqlDataReader.GetString(int colOrdinal)
: This should return a JSON string.SqlDataReader.GetFieldValue<byte[]>(int colOrdinal)
. The byte[] returned should be usable by Utf8JsonReader to create a JSON reader. This is the high performance scenario in .Net.SqlDataReader.GetStream()
should support a TextStream which can be serialized as a JSON text. We will need to check if the COLTYPE is JSON, then we stream the data according to the payload sent by the server.SqlDataReader.GetFieldType(Int32)
: Returns the ‘type’ for JSONSqlDataReader.GetSqlJson(Int32)
: Returns aSqlJson
that contains the JSON stored within the corresponding field.SqlParameter
will not have any new APIs exposed. The behavior of existing APIs will be enhanced, so that they can work withSqlDbType
andSqlJson
type.Backward compat with server without JSON support
Backward compat of new client with old server. What happens when
SqlDbType.Json
/SqlJson
is used with a server, which doesn't have Json support. This is pending discussions.Decision: The client will send the new TDS type to older sql server, and the sql server will error out, and the error will be exchanged appropriately with the clients.
Technical details
0x0D
tdsType
for JSON is planned to be244
Dependencies
SqlDbType
enum update.Child issues and PRs tracking this work
The text was updated successfully, but these errors were encountered: