Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

SqlClient enhancement enable GetFieldValue<XmlReader> #34880

Merged
merged 2 commits into from
Feb 5, 2019

Conversation

Wraith2
Copy link
Contributor

@Wraith2 Wraith2 commented Jan 26, 2019

Closes https://github.com/dotnet/corefx/issues/30958

To get data from an SqlDataReader instance you can use a number of approaches. One approach is to use Get[Type] overloads like GetInt32(int) and GetXmlReader(int), another is to use the new GetFieldValue<T> generic version. Unfortunately while most types work with the generic function XmlReader does not and will throw an error. This PR changes that behaviour and adds special casing for GetFieldValue<XmlReader> so that the more modern api style can be used with xml without special casing in the calling method.

GetXmlReader(int) handles null values by returning an empty stream, it is not considered an error. GetFieldValue will usually throw on a null value. I have chosen to replicate the GetXmlReader behaviour and return an empty stream on DBNull. I can see an argument that it should throw on DBNull instead, please consider this.

As usual the standard and manual tests have been run in native mode and passed successfully (apart from those noted in #34546). The changes are high up in the stack so native vs managed will make no difference. Tests are added to the existing DataStreamTest list.

/cc all the usual people @keeratsingh @afsanehr @saurabh500 and requestor @bricelam

add SqlTypeWorkarounds xml reader creation overload for TextReader
add DataStream test for GetFielvdValue<XmlReader> for value and null
@AfsanehR-zz AfsanehR-zz merged commit 9007057 into dotnet:master Feb 5, 2019
@AfsanehR-zz
Copy link
Contributor

Thank you for your contribution @Wraith2 !

@Wraith2 Wraith2 deleted the sqlfeature-getfieldvaluexml branch February 6, 2019 00:16
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…ldvaluexml

SqlClient enhancement enable GetFieldValue<XmlReader>

Commit migrated from dotnet/corefx@9007057
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants