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

Add | Feature: SqlBatch api #1825

Merged
merged 23 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ac1bc4d
netcore ref assembly changes
Wraith2 Oct 22, 2022
a2a70c7
initial implementation of batching api
Wraith2 Aug 15, 2023
6f232fd
working implementation and passing tests
Wraith2 Nov 3, 2022
ce54e14
sync ref and move to shared. address review feedback.
Wraith2 Nov 4, 2022
3f9105a
rename SqlException.SqlBatchCommand to BatchCommand
Wraith2 Nov 4, 2022
523085a
various fixes
Wraith2 Nov 4, 2022
7601228
add explicit dependency versions for netfx
Wraith2 Aug 15, 2023
2b96381
fix rebase change
Wraith2 Nov 17, 2022
a646ca7
limit to net6 and later
Wraith2 Aug 15, 2023
49b13a1
rename namespace to avoid clashes and make tests netcore only
Wraith2 Aug 15, 2023
4fc1661
fix reflection SqlError creation test
Wraith2 Aug 16, 2023
b185d8c
raise exception directly in test
Wraith2 Aug 16, 2023
f74c9e8
add net8 support for new batch command functions
Wraith2 Aug 16, 2023
74767ab
change SqlException to keep old Create signatures and disambiguate ca…
Wraith2 Aug 28, 2023
0aab8a7
split SqlError constructors
Wraith2 Aug 29, 2023
f0e8de2
add doc comments files and placeholders
Wraith2 Aug 31, 2023
358ffbd
fill in documentation todos
Wraith2 Oct 29, 2023
f86c2c5
address feedback
Wraith2 Oct 30, 2023
d4adde8
remove public netfx types
Wraith2 Nov 1, 2023
7e7a722
Merge branch 'main' of https://github.com/dotnet/SqlClient into api-b…
David-Engel Nov 2, 2023
eaad4ab
Remove unused version props
David-Engel Nov 2, 2023
8b117d1
Remove stray spaces
David-Engel Nov 2, 2023
b749474
Add samples/SqlBatch_ExecuteReader.cs to API doc snippets
David-Engel Nov 3, 2023
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
46 changes: 46 additions & 0 deletions doc/samples/SqlBatch_ExecuteReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// <Snippet1>
using Microsoft.Data.SqlClient;

class Program
{
static void Main()
{
string str = "Data Source=(local);Initial Catalog=Northwind;"
+ "Integrated Security=SSPI;Encrypt=False";
RunBatch(str);
}

static void RunBatch(string connString)
{
using var connection = new SqlConnection(connString);
connection.Open();

var batch = new SqlBatch(connection);

const int count = 10;
const string parameterName = "parameter";
for (int i = 0; i < count; i++)
{
var batchCommand = new SqlBatchCommand($"SELECT @{parameterName} as value");
batchCommand.Parameters.Add(new SqlParameter(parameterName, i));
batch.BatchCommands.Add(batchCommand);
}

// Optionally Prepare
batch.Prepare();

var results = new List<int>(count);
using (SqlDataReader reader = batch.ExecuteReader())
{
do
{
while (reader.Read())
{
results.Add(reader.GetFieldValue<int>(0));
}
} while (reader.NextResult());
}
Console.WriteLine(string.Join(", ", results));
}
}
// </Snippet1>
651 changes: 651 additions & 0 deletions doc/snippets/Microsoft.Data.Common/DbBatch.xml

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions doc/snippets/Microsoft.Data.Common/DbBatchCommand.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<Type Name="DbBatchCommand" FullName="System.Data.Common.DbBatchCommand">
<TypeSignature Language="C#" Value="public abstract class DbBatchCommand" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class DbBatchCommand" />
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(0)]</AttributeName>
<AttributeName Language="F#">[&lt;System.Runtime.CompilerServices.Nullable(0)&gt;]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="net-8.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[&lt;System.Runtime.CompilerServices.NullableContext(1)&gt;]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>
Represents a single command within a <see cref="T:System.Data.Common.DbBatch" />. A batch can be executed against a data source in a single round trip.
</summary>
<remarks>To be added.</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected DbBatchCommand ();" />
<MemberSignature Language="VB.NET" Value="Protected Sub New ()" />
<MemberType>Constructor</MemberType>
<Parameters />
<Docs>
<summary>
Constructs an instance of the <see cref="T:System.Data.Common.DbBatchCommand" /> object.
</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="CommandText">
<MemberSignature Language="C#" Value="public abstract string CommandText { get; set; }" />
<MemberSignature Language="VB.NET" Value="Public MustOverride Property CommandText As String" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the text command to run against the data source.</summary>
<value>The text command to execute. The default value is an empty string ("").</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="CommandType">
<MemberSignature Language="C#" Value="public abstract System.Data.CommandType CommandType { get; set; }" />
<MemberSignature Language="VB.NET" Value="Public MustOverride Property CommandType As CommandType" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>System.Data.CommandType</ReturnType>
</ReturnValue>
<Docs>
<summary>
Gets or sets how the <see cref="P:System.Data.Common.DbBatchCommand.CommandText" /> property is interpreted.
</summary>
<value>
One of the enumeration values that specifies how a command string is interpreted. The default is <see langword="Text" />.
</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="DbParameterCollection">
<MemberSignature Language="C#" Value="protected abstract System.Data.Common.DbParameterCollection DbParameterCollection { get; }" />
<MemberSignature Language="VB.NET" Value="Protected MustOverride ReadOnly Property DbParameterCollection As DbParameterCollection" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>System.Data.Common.DbParameterCollection</ReturnType>
</ReturnValue>
<Docs>
<summary>
Gets the collection of <see cref="T:System.Data.Common.DbParameter" /> objects.
</summary>
<value>The parameters of the SQL statement or stored procedure.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Parameters">
<MemberSignature Language="C#" Value="public System.Data.Common.DbParameterCollection Parameters { get; }" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Parameters As DbParameterCollection" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>System.Data.Common.DbParameterCollection</ReturnType>
</ReturnValue>
<Docs>
<summary>
Gets the collection of <see cref="T:System.Data.Common.DbParameter" /> objects. For more information on parameters, see [Configuring Parameters and Parameter Data Types](/dotnet/framework/data/adonet/configuring-parameters-and-parameter-data-types).
</summary>
<value>The parameters of the SQL statement or stored procedure.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="RecordsAffected">
<MemberSignature Language="C#" Value="public abstract int RecordsAffected { get; }" />
<MemberSignature Language="VB.NET" Value="Public MustOverride ReadOnly Property RecordsAffected As Integer" />
<MemberType>Property</MemberType>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>
Gets the number of rows changed, inserted, or deleted by execution of this specific <see cref="T:System.Data.Common.DbBatchCommand" />.
</summary>
<value>The number of rows changed, inserted, or deleted. -1 for SELECT statements; 0 if no rows were affected or the statement failed.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>