Skip to content

Commit b59005e

Browse files
committed
Fix null check and iterate over StructuredData rows
Ensure `context.StructuredData` is checked for null before iteration. Update the logic to process each row with a new `NpgsqlCommand` and improve logging to safely access the `Count` property. #6
1 parent 3558258 commit b59005e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/PostgreSqlPlugin.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,17 @@ private async Task ExecuteStructuredDataAsync(
151151
{
152152
int totalAffected = 0;
153153

154-
foreach (var row in context.StructuredData)
154+
if (context.StructuredData is not null)
155155
{
156-
await using var cmd = new NpgsqlCommand(sql, connection);
157-
AddParameters(cmd, row);
158-
totalAffected += await cmd.ExecuteNonQueryAsync(token);
156+
foreach (var row in context.StructuredData)
157+
{
158+
await using var cmd = new NpgsqlCommand(sql, connection);
159+
AddParameters(cmd, row);
160+
totalAffected += await cmd.ExecuteNonQueryAsync(token);
161+
}
159162
}
160163

161-
_logger?.LogInfo($"Executed structured SQL for {context.StructuredData.Count} rows. Total affected: {totalAffected}");
164+
_logger?.LogInfo($"Executed structured SQL for {context.StructuredData?.Count} rows. Total affected: {totalAffected}");
162165
}
163166

164167
private async Task ExecuteSingleNonQueryAsync(

0 commit comments

Comments
 (0)