Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
The command object that is executing.
</summary>
</Command>
<BatchCommands>
<summary>
The commands that make up the batch when the command is executing as part of a <see cref="T:Microsoft.Data.SqlClient.SqlBatch" />, or <see langword="null" /> when it is not.
</summary>
</BatchCommands>
</members>
<members name="SqlClientCommandAfter">
<SqlClientCommandAfter>
Expand Down Expand Up @@ -130,6 +135,11 @@
An IDictionary of statistic information about the event that has completed.
</summary>
</Statistics>
<BatchCommands>
<summary>
The commands that make up the batch when the command is executing as part of a <see cref="T:Microsoft.Data.SqlClient.SqlBatch" />, or <see langword="null" /> when it is not.
</summary>
</BatchCommands>
</members>
<members name="SqlClientCommandError">
<SqlClientCommandError>
Expand Down Expand Up @@ -162,6 +172,11 @@
The exception object that caused the command execution to fail.
</summary>
</Exception>
<BatchCommands>
<summary>
The commands that make up the batch when the command is executing as part of a <see cref="T:Microsoft.Data.SqlClient.SqlBatch" />, or <see langword="null" /> when it is not.
</summary>
</BatchCommands>
</members>
<members name="SqlClientConnectionOpenBefore">
<SqlClientConnectionOpenBefore>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public sealed class SqlClientCommandAfter : System.Collections.Generic.IReadOnly
public SqlCommand Command => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandAfter"]/Statistics/*'/>
public System.Collections.IDictionary Statistics => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandAfter"]/BatchCommands/*'/>
public System.Collections.Generic.IReadOnlyList<SqlBatchCommand> BatchCommands => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Count/*'/>
public int Count => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Item1/*'/>
Expand Down Expand Up @@ -50,6 +52,8 @@ public sealed class SqlClientCommandBefore : System.Collections.Generic.IReadOnl
public long? TransactionId => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandBefore"]/Command/*'/>
public SqlCommand Command => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandBefore"]/BatchCommands/*'/>
public System.Collections.Generic.IReadOnlyList<SqlBatchCommand> BatchCommands => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Count/*'/>
public int Count => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Item1/*'/>
Expand Down Expand Up @@ -79,6 +83,8 @@ public sealed class SqlClientCommandError : System.Collections.Generic.IReadOnly
public SqlCommand Command => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandError"]/Exception/*'/>
public System.Exception Exception { get; }
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandError"]/BatchCommands/*'/>
public System.Collections.Generic.IReadOnlyList<SqlBatchCommand> BatchCommands => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Count/*'/>
public int Count => throw null;
/// <include file='../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Item1/*'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ internal SqlClientCommandAfter(
Guid? connectionId,
long? transactionId,
SqlCommand command,
IDictionary statistics)
IDictionary statistics,
IReadOnlyList<SqlBatchCommand> batchCommands)
{
OperationId = operationId;
Operation = operation;
Expand All @@ -30,6 +31,7 @@ internal SqlClientCommandAfter(
TransactionId = transactionId;
Command = command;
Statistics = statistics;
BatchCommands = batchCommands;
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/OperationId/*'/>
Expand All @@ -46,9 +48,11 @@ internal SqlClientCommandAfter(
public SqlCommand Command { get; }
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandAfter"]/Statistics/*'/>
public IDictionary Statistics { get; }
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandAfter"]/BatchCommands/*'/>
public IReadOnlyList<SqlBatchCommand> BatchCommands { get; }

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Count/*'/>
public int Count => 3 + 4;
public int Count => 3 + 5;

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Item1/*'/>
public KeyValuePair<string, object> this[int index]
Expand All @@ -62,6 +66,7 @@ public KeyValuePair<string, object> this[int index]
4 => new KeyValuePair<string, object>(nameof(TransactionId), TransactionId),
5 => new KeyValuePair<string, object>(nameof(Command), Command),
6 => new KeyValuePair<string, object>(nameof(Statistics), Statistics),
7 => new KeyValuePair<string, object>(nameof(BatchCommands), BatchCommands),
_ => throw new IndexOutOfRangeException(nameof(index)),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ internal SqlClientCommandBefore(
long timestamp,
Guid? connectionId,
long? transactionId,
SqlCommand command)
SqlCommand command,
IReadOnlyList<SqlBatchCommand> batchCommands)
{
OperationId = operationId;
Operation = operation;
Timestamp = timestamp;
ConnectionId = connectionId;
TransactionId = transactionId;
Command = command;
BatchCommands = batchCommands;
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/OperationId/*'/>
Expand All @@ -42,9 +44,11 @@ internal SqlClientCommandBefore(
public long? TransactionId { get; }
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandBefore"]/Command/*'/>
public SqlCommand Command { get; }
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandBefore"]/BatchCommands/*'/>
public IReadOnlyList<SqlBatchCommand> BatchCommands { get; }

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Count/*'/>
public int Count => 3 + 3;
public int Count => 3 + 4;

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Item1/*'/>
public KeyValuePair<string, object> this[int index]
Expand All @@ -57,6 +61,7 @@ public KeyValuePair<string, object> this[int index]
3 => new KeyValuePair<string, object>(nameof(ConnectionId), ConnectionId),
4 => new KeyValuePair<string, object>(nameof(TransactionId), TransactionId),
5 => new KeyValuePair<string, object>(nameof(Command), Command),
6 => new KeyValuePair<string, object>(nameof(BatchCommands), BatchCommands),
_ => throw new IndexOutOfRangeException(nameof(index)),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ internal SqlClientCommandError(
Guid? connectionId,
long? transactionId,
SqlCommand command,
Exception exception)
Exception exception,
IReadOnlyList<SqlBatchCommand> batchCommands)
{
OperationId = operationId;
Operation = operation;
Expand All @@ -31,6 +32,7 @@ internal SqlClientCommandError(
TransactionId = transactionId;
Command = command;
Exception = exception;
BatchCommands = batchCommands;
}
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/OperationId/*'/>
public Guid OperationId { get; }
Expand All @@ -46,9 +48,11 @@ internal SqlClientCommandError(
public SqlCommand Command { get; }
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandError"]/Exception/*'/>
public Exception Exception { get; }
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientCommandError"]/BatchCommands/*'/>
public IReadOnlyList<SqlBatchCommand> BatchCommands { get; }

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Count/*'/>
public int Count => 3 + 4;
public int Count => 3 + 5;

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientDiagnostic.xml' path='docs/members[@name="SqlClientDiagnostic"]/Item1/*'/>
public KeyValuePair<string, object> this[int index]
Expand All @@ -62,6 +66,7 @@ public KeyValuePair<string, object> this[int index]
4 => new KeyValuePair<string, object>(nameof(TransactionId), TransactionId),
5 => new KeyValuePair<string, object>(nameof(Command), Command),
6 => new KeyValuePair<string, object>(nameof(Exception), Exception),
7 => new KeyValuePair<string, object>(nameof(BatchCommands), BatchCommands),
_ => throw new IndexOutOfRangeException(nameof(index)),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void WriteCommandAfter(
sqlCommand.Connection?.ClientConnectionId,
transaction?.InternalTransaction?.TransactionId,
sqlCommand,
sqlCommand.Statistics?.GetDictionary()
sqlCommand.Statistics?.GetDictionary(),
sqlCommand.BatchCommands
)
);
}
Expand All @@ -112,7 +113,8 @@ public Guid WriteCommandBefore(
Stopwatch.GetTimestamp(),
sqlCommand.Connection?.ClientConnectionId,
transaction?.InternalTransaction?.TransactionId,
sqlCommand
sqlCommand,
sqlCommand.BatchCommands
)
);

Expand Down Expand Up @@ -142,7 +144,8 @@ public void WriteCommandError(
sqlCommand.Connection?.ClientConnectionId,
transaction?.InternalTransaction?.TransactionId,
sqlCommand,
ex
ex,
sqlCommand.BatchCommands
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.Common;
using System.Threading;
Expand All @@ -23,6 +24,7 @@ public class SqlBatch :
private SqlCommand _batchCommand;
private List<SqlBatchCommand> _commands;
private SqlBatchCommandCollection _providerCommands;
private ReadOnlyCollection<SqlBatchCommand> _readOnlyCommands;

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ctor1/*'/>
public SqlBatch()
Expand Down Expand Up @@ -213,6 +215,7 @@ void Dispose()
_batchCommand = null;
_commands?.Clear();
_commands = null;
_readOnlyCommands = null;
#if NET
base.Dispose();
#endif
Expand Down Expand Up @@ -355,6 +358,9 @@ private void SetupBatchCommandExecute()
}
_batchCommand.Connection = Connection;
_batchCommand.Transaction = Transaction;
// Surfaced on the command diagnostic payloads. The wrapper is a view over _commands,
// which is never reassigned while the batch is usable, so it is allocated once.
_batchCommand.BatchCommands = _readOnlyCommands != null ? _readOnlyCommands : _readOnlyCommands = new ReadOnlyCollection<SqlBatchCommand>(_commands);
_batchCommand.SetBatchRPCMode(true, _commands.Count);
_batchCommand.Parameters.Clear();
for (int index = 0; index < _commands.Count; index++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ namespace Microsoft.Data.SqlClient
// @TODO: There's a good question here - should this be a separate type of SqlCommand?
public sealed partial class SqlCommand
{
#region Internal Properties

/// <summary>
/// The commands of the <see cref="SqlBatch"/> this command is executing on behalf of, or
/// <see langword="null" /> when it is not executing on behalf of a batch. Set by
/// <see cref="SqlBatch"/> before each execution and surfaced on the command diagnostic
/// payloads.
/// </summary>
internal IReadOnlyList<SqlBatchCommand> BatchCommands { get; set; }

#endregion

#region Internal Methods

internal void AddBatchCommand(SqlBatchCommand batchCommand)
Expand Down
Loading
Loading