Skip to content

Commit b9b9153

Browse files
authored
Cleanup | SMI Cleanup (part 3) (#3431)
* Delete SqlDataReaderSmi * Delete SqlInternalConnectionSmi * Delete eventsink from command class, and code that called it (that was no longer being used) * Delete netfx specific ValueUtilsSmi * Remove the rest of the (now) unused classes for SMI * Make static classes ... static * Remove dead methods * Remove dead properties and fields * Remove SqlSequentialStreamSmi and SqlSequentialTextReaderSmi since they are no longer used * Remove parent from SmiEventSink_Default - which I think means all the methods throw now ... * Remove obsolete code from SmiRecordBuffer * Remove dead code from SmiEventSink for netfx * Remove ITypedGetters/ITypedSetters * Remove unused sink parameters * Remove the now empty netfx SmiEventSink_Default and SmiEventSink * Remove tests from SqlMetaDataTest that exercised dead code * use the same style of #if in SmiEventSink
1 parent 2b9870b commit b9b9153

37 files changed

+385
-5646
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,9 @@
411411
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs">
412412
<Link>Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs</Link>
413413
</Compile>
414-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedGetters.cs">
415-
<Link>Microsoft\Data\SqlClient\Server\ITypedGetters.cs</Link>
416-
</Compile>
417414
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedGettersV3.cs">
418415
<Link>Microsoft\Data\SqlClient\Server\ITypedGettersV3.cs</Link>
419416
</Compile>
420-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedSetters.cs">
421-
<Link>Microsoft\Data\SqlClient\Server\ITypedSetters.cs</Link>
422-
</Compile>
423417
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedSettersV3.cs">
424418
<Link>Microsoft\Data\SqlClient\Server\ITypedSettersV3.cs</Link>
425419
</Compile>
@@ -429,11 +423,8 @@
429423
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs">
430424
<Link>Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs</Link>
431425
</Compile>
432-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
433-
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
434-
</Compile>
435426
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs">
436-
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs</Link>
427+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs</Link>
437428
</Compile>
438429
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiGettersStream.cs">
439430
<Link>Microsoft\Data\SqlClient\Server\SmiGettersStream.cs</Link>

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

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,9 @@
522522
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs">
523523
<Link>Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs</Link>
524524
</Compile>
525-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedGetters.cs">
526-
<Link>Microsoft\Data\SqlClient\Server\ITypedGetters.cs</Link>
527-
</Compile>
528525
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedGettersV3.cs">
529526
<Link>Microsoft\Data\SqlClient\Server\ITypedGettersV3.cs</Link>
530527
</Compile>
531-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedSetters.cs">
532-
<Link>Microsoft\Data\SqlClient\Server\ITypedSetters.cs</Link>
533-
</Compile>
534528
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ITypedSettersV3.cs">
535529
<Link>Microsoft\Data\SqlClient\Server\ITypedSettersV3.cs</Link>
536530
</Compile>
@@ -540,33 +534,12 @@
540534
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs">
541535
<Link>Microsoft\Data\SqlClient\Server\MetadataUtilsSmi.cs</Link>
542536
</Compile>
543-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiConnection.netfx.cs">
544-
<Link>Microsoft\Data\SqlClient\Server\SmiConnection.netfx.cs</Link>
545-
</Compile>
546-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink.cs">
547-
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink.cs</Link>
548-
</Compile>
549537
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs">
550-
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.Common.cs</Link>
551-
</Compile>
552-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs">
553-
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.netfx.cs</Link>
554-
</Compile>
555-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventSink_DeferredProcessing.netfx.cs">
556-
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_DeferredProcessing.netfx.cs</Link>
557-
</Compile>
558-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiEventStream.netfx.cs">
559-
<Link>Microsoft\Data\SqlClient\Server\SmiEventStream.netfx.cs</Link>
560-
</Compile>
561-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiExecuteType.netfx.cs">
562-
<Link>Microsoft\Data\SqlClient\Server\SmiExecuteType.netfx.cs</Link>
538+
<Link>Microsoft\Data\SqlClient\Server\SmiEventSink_Default.cs</Link>
563539
</Compile>
564540
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiGettersStream.cs">
565541
<Link>Microsoft\Data\SqlClient\Server\SmiGettersStream.cs</Link>
566542
</Compile>
567-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiLink.netfx.cs">
568-
<Link>Microsoft\Data\SqlClient\Server\SmiLink.netfx.cs</Link>
569-
</Compile>
570543
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiMetaData.cs">
571544
<Link>Microsoft\Data\SqlClient\Server\SmiMetaData.cs</Link>
572545
</Compile>
@@ -576,15 +549,9 @@
576549
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiRecordBuffer.cs">
577550
<Link>Microsoft\Data\SqlClient\Server\SmiRecordBuffer.cs</Link>
578551
</Compile>
579-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiRequestExecutor.netfx.cs">
580-
<Link>Microsoft\Data\SqlClient\Server\SmiRequestExecutor.netfx.cs</Link>
581-
</Compile>
582552
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiSettersStream.cs">
583553
<Link>Microsoft\Data\SqlClient\Server\SmiSettersStream.cs</Link>
584554
</Compile>
585-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiStream.netfx.cs">
586-
<Link>Microsoft\Data\SqlClient\Server\SmiStream.netfx.cs</Link>
587-
</Compile>
588555
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs">
589556
<Link>Microsoft\Data\SqlClient\Server\SmiTypedGetterSetter.cs</Link>
590557
</Compile>
@@ -615,9 +582,6 @@
615582
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs">
616583
<Link>Microsoft\Data\SqlClient\Server\ValueUtilsSmi.cs</Link>
617584
</Compile>
618-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\ValueUtilsSmi.netfx.cs">
619-
<Link>Microsoft\Data\SqlClient\Server\ValueUtilsSmi.netfx.cs</Link>
620-
</Compile>
621585
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SqlSer.cs">
622586
<Link>Microsoft\Data\SqlClient\Server\SqlSer.cs</Link>
623587
</Compile>
@@ -955,11 +919,7 @@
955919
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
956920
<Compile Include="Microsoft\Data\SqlClient\SqlConnection.cs" />
957921
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionHelper.cs" />
958-
<Compile Include="Microsoft\Data\SqlClient\SqlDataReaderSmi.cs" />
959-
<Compile Include="Microsoft\Data\SqlClient\SqlInternalConnectionSmi.cs" />
960922
<Compile Include="Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs" />
961-
<Compile Include="Microsoft\Data\SqlClient\SqlSequentialStreamSmi.cs" />
962-
<Compile Include="Microsoft\Data\SqlClient\SqlSequentialTextReaderSmi.cs" />
963923
<Compile Include="Microsoft\Data\SqlClient\TdsParser.cs" />
964924
<Compile Include="Microsoft\Data\SqlClient\TdsParser.netfx.cs" />
965925
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.netfx.cs" />

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

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -420,101 +420,6 @@ private CachedAsyncState cachedAsyncState
420420
/// </summary>
421421
internal bool CachingQueryMetadataPostponed { get; set; }
422422

423-
//
424-
// Smi execution-specific stuff
425-
//
426-
sealed private class CommandEventSink : SmiEventSink_Default
427-
{
428-
private SqlCommand _command;
429-
430-
internal CommandEventSink(SqlCommand command) : base()
431-
{
432-
_command = command;
433-
}
434-
435-
internal override void StatementCompleted(int rowsAffected)
436-
{
437-
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlCommand.CommandEventSink.StatementCompleted|ADV> {0}, rowsAffected={1}.", _command.ObjectID, rowsAffected);
438-
_command.InternalRecordsAffected = rowsAffected;
439-
440-
// UNDONE: need to fire events back to user code, but this may be called
441-
// while in a callback from the native server. Calling user code in
442-
// this situation is BAAAAD, because the user code could call back to
443-
// the server.
444-
// _command.OnStatementCompleted( rowsAffected );
445-
}
446-
447-
internal override void BatchCompleted()
448-
{
449-
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlCommand.CommandEventSink.BatchCompleted|ADV> {0}.", _command.ObjectID);
450-
}
451-
452-
internal override void ParametersAvailable(SmiParameterMetaData[] metaData, ITypedGettersV3 parameterValues)
453-
{
454-
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlCommand.CommandEventSink.ParametersAvailable|ADV> {0} metaData.Length={1}.", _command.ObjectID, metaData?.Length);
455-
456-
if (SqlClientEventSource.Log.IsAdvancedTraceOn())
457-
{
458-
if (metaData != null)
459-
{
460-
for (int i = 0; i < metaData.Length; i++)
461-
{
462-
SqlClientEventSource.Log.AdvancedTraceEvent("<sc.SqlCommand.CommandEventSink.ParametersAvailable|ADV> {0}, metaData[{1}] is {2}{3}", _command.ObjectID, i, metaData[i].GetType(), metaData[i].TraceString());
463-
}
464-
}
465-
}
466-
467-
Debug.Fail("NegotiatedSmiVersion will always throw (SmiContextFactory.Instance.NegotiatedSmiVersion >= SmiContextFactory.Sql2005Version)");
468-
_command.OnParametersAvailableSmi(metaData, parameterValues);
469-
}
470-
471-
internal override void ParameterAvailable(SmiParameterMetaData metaData, SmiTypedGetterSetter parameterValues, int ordinal)
472-
{
473-
if (SqlClientEventSource.Log.IsAdvancedTraceOn())
474-
{
475-
SqlClientEventSource.Log.AdvancedTraceEvent("<sc.SqlCommand.CommandEventSink.ParameterAvailable|ADV> {0}, metaData[{1}] is {2}{ 3}", _command.ObjectID, ordinal, metaData?.GetType(), metaData?.TraceString());
476-
}
477-
478-
Debug.Fail("NegotiatedSmiVersion will always throw (SmiContextFactory.Instance.NegotiatedSmiVersion >= SmiContextFactory.Sql2008Version)");
479-
_command.OnParameterAvailableSmi(metaData, parameterValues, ordinal);
480-
}
481-
}
482-
483-
private CommandEventSink _smiEventSink;
484-
private SmiEventSink_DeferredProcessing _outParamEventSink;
485-
486-
private CommandEventSink EventSink
487-
{
488-
get
489-
{
490-
if (_smiEventSink == null)
491-
{
492-
_smiEventSink = new CommandEventSink(this);
493-
}
494-
495-
_smiEventSink.Parent = InternalSmiConnection.CurrentEventSink;
496-
return _smiEventSink;
497-
}
498-
}
499-
500-
private SmiEventSink_DeferredProcessing OutParamEventSink
501-
{
502-
get
503-
{
504-
if (_outParamEventSink == null)
505-
{
506-
_outParamEventSink = new SmiEventSink_DeferredProcessing(EventSink);
507-
}
508-
else
509-
{
510-
_outParamEventSink.Parent = EventSink;
511-
}
512-
513-
return _outParamEventSink;
514-
}
515-
}
516-
517-
518423
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml' path='docs/members[@name="SqlCommand"]/ctor[@name="default"]/*'/>
519424
public SqlCommand() : base()
520425
{
@@ -655,14 +560,6 @@ protected override DbConnection DbConnection
655560
}
656561
}
657562

658-
private SqlInternalConnectionSmi InternalSmiConnection
659-
{
660-
get
661-
{
662-
return (SqlInternalConnectionSmi)_activeConnection.InnerConnection;
663-
}
664-
}
665-
666563
private SqlInternalConnectionTds InternalTdsConnection
667564
{
668565
get
@@ -6137,66 +6034,6 @@ internal void OnReturnValue(SqlReturnValue rec, TdsParserStateObject stateObj)
61376034
return;
61386035
}
61396036

6140-
internal void OnParametersAvailableSmi(SmiParameterMetaData[] paramMetaData, ITypedGettersV3 parameterValues)
6141-
{
6142-
Debug.Assert(paramMetaData != null);
6143-
6144-
for (int index = 0; index < paramMetaData.Length; index++)
6145-
{
6146-
OnParameterAvailableSmi(paramMetaData[index], parameterValues, index);
6147-
}
6148-
}
6149-
6150-
internal void OnParameterAvailableSmi(SmiParameterMetaData metaData, ITypedGettersV3 parameterValues, int ordinal)
6151-
{
6152-
if (ParameterDirection.Input != metaData.Direction)
6153-
{
6154-
string name = null;
6155-
if (ParameterDirection.ReturnValue != metaData.Direction)
6156-
{
6157-
name = metaData.Name;
6158-
}
6159-
6160-
SqlParameterCollection parameters = GetCurrentParameterCollection();
6161-
int count = GetParameterCount(parameters);
6162-
SqlParameter param = GetParameterForOutputValueExtraction(parameters, name, count);
6163-
6164-
if (param != null)
6165-
{
6166-
param.LocaleId = (int)metaData.LocaleId;
6167-
param.CompareInfo = metaData.CompareOptions;
6168-
SqlBuffer buffer = new SqlBuffer();
6169-
object result;
6170-
if (_activeConnection.Is2008OrNewer)
6171-
{
6172-
result = ValueUtilsSmi.GetOutputParameterV200Smi(
6173-
OutParamEventSink,
6174-
(SmiTypedGetterSetter)parameterValues,
6175-
ordinal,
6176-
metaData,
6177-
buffer);
6178-
}
6179-
else
6180-
{
6181-
result = ValueUtilsSmi.GetOutputParameterV3Smi(
6182-
OutParamEventSink,
6183-
parameterValues,
6184-
ordinal,
6185-
metaData,
6186-
buffer);
6187-
}
6188-
if (result != null)
6189-
{
6190-
param.Value = result;
6191-
}
6192-
else
6193-
{
6194-
param.SetSqlBuffer(buffer);
6195-
}
6196-
}
6197-
}
6198-
}
6199-
62006037
private SqlParameterCollection GetCurrentParameterCollection()
62016038
{
62026039
if (_batchRPCMode)

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,33 +1906,24 @@ private bool TryOpenInner(TaskCompletionSource<DbConnectionInternal> retry)
19061906
// GetBestEffortCleanup must happen AFTER OpenConnection to get the correct target.
19071907
bestEffortCleanupTarget = SqlInternalConnection.GetBestEffortCleanupTarget(this);
19081908

1909-
var tdsInnerConnection = (InnerConnection as SqlInternalConnectionTds);
1910-
if (tdsInnerConnection == null)
1909+
var tdsInnerConnection = (SqlInternalConnectionTds)InnerConnection;
1910+
Debug.Assert(tdsInnerConnection.Parser != null, "Where's the parser?");
1911+
1912+
if (!tdsInnerConnection.ConnectionOptions.Pooling)
1913+
{
1914+
// For non-pooled connections, we need to make sure that the finalizer does actually run to avoid leaking SNI handles
1915+
GC.ReRegisterForFinalize(this);
1916+
}
1917+
1918+
if (StatisticsEnabled)
19111919
{
1912-
// @TODO: This branch can't be called, because it'll automatically break. But I can't prove it isn't just yet....
1913-
SqlInternalConnectionSmi innerConnection = (InnerConnection as SqlInternalConnectionSmi);
1914-
innerConnection.AutomaticEnlistment();
1920+
_statistics._openTimestamp = ADP.TimerCurrent();
1921+
tdsInnerConnection.Parser.Statistics = _statistics;
19151922
}
19161923
else
19171924
{
1918-
Debug.Assert(tdsInnerConnection.Parser != null, "Where's the parser?");
1919-
1920-
if (!tdsInnerConnection.ConnectionOptions.Pooling)
1921-
{
1922-
// For non-pooled connections, we need to make sure that the finalizer does actually run to avoid leaking SNI handles
1923-
GC.ReRegisterForFinalize(this);
1924-
}
1925-
1926-
if (StatisticsEnabled)
1927-
{
1928-
_statistics._openTimestamp = ADP.TimerCurrent();
1929-
tdsInnerConnection.Parser.Statistics = _statistics;
1930-
}
1931-
else
1932-
{
1933-
tdsInnerConnection.Parser.Statistics = null;
1934-
_statistics = null; // in case of previous Open/Close/reset_CollectStats sequence
1935-
}
1925+
tdsInnerConnection.Parser.Statistics = null;
1926+
_statistics = null; // in case of previous Open/Close/reset_CollectStats sequence
19361927
}
19371928
}
19381929
catch (System.OutOfMemoryException e)

0 commit comments

Comments
 (0)