-
Notifications
You must be signed in to change notification settings - Fork 311
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
edwardneal
wants to merge
7
commits into
dotnet:main
Choose a base branch
from
edwardneal:cleanup/sqldatarecord-contextconnection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb5999a
Merge identical one-line methods
edwardneal 609f63b
Merge remaining methods in target-specific files
edwardneal b36d69e
Remove redundant SmiRecordBuffer class
edwardneal 1437afc
Perform initial cleanup of ITypedXettersV3 interfaces
edwardneal 44e9ae5
Remove now-unused resource strings
edwardneal 402b207
Move conditional compilation directive, add parameter name
edwardneal e136b03
Respond to code review
edwardneal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SmiRecordBuffer.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ namespace Microsoft.Data.SqlClient.Server | |
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SqlDataRecord/*' /> | ||
public partial class SqlDataRecord : IDataRecord | ||
{ | ||
private readonly SmiRecordBuffer _recordBuffer; | ||
private readonly MemoryRecordBuffer _recordBuffer; | ||
private readonly SmiExtendedMetaData[] _columnSmiMetaData; | ||
private readonly SqlMetaData[] _columnMetaData; | ||
private FieldNameLookup _fieldNameLookup; | ||
|
@@ -54,10 +54,22 @@ public virtual string GetDataTypeName(int ordinal) | |
#if NET | ||
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)] | ||
#endif | ||
public virtual Type GetFieldType(int ordinal) => GetFieldTypeFrameworkSpecific(ordinal); | ||
public virtual Type GetFieldType(int ordinal) | ||
{ | ||
SqlMetaData md = GetSqlMetaData(ordinal); | ||
|
||
#if NETFRAMEWORK | ||
if (md.SqlDbType == SqlDbType.Udt) | ||
{ | ||
return md.Type; | ||
} | ||
#endif | ||
|
||
return MetaType.GetMetaTypeFromSqlDbType(md.SqlDbType, isMultiValued: false).ClassType; | ||
} | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetValue/*' /> | ||
public virtual object GetValue(int ordinal) => GetValueFrameworkSpecific(ordinal); | ||
public virtual object GetValue(int ordinal) => ValueUtilsSmi.GetValue200(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetValues/*' /> | ||
public virtual int GetValues(object[] values) | ||
|
@@ -177,7 +189,7 @@ public virtual SqlMetaData GetSqlMetaData(int ordinal) | |
public virtual Type GetSqlFieldType(int ordinal) => MetaType.GetMetaTypeFromSqlDbType(GetSqlMetaData(ordinal).SqlDbType, false).SqlType; | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlValue/*' /> | ||
public virtual object GetSqlValue(int ordinal) => GetSqlValueFrameworkSpecific(ordinal); | ||
public virtual object GetSqlValue(int ordinal) => ValueUtilsSmi.GetSqlValue200(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlValues/*' /> | ||
public virtual int GetSqlValues(object[] values) | ||
|
@@ -200,10 +212,10 @@ public virtual int GetSqlValues(object[] values) | |
public virtual SqlBinary GetSqlBinary(int ordinal) => ValueUtilsSmi.GetSqlBinary(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlBytes/*' /> | ||
public virtual SqlBytes GetSqlBytes(int ordinal) => GetSqlBytesFrameworkSpecific(ordinal); | ||
public virtual SqlBytes GetSqlBytes(int ordinal) => ValueUtilsSmi.GetSqlBytes(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlXml/*' /> | ||
public virtual SqlXml GetSqlXml(int ordinal) => GetSqlXmlFrameworkSpecific(ordinal); | ||
public virtual SqlXml GetSqlXml(int ordinal) => ValueUtilsSmi.GetSqlXml(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlBoolean/*' /> | ||
public virtual SqlBoolean GetSqlBoolean(int ordinal) => ValueUtilsSmi.GetSqlBoolean(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
@@ -212,7 +224,7 @@ public virtual int GetSqlValues(object[] values) | |
public virtual SqlByte GetSqlByte(int ordinal) => ValueUtilsSmi.GetSqlByte(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlChars/*' /> | ||
public virtual SqlChars GetSqlChars(int ordinal) => GetSqlCharsFrameworkSpecific(ordinal); | ||
public virtual SqlChars GetSqlChars(int ordinal) => ValueUtilsSmi.GetSqlChars(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/GetSqlInt16/*' /> | ||
public virtual SqlInt16 GetSqlInt16(int ordinal) => ValueUtilsSmi.GetSqlInt16(_recordBuffer, ordinal, GetSmiMetaData(ordinal)); | ||
|
@@ -246,10 +258,78 @@ public virtual int GetSqlValues(object[] values) | |
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValues/*' /> | ||
// ISqlUpdateableRecord Implementation | ||
public virtual int SetValues(params object[] values) => SetValuesFrameworkSpecific(values); | ||
public virtual int SetValues(params object[] values) | ||
{ | ||
if (values == null) | ||
{ | ||
throw ADP.ArgumentNull(nameof(values)); | ||
} | ||
|
||
// Allow values array longer than FieldCount, just ignore the extra cells. | ||
int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
ExtendedClrTypeCode[] typeCodes = new ExtendedClrTypeCode[copyLength]; | ||
|
||
// Verify all data values as acceptable before changing current state. | ||
for (int i = 0; i < copyLength; i++) | ||
{ | ||
SqlMetaData metaData = GetSqlMetaData(i); | ||
typeCodes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( | ||
metaData.SqlDbType, | ||
isMultiValued: false, | ||
values[i], | ||
metaData.Type); | ||
if (typeCodes[i] == ExtendedClrTypeCode.Invalid) | ||
{ | ||
throw ADP.InvalidCast(); | ||
} | ||
} | ||
|
||
// Now move the data. We've already validated the element types above, so this will | ||
// only throw if an invalid UDT was sent. | ||
for (int i = 0; i < copyLength; i++) | ||
{ | ||
ValueUtilsSmi.SetCompatibleValueV200( | ||
_recordBuffer, | ||
ordinal: i, | ||
GetSmiMetaData(i), | ||
values[i], | ||
typeCodes[i], | ||
offset: 0, | ||
peekAhead: null); | ||
} | ||
|
||
return copyLength; | ||
} | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetValue/*' /> | ||
public virtual void SetValue(int ordinal, object value) => SetValueFrameworkSpecific(ordinal, value); | ||
public virtual void SetValue(int ordinal, object value) | ||
{ | ||
SqlMetaData metaData = GetSqlMetaData(ordinal); | ||
ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType( | ||
metaData.SqlDbType, | ||
isMultiValued: false, | ||
value, | ||
metaData.Type); | ||
if (typeCode == ExtendedClrTypeCode.Invalid) | ||
{ | ||
throw ADP.InvalidCast(); | ||
} | ||
|
||
ValueUtilsSmi.SetCompatibleValueV200( | ||
_recordBuffer, | ||
ordinal, | ||
GetSmiMetaData(ordinal), | ||
value, | ||
typeCode, | ||
offset: 0, | ||
peekAhead: null); | ||
} | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetBoolean/*' /> | ||
public virtual void SetBoolean(int ordinal, bool value) => ValueUtilsSmi.SetBoolean(_recordBuffer, ordinal, GetSmiMetaData(ordinal), value); | ||
|
@@ -290,10 +370,10 @@ public virtual int GetSqlValues(object[] values) | |
public virtual void SetDateTime(int ordinal, DateTime value) => ValueUtilsSmi.SetDateTime(_recordBuffer, ordinal, GetSmiMetaData(ordinal), value); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetTimeSpan/*' /> | ||
public virtual void SetTimeSpan(int ordinal, TimeSpan value) => SetTimeSpanFrameworkSpecific(ordinal, value); | ||
public virtual void SetTimeSpan(int ordinal, TimeSpan value) => ValueUtilsSmi.SetTimeSpan(_recordBuffer, ordinal, GetSmiMetaData(ordinal), value); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetDateTimeOffset/*' /> | ||
public virtual void SetDateTimeOffset(int ordinal, DateTimeOffset value) => SetDateTimeOffsetFrameworkSpecific(ordinal, value); | ||
public virtual void SetDateTimeOffset(int ordinal, DateTimeOffset value) => ValueUtilsSmi.SetDateTimeOffset(_recordBuffer, ordinal, GetSmiMetaData(ordinal), value); | ||
|
||
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SetDBNull/*' /> | ||
public virtual void SetDBNull(int ordinal) | ||
|
97 changes: 0 additions & 97 deletions
97
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlDataRecord.netcore.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - done!