diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index a4bc1f651f202b..1bec60c93e3511 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -1919,6 +1919,56 @@ public void RemoveAt(string sourceTable) { } System.Data.ITableMapping System.Data.ITableMappingCollection.Add(string sourceTableName, string dataSetTableName) { throw null; } System.Data.ITableMapping System.Data.ITableMappingCollection.GetByDataSetTable(string dataSetTableName) { throw null; } } + public abstract class DbBatch : System.IDisposable, System.IAsyncDisposable + { + public System.Data.Common.DbBatchCommandCollection BatchCommands { get { throw null; } } + protected abstract System.Data.Common.DbBatchCommandCollection DbBatchCommands { get; } + public abstract int Timeout { get; set; } + public System.Data.Common.DbConnection? Connection { get; set; } + protected abstract System.Data.Common.DbConnection? DbConnection { get; set; } + public System.Data.Common.DbTransaction? Transaction { get; set; } + protected abstract System.Data.Common.DbTransaction? DbTransaction { get; set; } + public System.Data.Common.DbDataReader ExecuteReader(System.Data.CommandBehavior behavior = System.Data.CommandBehavior.Default) { throw null; } + protected abstract System.Data.Common.DbDataReader ExecuteDbDataReader(System.Data.CommandBehavior behavior); + public System.Threading.Tasks.Task ExecuteReaderAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; } + public System.Threading.Tasks.Task ExecuteReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken = default) { throw null; } + protected abstract System.Threading.Tasks.Task ExecuteDbDataReaderAsync(System.Data.CommandBehavior behavior, System.Threading.CancellationToken cancellationToken); + public abstract int ExecuteNonQuery(); + public abstract System.Threading.Tasks.Task ExecuteNonQueryAsync(System.Threading.CancellationToken cancellationToken = default); + public abstract object? ExecuteScalar(); + public abstract System.Threading.Tasks.Task ExecuteScalarAsync(System.Threading.CancellationToken cancellationToken = default); + public abstract void Prepare(); + public abstract System.Threading.Tasks.Task PrepareAsync(System.Threading.CancellationToken cancellationToken = default); + public abstract void Cancel(); + public System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; } + protected abstract System.Data.Common.DbBatchCommand CreateDbBatchCommand(); + public virtual void Dispose() { throw null; } + public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } + } + public abstract class DbBatchCommand + { + public abstract string CommandText { get; set; } + public abstract CommandType CommandType { get; set; } + public abstract int RecordsAffected { get; } + public DbParameterCollection Parameters { get { throw null; } } + protected abstract DbParameterCollection DbParameterCollection { get; } + } + public abstract class DbBatchCommandCollection : System.Collections.Generic.IList + { + public abstract System.Collections.Generic.IEnumerator GetEnumerator(); + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + public abstract void Add(System.Data.Common.DbBatchCommand item); + public abstract void Clear(); + public abstract bool Contains(System.Data.Common.DbBatchCommand item); + public abstract void CopyTo(System.Data.Common.DbBatchCommand[] array, int arrayIndex); + public abstract bool Remove(System.Data.Common.DbBatchCommand item); + public abstract int Count { get; } + public abstract bool IsReadOnly { get; } + public abstract int IndexOf(DbBatchCommand item); + public abstract void Insert(int index, DbBatchCommand item); + public abstract void RemoveAt(int index); + public abstract DbBatchCommand this[int index] { get; set; } + } public abstract partial class DbColumn { protected DbColumn() { } @@ -2077,6 +2127,9 @@ public virtual event System.Data.StateChangeEventHandler? StateChange { add { } public virtual System.Threading.Tasks.Task ChangeDatabaseAsync(string databaseName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public abstract void Close(); public virtual System.Threading.Tasks.Task CloseAsync() { throw null; } + public virtual bool CanCreateBatch { get { throw null; } } + public System.Data.Common.DbBatch CreateBatch() { throw null; } + protected virtual System.Data.Common.DbBatch CreateDbBatch() { throw null; } public System.Data.Common.DbCommand CreateCommand() { throw null; } protected abstract System.Data.Common.DbCommand CreateDbCommand(); public virtual System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } @@ -2367,6 +2420,8 @@ protected DbException(string? message, System.Exception? innerException) { } protected DbException(string? message, int errorCode) { } public virtual bool IsTransient { get { throw null; } } public virtual string? SqlState { get { throw null; } } + public System.Data.Common.DbBatchCommand? BatchCommand { get { throw null; } } + protected virtual System.Data.Common.DbBatchCommand? DbBatchCommand { get { throw null; } } } public static partial class DbMetaDataCollectionNames { @@ -2528,9 +2583,12 @@ public static void RegisterFactory(string providerInvariantName, [System.Diagnos public abstract partial class DbProviderFactory { protected DbProviderFactory() { } + public virtual bool CanCreateBatch { get { throw null; } } public virtual bool CanCreateCommandBuilder { get { throw null; } } public virtual bool CanCreateDataAdapter { get { throw null; } } public virtual bool CanCreateDataSourceEnumerator { get { throw null; } } + public virtual System.Data.Common.DbBatch CreateBatch() { throw null; } + public virtual System.Data.Common.DbBatchCommand CreateBatchCommand() { throw null; } public virtual System.Data.Common.DbCommand? CreateCommand() { throw null; } public virtual System.Data.Common.DbCommandBuilder? CreateCommandBuilder() { throw null; } public virtual System.Data.Common.DbConnection? CreateConnection() { throw null; } diff --git a/src/libraries/System.Data.Common/src/System.Data.Common.csproj b/src/libraries/System.Data.Common/src/System.Data.Common.csproj index 5e445cebc31df6..b836c7f2c8e149 100644 --- a/src/libraries/System.Data.Common/src/System.Data.Common.csproj +++ b/src/libraries/System.Data.Common/src/System.Data.Common.csproj @@ -183,6 +183,9 @@ + + + Component diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs new file mode 100644 index 00000000000000..a3b6e352428ce7 --- /dev/null +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatch.cs @@ -0,0 +1,76 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Threading; +using System.Threading.Tasks; + +namespace System.Data.Common +{ + public abstract class DbBatch : IDisposable, IAsyncDisposable + { + public DbBatchCommandCollection BatchCommands => DbBatchCommands; + + protected abstract DbBatchCommandCollection DbBatchCommands { get; } + + public abstract int Timeout { get; set; } + + public DbConnection? Connection + { + get => DbConnection; + set => DbConnection = value; + } + + protected abstract DbConnection? DbConnection { get; set; } + + public DbTransaction? Transaction + { + get => DbTransaction; + set => DbTransaction = value; + } + + protected abstract DbTransaction? DbTransaction { get; set; } + + public DbDataReader ExecuteReader(CommandBehavior behavior = CommandBehavior.Default) + => ExecuteDbDataReader(behavior); + + protected abstract DbDataReader ExecuteDbDataReader(CommandBehavior behavior); + + public Task ExecuteReaderAsync(CancellationToken cancellationToken = default) + => ExecuteDbDataReaderAsync(CommandBehavior.Default, cancellationToken); + + public Task ExecuteReaderAsync( + CommandBehavior behavior, + CancellationToken cancellationToken = default) + => ExecuteDbDataReaderAsync(behavior, cancellationToken); + + protected abstract Task ExecuteDbDataReaderAsync( + CommandBehavior behavior, + CancellationToken cancellationToken); + + public abstract int ExecuteNonQuery(); + + public abstract Task ExecuteNonQueryAsync(CancellationToken cancellationToken = default); + + public abstract object? ExecuteScalar(); + + public abstract Task ExecuteScalarAsync(CancellationToken cancellationToken = default); + + public abstract void Prepare(); + + public abstract Task PrepareAsync(CancellationToken cancellationToken = default); + + public abstract void Cancel(); + + public DbBatchCommand CreateBatchCommand() => CreateDbBatchCommand(); + + protected abstract DbBatchCommand CreateDbBatchCommand(); + + public virtual void Dispose() {} + + public virtual ValueTask DisposeAsync() + { + Dispose(); + return default; + } + } +} diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs new file mode 100644 index 00000000000000..fa6f306e5aaa0e --- /dev/null +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommand.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; + +namespace System.Data.Common +{ + public abstract class DbBatchCommand + { + public abstract string CommandText { get; set; } + + public abstract CommandType CommandType { get; set; } + + public abstract int RecordsAffected { get; } + + public DbParameterCollection Parameters => DbParameterCollection; + + protected abstract DbParameterCollection DbParameterCollection { get; } + } +} diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs new file mode 100644 index 00000000000000..736cc5cbb093f6 --- /dev/null +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbBatchCommandCollection.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.Collections.Generic; + +namespace System.Data.Common +{ + public abstract class DbBatchCommandCollection : IList + { + public abstract IEnumerator GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public abstract void Add(DbBatchCommand item); + + public abstract void Clear(); + + public abstract bool Contains(DbBatchCommand item); + + public abstract void CopyTo(DbBatchCommand[] array, int arrayIndex); + + public abstract bool Remove(DbBatchCommand item); + + public abstract int Count { get; } + + public abstract bool IsReadOnly { get; } + + public abstract int IndexOf(DbBatchCommand item); + + public abstract void Insert(int index, DbBatchCommand item); + + public abstract void RemoveAt(int index); + + public abstract DbBatchCommand this[int index] { get; set; } + } +} diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs index a749668b456770..d983aad07c71bf 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnection.cs @@ -128,6 +128,12 @@ public virtual Task ChangeDatabaseAsync(string databaseName, CancellationToken c } } + public virtual bool CanCreateBatch => false; + + public DbBatch CreateBatch() => CreateDbBatch(); + + protected virtual DbBatch CreateDbBatch() => throw new NotSupportedException(); + public DbCommand CreateCommand() => CreateDbCommand(); IDbCommand IDbConnection.CreateCommand() => CreateDbCommand(); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs index 25bebd95cd50ae..55b0bce2fddc92 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbException.cs @@ -41,5 +41,9 @@ protected DbException(System.Runtime.Serialization.SerializationInfo info, Syste /// A standard SQL 5-character return code, or . /// public virtual string? SqlState => null; + + public DbBatchCommand? BatchCommand => DbBatchCommand; + + protected virtual DbBatchCommand? DbBatchCommand => null; } } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs index 6065bc6acd8e22..7282338b5407a4 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbProviderFactory.cs @@ -13,6 +13,8 @@ public abstract partial class DbProviderFactory protected DbProviderFactory() { } + public virtual bool CanCreateBatch => false; + public virtual bool CanCreateDataSourceEnumerator => false; public virtual bool CanCreateDataAdapter @@ -47,6 +49,10 @@ public virtual bool CanCreateCommandBuilder } } + public virtual DbBatch CreateBatch() => throw new NotSupportedException(); + + public virtual DbBatchCommand CreateBatchCommand() => throw new NotSupportedException(); + public virtual DbCommand? CreateCommand() => null; public virtual DbCommandBuilder? CreateCommandBuilder() => null;