Skip to content
Merged
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
173 changes: 163 additions & 10 deletions src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.cs
Comment thread
paulmedynski marked this conversation as resolved.

Large diffs are not rendered by default.

170 changes: 140 additions & 30 deletions src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBatch.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if NET

using System;
using System.Collections.Generic;
using System.Data;
Expand All @@ -15,7 +13,12 @@
namespace Microsoft.Data.SqlClient
{
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/SqlBatch/*'/>
public class SqlBatch : DbBatch
public class SqlBatch :
#if NET
DbBatch
#else
IDisposable, IAsyncDisposable
#endif
{
private SqlCommand _batchCommand;
private List<SqlBatchCommand> _commands;
Expand All @@ -33,8 +36,30 @@ public SqlBatch(SqlConnection connection = null, SqlTransaction transaction = nu
Connection = connection;
Transaction = transaction;
}

#if NET
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbBatchCommands/*'/>
protected override DbBatchCommandCollection DbBatchCommands => BatchCommands;

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/CreateDbBatchCommand/*'/>
protected override DbBatchCommand CreateDbBatchCommand() => new SqlBatchCommand();
#endif

#if NETFRAMEWORK
/// <inheritdoc cref="System.IAsyncDisposable.DisposeAsync"/>
public virtual ValueTask DisposeAsync()
{
Dispose();
return default;
}
#endif

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Timeout/*'/>
public override int Timeout
public
#if NET
override
#endif
int Timeout
{
get
{
Expand All @@ -47,12 +72,22 @@ public override int Timeout
_batchCommand.CommandTimeout = value;
}
}
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbBatchCommands/*'/>
protected override DbBatchCommandCollection DbBatchCommands => BatchCommands;

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/BatchCommands/*'/>
public new SqlBatchCommandCollection BatchCommands => _providerCommands != null ? _providerCommands : _providerCommands = new SqlBatchCommandCollection(Commands); // Commands call will check disposed
public
#if NET
new
#endif
SqlBatchCommandCollection BatchCommands => _providerCommands != null ? _providerCommands : _providerCommands = new SqlBatchCommandCollection(Commands); // Commands call will check disposed

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbConnection/*'/>
protected override DbConnection DbConnection
protected
#if NET
override
#else
virtual
#endif
DbConnection DbConnection
{
get
{
Expand All @@ -65,8 +100,15 @@ protected override DbConnection DbConnection
Connection = (SqlConnection)value;
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/DbTransaction/*'/>
protected override DbTransaction DbTransaction
protected
#if NET
override
#else
virtual
#endif
DbTransaction DbTransaction
{
get
{
Expand All @@ -79,60 +121,103 @@ protected override DbTransaction DbTransaction
Transaction = (SqlTransaction)value;
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Cancel/*'/>
public override void Cancel()
public
#if NET
override
#endif
void Cancel()
{
CheckDisposed();
_batchCommand.Cancel();
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteNonQuery/*'/>
public override int ExecuteNonQuery()
public
#if NET
override
#endif
int ExecuteNonQuery()
{
CheckDisposed();
SetupBatchCommandExecute();
return _batchCommand.ExecuteNonQuery();
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteNonQueryAsync/*'/>
public override Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken = default)
public
#if NET
override
#endif
Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken = default)
{
CheckDisposed();
SetupBatchCommandExecute();
return _batchCommand.ExecuteNonQueryAsync(cancellationToken);
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteScalar/*'/>
public override object ExecuteScalar()
public
#if NET
override
#endif
object ExecuteScalar()
{
CheckDisposed();
SetupBatchCommandExecute();
return _batchCommand.ExecuteScalar();
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteScalarAsync/*'/>
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken = default)
public
#if NET
override
#endif
Task<object> ExecuteScalarAsync(CancellationToken cancellationToken = default)
{
CheckDisposed();
SetupBatchCommandExecute();
return _batchCommand.ExecuteScalarBatchAsync(cancellationToken);
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Prepare/*'/>
public override void Prepare()
public
#if NET
override
#endif
void Prepare()
{
CheckDisposed();
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/PrepareAsync/*'/>
public override Task PrepareAsync(CancellationToken cancellationToken = default)
public
#if NET
override
#endif
Task PrepareAsync(CancellationToken cancellationToken = default)
{
CheckDisposed();
return Task.CompletedTask;
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Dispose/*'/>
public override void Dispose()
public
#if NET
override
#endif
void Dispose()
{
_batchCommand?.Dispose();
_batchCommand = null;
_commands?.Clear();
_commands = null;
#if NET
base.Dispose();
#endif
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Commands/*'/>
public List<SqlBatchCommand> Commands
{
Expand All @@ -142,8 +227,13 @@ public List<SqlBatchCommand> Commands
return _commands != null ? _commands : _commands = new List<SqlBatchCommand>();
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Connection/*'/>
public new SqlConnection Connection
public
#if NET
new
#endif
SqlConnection Connection
{
get
{
Expand All @@ -156,8 +246,13 @@ public List<SqlBatchCommand> Commands
_batchCommand.Connection = value;
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/Transaction/*'/>
public new SqlTransaction Transaction
public
#if NET
new
#endif
SqlTransaction Transaction
{
get
{
Expand All @@ -170,24 +265,44 @@ public List<SqlBatchCommand> Commands
_batchCommand.Transaction = value;
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteReader/*'/>
public SqlDataReader ExecuteReader()
{
CheckDisposed();
SetupBatchCommandExecute();
return _batchCommand.ExecuteReader();
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteReaderAsync/*'/>
public new Task<SqlDataReader> ExecuteReaderAsync(CancellationToken cancellationToken = default)
public
#if NET
new
#endif
Task<SqlDataReader> ExecuteReaderAsync(CancellationToken cancellationToken = default)
{
CheckDisposed();
SetupBatchCommandExecute();
return _batchCommand.ExecuteReaderAsync(cancellationToken);
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteDbDataReader/*'/>
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) => ExecuteReader();
protected
#if NET
override
#else
virtual
#endif
DbDataReader ExecuteDbDataReader(CommandBehavior behavior) => ExecuteReader();

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/ExecuteDbDataReaderAsync/*'/>
protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
protected
#if NET
override
#else
virtual
#endif
Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
{
CheckDisposed();
SetupBatchCommandExecute();
Expand All @@ -204,19 +319,16 @@ protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior b
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled,
TaskScheduler.Default
);
}
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBatch.xml' path='docs/members[@name="SqlBatch"]/CreateDbBatchCommand/*'/>
protected override DbBatchCommand CreateDbBatchCommand()
{
return new SqlBatchCommand();
}

private void CheckDisposed()
{
if (_batchCommand is null)
{
throw ADP.ObjectDisposed(this);
}
}

private void SetupBatchCommandExecute()
{
SqlConnection connection = Connection;
Expand All @@ -240,5 +352,3 @@ private void SetupBatchCommandExecute()
}
}
}

#endif
Loading
Loading