This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
SqlClient enhancement enable GetFieldValue<XmlReader> #34880
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
andGetXmlReader(int)
, another is to use the newGetFieldValue<T>
generic version. Unfortunately while most types work with the generic functionXmlReader
does not and will throw an error. This PR changes that behaviour and adds special casing forGetFieldValue<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 theGetXmlReader
behaviour and return an empty stream onDBNull
. I can see an argument that it should throw onDBNull
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