Skip to content

Commit

Permalink
Unify MySqlBulkCopy API. Fixes #1364
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Sep 3, 2023
1 parent 3d10049 commit 761c1c2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
47 changes: 0 additions & 47 deletions src/MySqlConnector/MySqlBulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public MySqlBulkCopyResult WriteToServer(DataTable dataTable)
#pragma warning restore CA2012
}

#if NETCOREAPP || NETSTANDARD2_0_OR_GREATER
/// <summary>
/// Asynchronously copies all rows in the supplied <see cref="DataTable"/> to the destination table specified by the
/// <see cref="DestinationTableName"/> property of the <see cref="MySqlBulkCopy"/> object.
Expand All @@ -130,20 +129,6 @@ public async ValueTask<MySqlBulkCopyResult> WriteToServerAsync(DataTable dataTab
m_valuesEnumerator = DataRowsValuesEnumerator.Create(dataTable ?? throw new ArgumentNullException(nameof(dataTable)));
return await WriteToServerAsync(IOBehavior.Asynchronous, cancellationToken).ConfigureAwait(false);
}
#else
/// <summary>
/// Asynchronously copies all rows in the supplied <see cref="DataTable"/> to the destination table specified by the
/// <see cref="DestinationTableName"/> property of the <see cref="MySqlBulkCopy"/> object.
/// </summary>
/// <param name="dataTable">The <see cref="DataTable"/> to copy.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>A <see cref="MySqlBulkCopyResult"/> with the result of the bulk copy operation.</returns>
public async Task<MySqlBulkCopyResult> WriteToServerAsync(DataTable dataTable, CancellationToken cancellationToken = default)
{
m_valuesEnumerator = DataRowsValuesEnumerator.Create(dataTable ?? throw new ArgumentNullException(nameof(dataTable)));
return await WriteToServerAsync(IOBehavior.Asynchronous, cancellationToken).ConfigureAwait(false);
}
#endif

/// <summary>
/// Copies all rows in the supplied sequence of <see cref="DataRow"/> objects to the destination table specified by the
Expand All @@ -161,7 +146,6 @@ public MySqlBulkCopyResult WriteToServer(IEnumerable<DataRow> dataRows, int colu
#pragma warning restore CA2012
}

#if NETCOREAPP || NETSTANDARD2_0_OR_GREATER
/// <summary>
/// Asynchronously copies all rows in the supplied sequence of <see cref="DataRow"/> objects to the destination table specified by the
/// <see cref="DestinationTableName"/> property of the <see cref="MySqlBulkCopy"/> object. The number of columns
Expand All @@ -176,22 +160,6 @@ public async ValueTask<MySqlBulkCopyResult> WriteToServerAsync(IEnumerable<DataR
m_valuesEnumerator = new DataRowsValuesEnumerator(dataRows ?? throw new ArgumentNullException(nameof(dataRows)), columnCount);
return await WriteToServerAsync(IOBehavior.Asynchronous, cancellationToken).ConfigureAwait(false);
}
#else
/// <summary>
/// Asynchronously copies all rows in the supplied sequence of <see cref="DataRow"/> objects to the destination table specified by the
/// <see cref="DestinationTableName"/> property of the <see cref="MySqlBulkCopy"/> object. The number of columns
/// to be read from the <see cref="DataRow"/> objects must be specified in advance.
/// </summary>
/// <param name="dataRows">The collection of <see cref="DataRow"/> objects.</param>
/// <param name="columnCount">The number of columns to copy (in each row).</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>A <see cref="MySqlBulkCopyResult"/> with the result of the bulk copy operation.</returns>
public async Task<MySqlBulkCopyResult> WriteToServerAsync(IEnumerable<DataRow> dataRows, int columnCount, CancellationToken cancellationToken = default)
{
m_valuesEnumerator = new DataRowsValuesEnumerator(dataRows ?? throw new ArgumentNullException(nameof(dataRows)), columnCount);
return await WriteToServerAsync(IOBehavior.Asynchronous, cancellationToken).ConfigureAwait(false);
}
#endif

