Skip to content

Commit 7305c1c

Browse files
Move to Shared -SqlDataRecord (#1309)
1 parent f88b7e4 commit 7305c1c

File tree

7 files changed

+662
-1004
lines changed

7 files changed

+662
-1004
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@
157157
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiMetaData.cs">
158158
<Link>Microsoft\Data\SqlClient\Server\SmiMetaData.cs</Link>
159159
</Compile>
160+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlDataRecord.cs">
161+
<Link>Microsoft\Data\SqlClient\Server\SqlDataRecord.cs</Link>
162+
</Compile>
163+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlDataRecord.netcore.cs">
164+
<Link>Microsoft\Data\SqlClient\Server\SqlDataRecord.netcore.cs</Link>
165+
</Compile>
160166
<Compile Include="..\..\src\Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs">
161167
<Link>Microsoft\Data\SqlClient\ColumnEncryptionKeyInfo.cs</Link>
162168
</Compile>
@@ -465,7 +471,6 @@
465471
<Compile Include="Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs" />
466472
<Compile Include="Microsoft\Data\SqlClient\Server\SmiMetaDataProperty.cs" />
467473
<Compile Include="Microsoft\Data\SqlClient\Server\SmiXetterAccessMap.cs" />
468-
<Compile Include="Microsoft\Data\SqlClient\Server\SqlDataRecord.cs" />
469474
<Compile Include="Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs" />
470475
<Compile Include="Microsoft\Data\SqlClient\SqlDbColumn.cs" />
471476
<Compile Include="Microsoft\Data\Common\DbConnectionOptions.cs" />

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Server/SqlDataRecord.cs

Lines changed: 0 additions & 461 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@
225225
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs">
226226
<Link>Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs</Link>
227227
</Compile>
228+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlDataRecord.cs">
229+
<Link>Microsoft\Data\SqlClient\Server\SqlDataRecord.cs</Link>
230+
</Compile>
231+
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SqlDataRecord.netfx.cs">
232+
<Link>Microsoft\Data\SqlClient\Server\SqlDataRecord.netfx.cs</Link>
233+
</Compile>
228234
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\SmiMetaData.cs">
229235
<Link>Microsoft\Data\SqlClient\Server\SmiMetaData.cs</Link>
230236
</Compile>
@@ -466,7 +472,6 @@
466472
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
467473
<Compile Include="Microsoft\Data\SqlClient\LocalDBConfig.cs" />
468474
<Compile Include="Microsoft\Data\SqlClient\Reliability\SqlConfigurableRetryLogicManager.LoadType.cs" />
469-
<Compile Include="Microsoft\Data\SqlClient\Server\SqlDataRecord.cs" />
470475
<Compile Include="Microsoft\Data\SqlClient\Server\TriggerAction.cs" />
471476
<Compile Include="Microsoft\Data\SqlTypes\SqlFileStream.cs" />
472477
<Compile Include="Microsoft\Data\SqlTypes\UnsafeNativeMethods.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Server/SqlDataRecord.cs

Lines changed: 0 additions & 541 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/SqlDataRecord.cs

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Data;
7+
using System.Data.SqlTypes;
8+
using Microsoft.Data.Common;
9+
10+
namespace Microsoft.Data.SqlClient.Server
11+
{
12+
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SqlDataRecord/*' />
13+
public partial class SqlDataRecord : IDataRecord
14+
{
15+
private Type GetFieldTypeFrameworkSpecific(int ordinal)
16+
=> MetaType.GetMetaTypeFromSqlDbType(GetSqlMetaData(ordinal).SqlDbType, false).ClassType;
17+
18+
private object GetValueFrameworkSpecific(int ordinal)
19+
=> ValueUtilsSmi.GetValue200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal));
20+
private object GetSqlValueFrameworkSpecific(int ordinal)
21+
=> ValueUtilsSmi.GetSqlValue200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal));
22+
23+
private SqlBytes GetSqlBytesFrameworkSpecific(int ordinal)
24+
=> ValueUtilsSmi.GetSqlBytes(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal));
25+
26+
private SqlXml GetSqlXmlFrameworkSpecific(int ordinal)
27+
=> ValueUtilsSmi.GetSqlXml(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal));
28+
29+
private SqlChars GetSqlCharsFrameworkSpecific(int ordinal)
30+
=> ValueUtilsSmi.GetSqlChars(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal));
31+
private int SetValuesFrameworkSpecific(params object[] values)
32+
{
33+
if (values == null)
34+
{
35+
throw ADP.ArgumentNull(nameof(values));
36+
}
37+
38+
// Allow values array longer than FieldCount, just ignore the extra cells.
39+
int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length;
40+
41+
ExtendedClrTypeCode[] typeCodes = new ExtendedClrTypeCode[copyLength];
42+
43+
// Verify all data values as acceptable before changing current state.
44+
for (int i = 0; i < copyLength; i++)
45+
{
46+
SqlMetaData metaData = GetSqlMetaData(i);
47+
typeCodes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(
48+
metaData.SqlDbType,
49+
isMultiValued: false,
50+
values[i],
51+
metaData.Type
52+
);
53+
if (typeCodes[i] == ExtendedClrTypeCode.Invalid)
54+
{
55+
throw ADP.InvalidCast();
56+
}
57+
}
58+
59+
// Now move the data (it'll only throw if someone plays with the values array between
60+
// the validation loop and here, or if an invalid UDT was sent).
61+
for (int i = 0; i < copyLength; i++)
62+
{
63+
ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0, length: 0, peekAhead: null);
64+
}
65+
66+
return copyLength;
67+
}
68+
69+
private void SetValueFrameworkSpecific(int ordinal, object value)
70+
{
71+
SqlMetaData metaData = GetSqlMetaData(ordinal);
72+
ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(
73+
metaData.SqlDbType,
74+
isMultiValued: false,
75+
value,
76+
metaData.Type
77+
);
78+
if (typeCode == ExtendedClrTypeCode.Invalid)
79+
{
80+
throw ADP.InvalidCast();
81+
}
82+
83+
ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0, length: 0, peekAhead: null);
84+
}
85+
86+
private void SetTimeSpanFrameworkSpecific(int ordinal, TimeSpan value)
87+
=> ValueUtilsSmi.SetTimeSpan(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value);
88+
89+
private void SetDateTimeOffsetFrameworkSpecific(int ordinal, DateTimeOffset value)
90+
=> ValueUtilsSmi.SetDateTimeOffset(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value);
91+
92+
}
93+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Data;
7+
using System.Data.SqlTypes;
8+
using Microsoft.Data.Common;
9+
10+
namespace Microsoft.Data.SqlClient.Server
11+
{
12+
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient.Server/SqlDataRecord.xml' path='docs/members[@name="SqlDataRecord"]/SqlDataRecord/*' />
13+
public partial class SqlDataRecord : IDataRecord
14+
{
15+
private readonly SmiContext _recordContext;
16+
17+
private Type GetFieldTypeFrameworkSpecific(int ordinal)
18+
{
19+
SqlMetaData md = GetSqlMetaData(ordinal);
20+
if (md.SqlDbType == SqlDbType.Udt)
21+
{
22+
return md.Type;
23+
}
24+
else
25+
{
26+
return MetaType.GetMetaTypeFromSqlDbType(md.SqlDbType, false).ClassType;
27+
}
28+
}
29+
30+
private object GetValueFrameworkSpecific(int ordinal)
31+
{
32+
SmiMetaData metaData = GetSmiMetaData(ordinal);
33+
if (SmiVersion >= SmiContextFactory.KatmaiVersion)
34+
{
35+
return ValueUtilsSmi.GetValue200(_eventSink, _recordBuffer, ordinal, metaData, _recordContext);
36+
}
37+
else
38+
{
39+
return ValueUtilsSmi.GetValue(_eventSink, _recordBuffer, ordinal, metaData, _recordContext);
40+
}
41+
}
42+
43+
private object GetSqlValueFrameworkSpecific(int ordinal)
44+
{
45+
SmiMetaData metaData = GetSmiMetaData(ordinal);
46+
if (SmiVersion >= SmiContextFactory.KatmaiVersion)
47+
{
48+
return ValueUtilsSmi.GetSqlValue200(_eventSink, _recordBuffer, ordinal, metaData, _recordContext);
49+
}
50+
return ValueUtilsSmi.GetSqlValue(_eventSink, _recordBuffer, ordinal, metaData, _recordContext);
51+
}
52+
53+
private SqlBytes GetSqlBytesFrameworkSpecific(int ordinal) => ValueUtilsSmi.GetSqlBytes(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), _recordContext);
54+
55+
private SqlXml GetSqlXmlFrameworkSpecific(int ordinal) => ValueUtilsSmi.GetSqlXml(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), _recordContext);
56+
57+
private SqlChars GetSqlCharsFrameworkSpecific(int ordinal) => ValueUtilsSmi.GetSqlChars(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), _recordContext);
58+
59+
private int SetValuesFrameworkSpecific(params object[] values)
60+
{
61+
if (values == null)
62+
{
63+
throw ADP.ArgumentNull(nameof(values));
64+
}
65+
66+
// Allow values array longer than FieldCount, just ignore the extra cells.
67+
int copyLength = (values.Length > FieldCount) ? FieldCount : values.Length;
68+
69+
ExtendedClrTypeCode[] typeCodes = new ExtendedClrTypeCode[copyLength];
70+
71+
// Verify all data values as acceptable before changing current state.
72+
for (int i = 0; i < copyLength; i++)
73+
{
74+
SqlMetaData metaData = GetSqlMetaData(i);
75+
typeCodes[i] = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(
76+
metaData.SqlDbType,
77+
isMultiValued: false,
78+
values[i],
79+
metaData.Type,
80+
SmiVersion
81+
);
82+
if (typeCodes[i] == ExtendedClrTypeCode.Invalid)
83+
{
84+
throw ADP.InvalidCast();
85+
}
86+
}
87+
88+
// Now move the data (it'll only throw if someone plays with the values array between
89+
// the validation loop and here, or if an invalid UDT was sent).
90+
for (int i = 0; i < copyLength; i++)
91+
{
92+
if (SmiVersion >= SmiContextFactory.KatmaiVersion)
93+
{
94+
ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0, length: 0, peekAhead: null);
95+
}
96+
else
97+
{
98+
ValueUtilsSmi.SetCompatibleValue(_eventSink, _recordBuffer, i, GetSmiMetaData(i), values[i], typeCodes[i], offset: 0);
99+
}
100+
}
101+
102+
return copyLength;
103+
}
104+
105+
private void SetValueFrameworkSpecific(int ordinal, object value)
106+
{
107+
SqlMetaData metaData = GetSqlMetaData(ordinal);
108+
ExtendedClrTypeCode typeCode = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(
109+
metaData.SqlDbType,
110+
isMultiValued: false,
111+
value,
112+
metaData.Type,
113+
SmiVersion
114+
);
115+
if (typeCode == ExtendedClrTypeCode.Invalid)
116+
{
117+
throw ADP.InvalidCast();
118+
}
119+
120+
if (SmiVersion >= SmiContextFactory.KatmaiVersion)
121+
{
122+
ValueUtilsSmi.SetCompatibleValueV200(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0, length: 0, peekAhead: null);
123+
}
124+
else
125+
{
126+
ValueUtilsSmi.SetCompatibleValue(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, typeCode, offset: 0);
127+
}
128+
}
129+
130+
private void SetTimeSpanFrameworkSpecific(int ordinal, TimeSpan value) => ValueUtilsSmi.SetTimeSpan(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, SmiVersion >= SmiContextFactory.KatmaiVersion);
131+
private void SetDateTimeOffsetFrameworkSpecific(int ordinal, DateTimeOffset value) => ValueUtilsSmi.SetDateTimeOffset(_eventSink, _recordBuffer, ordinal, GetSmiMetaData(ordinal), value, SmiVersion >= SmiContextFactory.KatmaiVersion);
132+
133+
private ulong SmiVersion => InOutOfProcHelper.InProc ? SmiContextFactory.Instance.NegotiatedSmiVersion : SmiContextFactory.LatestVersion;
134+
}
135+
}

0 commit comments

Comments
 (0)