Skip to content

Commit 9be9a5a

Browse files
authored
Cleanup | Remove More Dead SMI Code (Part 2) (#3414)
* Oh hey, InOutOfProcHelper.InProc always returns false! Let's propagate that false everywhere it was being used to determine what other branches of code can be deleted * Remove usages of IsInProc that were always false * Remove dead code in SmiContextFactory and distill properties down to exceptions they will always throw b/c _smiLink will always be null * Propagate always thrown exceptions, remove that code from SmiContextFactory * Remove SmiVersion that was hardcoded to 2008. Propagate 2008 to all usages of the property It can continue to be propagated if we find out the version is always the same... * Remove SmiContextFactory.LatestVersion by replacing usage with 2008 and propagate that forward, allowing us to remove MetadataUtilsSmi.IsValidForSmiVersion and a block of code in SqlDataRecord * Propagate 2008 version, which eliminates a bunch of conditions, eliminating the last uses of SmiVersion2008 * Delete the now unused SmiContextFactory class * Remove _smiRequestContext from SqlCommand since it is always assigned `null`, replacing usages of it with `null` * Remove context parameter from ValueUtilsSmi.GetOutputParameterV3Smi, since it is always passed to itself * Remove context parameter from ValueUtilsSmi.GetOutputParameterV200Smi, since it is always passed to itself and is always null * Delete ExecuteToPipe since it is no longer being used. * Remove _recordContext from SqlDataRecord since it is always null, propagate null to all usages of it * SqlInternalConnectionSmi.InternalContext is always null, deleting and propagating null to all usages of it Also removing SqlInternalConnectionSmi.SmiConnection since it's never used. * Removing SqlContext usages from ValueUtilsSmi - it was always null, so it can be eliminated * Removing last references to SqlContext in SqlInternalConnectionSmi * Delete SmiContext * @edwardneal is a hero, deleting another bundle of unused code.
1 parent 95253ac commit 9be9a5a

20 files changed

+213
-1084
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,6 @@
543543
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiConnection.netfx.cs">
544544
<Link>Microsoft\Data\SqlClient\Server\SmiConnection.netfx.cs</Link>
545545
</Compile>
546-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiContext.netfx.cs">
547-
<Link>Microsoft\Data\SqlClient\Server\SmiContext.netfx.cs</Link>
548-
</Compile>
549-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiContextFactory.netfx.cs">
550-
<Link>Microsoft\Data\SqlClient\Server\SmiContextFactory.netfx.cs</Link>
551-
</Compile>
552546
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
553547
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
554548
</Compile>
@@ -953,8 +947,6 @@
953947
</Compile>
954948

955949
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
956-
<Compile Include="Microsoft\Data\SqlClient\SqlClientWrapperSmiStream.cs" />
957-
<Compile Include="Microsoft\Data\SqlClient\SqlClientWrapperSmiStreamChars.cs" />
958950
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
959951
<Compile Include="Microsoft\Data\SqlClient\SqlConnection.cs" />
960952
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionFactory.cs" />
@@ -968,7 +960,6 @@
968960
<Compile Include="Microsoft\Data\SqlClient\TdsParser.netfx.cs" />
969961
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.netfx.cs" />
970962
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectNative.cs" />
971-
<Compile Include="Microsoft\Data\SqlTypes\SqlStreamChars.cs" />
972963
<Compile Include="Microsoft\Data\SqlTypes\SqlTypeWorkarounds.netfx.cs" />
973964
</ItemGroup>
974965
<!-- Resources -->

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientWrapperSmiStream.cs

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

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientWrapperSmiStreamChars.cs

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

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ internal override void ParametersAvailable(SmiParameterMetaData[] metaData, ITyp
463463
}
464464
}
465465
}
466-
467-
Debug.Assert(SmiContextFactory.Instance.NegotiatedSmiVersion >= SmiContextFactory.Sql2005Version);
466+
467+
Debug.Fail("NegotiatedSmiVersion will always throw (SmiContextFactory.Instance.NegotiatedSmiVersion >= SmiContextFactory.Sql2005Version)");
468468
_command.OnParametersAvailableSmi(metaData, parameterValues);
469469
}
470470

