Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlBatch: Add missing overrides and tests #2223

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,14 @@ public override DataTable GetSchema(string collectionName, string[] restrictionV
return InnerConnection.GetSchema(ConnectionFactory, PoolGroup, this, collectionName, restrictionValues);
}

#if NET6_0_OR_GREATER
/// <inheritdoc />
public override bool CanCreateBatch => true;

/// <inheritdoc />
protected override DbBatch CreateDbBatch() => new SqlBatch(this);
#endif

private class OpenAsyncRetry
{
private SqlConnection _parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
public static class BatchTests
{
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
Wraith2 marked this conversation as resolved.
Show resolved Hide resolved
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public static void MissingCommandTextThrows()
{
Expand All @@ -33,6 +34,48 @@ public static void MissingConnectionThrows()
}
}

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public static void ConnectionCanCreateBatch()
{
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
Assert.True(connection.CanCreateBatch);
using (var batch = connection.CreateBatch())
{
Assert.NotNull(batch);
Assert.Equal(connection, batch.Connection);

batch.BatchCommands.Add(new SqlBatchCommand("SELECT @@SPID"));
connection.Open();
batch.ExecuteNonQuery();
}
}
}

#if NET8_0_OR_GREATER
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public static void SqlBatchCanCreateParameter()
{
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
using (var batch = connection.CreateBatch())
{
SqlBatchCommand batchCommand = new SqlBatchCommand("SELECT @p");

Assert.True(batchCommand.CanCreateParameter);
SqlParameter parameter = batchCommand.CreateParameter();
Assert.NotNull(parameter);
parameter.ParameterName = "@p";
parameter.Value = 1;
batchCommand.Parameters.Add(parameter);

batch.ExecuteNonQuery();

}
}
#endif

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
public static void StoredProcedureBatchSupported()
Expand Down