Skip to content

Commit 5ac8708

Browse files
committed
Added EnsureSuccess to FbBatchNonQueryResult.
1 parent 2d6f258 commit 5ac8708

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ public async Task BigBatch()
289289
Assert.IsTrue(result.AllSuccess);
290290
}
291291
}
292+
[Test]
293+
public async Task EnsureSuccess()
294+
{
295+
await EmptyTable();
296+
297+
await using (var cmd = Connection.CreateBatchCommand())
298+
{
299+
cmd.CommandText = "insert into batch (i) values (@i)";
300+
var batch1 = cmd.AddBatchParameters();
301+
batch1.Add("i", 2000);
302+
var result = await cmd.ExecuteNonQueryAsync();
303+
304+
Assert.Throws<FbException>(result.EnsureSuccess);
305+
}
306+
}
292307

293308
async Task EmptyTable()
294309
{

src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbBatchNonQueryResult.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ internal FbBatchNonQueryResult(ExecuteResultItem[] result)
4949

5050
public FbBatchNonQueryResultItem this[int index] => _items[index];
5151

52+
public void EnsureSuccess()
53+
{
54+
var indexes = _items.Where(x => !x.IsSuccess).Select((_, i) => i).ToList();
55+
if (indexes.Count == 0)
56+
return;
57+
throw FbException.Create($"Indexes {string.Join(", ", indexes)} failed in batch.");
58+
}
59+
5260
public IEnumerator<FbBatchNonQueryResultItem> GetEnumerator() => _items.GetEnumerator();
5361

5462
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

0 commit comments

Comments
 (0)