/// <summary>
/// Copies all rows in the supplied <see cref="IDataReader"/> to the destination table specified by the
Expand All @@ -207,7 +175,6 @@ public MySqlBulkCopyResult WriteToServer(IDataReader dataReader)
#pragma warning restore CA2012
}

#if NETCOREAPP || NETSTANDARD2_0_OR_GREATER
/// <summary>
/// Asynchronously copies all rows in the supplied <see cref="IDataReader"/> to the destination table specified by the
/// <see cref="DestinationTableName"/> property of the <see cref="MySqlBulkCopy"/> object.
Expand All @@ -220,20 +187,6 @@ public async ValueTask<MySqlBulkCopyResult> WriteToServerAsync(IDataReader dataR
m_valuesEnumerator = DataReaderValuesEnumerator.Create(dataReader ?? throw new ArgumentNullException(nameof(dataReader)));
return await WriteToServerAsync(IOBehavior.Asynchronous, cancellationToken).ConfigureAwait(false);
}
#else
/// <summary>
/// Asynchronously copies all rows in the supplied <see cref="IDataReader"/> to the destination table specified by the
/// <see cref="DestinationTableName"/> property of the <see cref="MySqlBulkCopy"/> object.
/// </summary>
/// <param name="dataReader">The <see cref="IDataReader"/> to copy from.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>A <see cref="MySqlBulkCopyResult"/> with the result of the bulk copy operation.</returns>
public async Task<MySqlBulkCopyResult> WriteToServerAsync(IDataReader dataReader, CancellationToken cancellationToken = default)
{
m_valuesEnumerator = DataReaderValuesEnumerator.Create(dataReader ?? throw new ArgumentNullException(nameof(dataReader)));
return await WriteToServerAsync(IOBehavior.Asynchronous, cancellationToken).ConfigureAwait(false);
}
#endif

private async ValueTask<MySqlBulkCopyResult> WriteToServerAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
{
Expand Down
12 changes: 1 addition & 11 deletions src/MySqlConnector/MySqlConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ private MySqlConnection(string connectionString, MySqlConnectorLoggingConfigurat
/// <remarks>Transactions may not be nested.</remarks>
public new ValueTask<MySqlTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = default) => BeginTransactionAsync(isolationLevel, default, AsyncIOBehavior, cancellationToken);

/// <summary>
/// Begins a database transaction asynchronously.
/// </summary>
/// <param name="isolationLevel">The <see cref="IsolationLevel"/> for the transaction.</param>
/// <param name="isReadOnly">If <c>true</c>, changes to tables used in the transaction are prohibited; otherwise, they are permitted.</param>
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task{MySqlTransaction}"/> representing the new database transaction.</returns>
/// <remarks>Transactions may not be nested.</remarks>
public ValueTask<MySqlTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, bool isReadOnly, CancellationToken cancellationToken = default) => BeginTransactionAsync(isolationLevel, isReadOnly, AsyncIOBehavior, cancellationToken);

/// <summary>
/// Begins a database transaction asynchronously.
/// </summary>
Expand All @@ -133,6 +123,7 @@ protected override async ValueTask<DbTransaction> BeginDbTransactionAsync(Isolat
/// <returns>A <see cref="Task{MySqlTransaction}"/> representing the new database transaction.</returns>
/// <remarks>Transactions may not be nested.</remarks>
public ValueTask<MySqlTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = default) => BeginTransactionAsync(isolationLevel, default, AsyncIOBehavior, cancellationToken);
#endif

/// <summary>
/// Begins a database transaction asynchronously.
Expand All @@ -143,7 +134,6 @@ protected override async ValueTask<DbTransaction> BeginDbTransactionAsync(Isolat
/// <returns>A <see cref="Task{MySqlTransaction}"/> representing the new database transaction.</returns>
/// <remarks>Transactions may not be nested.</remarks>
public ValueTask<MySqlTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, bool isReadOnly, CancellationToken cancellationToken = default) => BeginTransactionAsync(isolationLevel, isReadOnly, AsyncIOBehavior, cancellationToken);
#endif

private async ValueTask<MySqlTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, bool? isReadOnly, IOBehavior ioBehavior, CancellationToken cancellationToken)
{
Expand Down

0 comments on commit 761c1c2

Please sign in to comment.