Skip to content

Commit 360b1cd

Browse files
committed
Better method name.
1 parent 61f8a88 commit 360b1cd

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/FirebirdSql.Data.FirebirdClient.Tests/FbBatchCommandTests.cs

+33-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
using System;
1919
using System.Collections.Generic;
20+
using System.Linq;
2021
using System.Numerics;
2122
using System.Threading.Tasks;
2223
using FirebirdSql.Data.TestsBase;
@@ -273,7 +274,7 @@ public async Task BigBatch()
273274
{
274275
await EmptyTable();
275276

276-
const int Size = 60000;
277+
const int Size = 100_000;
277278

278279
await using (var cmd = Connection.CreateBatchCommand())
279280
{
@@ -322,6 +323,37 @@ public async Task EnsureSuccessNoThrow()
322323
}
323324
}
324325

326+
[Test]
327+
public async Task BatchSizeDynamicHandling()
328+
{
329+
await EmptyTable();
330+
331+
using (var cmd = Connection.CreateBatchCommand())
332+
{
333+
// something silly small
334+
cmd.BatchBufferSize = 32 * 1024;
335+
cmd.CommandText = "insert into batch (i) values (@i)";
336+
await cmd.PrepareAsync();
337+
for (var i = 0; i < 10_000; i++)
338+
{
339+
var bp = cmd.AddBatchParameters();
340+
bp.Add("i", 66);
341+
342+
if (await cmd.ComputeCurrentBatchSizeAsync() > cmd.BatchBufferSize)
343+
{
344+
var last = cmd.BatchParameters[^1];
345+
cmd.BatchParameters.Remove(last);
346+
var result = await cmd.ExecuteNonQueryAsync();
347+
Assert.DoesNotThrow(result.EnsureSuccess);
348+
cmd.BatchParameters.Clear();
349+
cmd.BatchParameters.Add(last);
350+
}
351+
}
352+
var result2 = await cmd.ExecuteNonQueryAsync();
353+
Assert.DoesNotThrow(result2.EnsureSuccess);
354+
}
355+
}
356+
325357
async Task EmptyTable()
326358
{
327359
await using (var cmd = Connection.CreateCommand())

src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbBatchCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public Task<string> GetCommandExplainedPlanAsync(CancellationToken cancellationT
552552
return _statement.GetExecutionExplainedPlanAsync(cancellationToken).AsTask();
553553
}
554554

555-
public int GetCurrentBatchSize()
555+
public int ComputeCurrentBatchSize()
556556
{
557557
if (_batch == null)
558558
{
@@ -564,7 +564,7 @@ public int GetCurrentBatchSize()
564564
}
565565
return _batch.ComputeBatchSize(_batchParameters.Count, this);
566566
}
567-
public async Task<int> GetCurrentBatchSizeAsync(CancellationToken cancellationToken = default)
567+
public async Task<int> ComputeCurrentBatchSizeAsync(CancellationToken cancellationToken = default)
568568
{
569569
if (_batch == null)
570570
{

0 commit comments

Comments
 (0)