@@ -474,12 +474,12 @@ internal override void ParameterAvailable(SmiParameterMetaData metaData, SmiType
474474
{
475475
SqlClientEventSource.Log.AdvancedTraceEvent("<sc.SqlCommand.CommandEventSink.ParameterAvailable|ADV> {0}, metaData[{1}] is {2}{ 3}", _command.ObjectID, ordinal, metaData?.GetType(), metaData?.TraceString());
476476
}
477-
Debug.Assert(SmiContextFactory.Instance.NegotiatedSmiVersion >= SmiContextFactory.Sql2008Version);
477+
478+
Debug.Fail("NegotiatedSmiVersion will always throw (SmiContextFactory.Instance.NegotiatedSmiVersion >= SmiContextFactory.Sql2008Version)");
478479
_command.OnParameterAvailableSmi(metaData, parameterValues, ordinal);
479480
}
480481
}
481482

482-
private SmiContext _smiRequestContext; // context that _smiRequest came from
483483
private CommandEventSink _smiEventSink;
484484
private SmiEventSink_DeferredProcessing _outParamEventSink;
485485

@@ -599,9 +599,6 @@ private SqlCommand(SqlCommand from) : this()
599599
_transaction = null;
600600
}
601601

602-
// If the connection has changes, then the request context may have changed as well
603-
_smiRequestContext = null;
604-
605602
// Command is no longer prepared on new connection, cleanup prepare status
606603
if (IsPrepared)
607604
{
@@ -1560,32 +1557,6 @@ public override int ExecuteNonQuery()
15601557
}
15611558
}
15621559

1563-
// Handles in-proc execute-to-pipe functionality
1564-
// Identical to ExecuteNonQuery
1565-
internal void ExecuteToPipe(SmiContext pipeContext)
1566-
{
1567-
SqlConnection.ExecutePermission.Demand();
1568-
1569-
// Reset _pendingCancel upon entry into any Execute - used to synchronize state
1570-
// between entry into Execute* API and the thread obtaining the stateObject.
1571-
_pendingCancel = false;
1572-
1573-
SqlStatistics statistics = null;
1574-
1575-
using (TryEventScope.Create("<sc.SqlCommand.ExecuteToPipe|INFO> {0}", ObjectID))
1576-
{
1577-
try
1578-
{
1579-
statistics = SqlStatistics.StartTimer(Statistics);
1580-
InternalExecuteNonQuery(null, nameof(ExecuteNonQuery), true, CommandTimeout, out _);
1581-
}
1582-
finally
1583-
{
1584-
SqlStatistics.StopTimer(statistics);
1585-
}
1586-
}
1587-
}
1588-
15891560
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml' path='docs/members[@name="SqlCommand"]/BeginExecuteNonQuery[@name="default"]/*'/>
15901561
[System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)]
15911562
public IAsyncResult BeginExecuteNonQuery()
@@ -6199,12 +6170,20 @@ internal void OnParameterAvailableSmi(SmiParameterMetaData metaData, ITypedGette
61996170
if (_activeConnection.Is2008OrNewer)
62006171
{
62016172
result = ValueUtilsSmi.GetOutputParameterV200Smi(
6202-
OutParamEventSink, (SmiTypedGetterSetter)parameterValues, ordinal, metaData, _smiRequestContext, buffer);
6173+
OutParamEventSink,
6174+
(SmiTypedGetterSetter)parameterValues,
6175+
ordinal,
6176+
metaData,
6177+
buffer);
62036178
}
62046179
else
62056180
{
62066181
result = ValueUtilsSmi.GetOutputParameterV3Smi(
6207-
OutParamEventSink, parameterValues, ordinal, metaData, _smiRequestContext, buffer);
6182+
OutParamEventSink,
6183+
parameterValues,
6184+
ordinal,
6185+
metaData,
6186+
buffer);
62086187
}
62096188
if (result != null)
62106189
{

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,7 @@ private bool TryOpenInner(TaskCompletionSource<DbConnectionInternal> retry)
19091909
var tdsInnerConnection = (InnerConnection as SqlInternalConnectionTds);
19101910
if (tdsInnerConnection == null)
19111911
{
1912+
// @TODO: This branch can't be called, because it'll automatically break. But I can't prove it isn't just yet....
19121913
SqlInternalConnectionSmi innerConnection = (InnerConnection as SqlInternalConnectionSmi);
19131914
innerConnection.AutomaticEnlistment();
19141915
}

0 commit comments

Comments
 (0)