Skip to content

Commit 7d5ece2

Browse files
authored
Implement CreateParameter for DbBatchCommand (#5300)
Closes #5179
1 parent 95b7a45 commit 7d5ece2

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/Npgsql/NpgsqlBatchCommand.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ public override string CommandText
3838
/// <inheritdoc cref="DbBatchCommand.Parameters"/>
3939
public new NpgsqlParameterCollection Parameters { get; } = new();
4040

41+
#pragma warning disable CA1822 // Mark members as static
42+
43+
#if NET8_0_OR_GREATER
44+
/// <inheritdoc/>
45+
public override NpgsqlParameter CreateParameter()
46+
#else
47+
/// <summary>
48+
/// Creates a new instance of a <see cref="NpgsqlParameter"/> object.
49+
/// </summary>
50+
/// <returns>An <see cref="NpgsqlParameter"/> object.</returns>
51+
public NpgsqlParameter CreateParameter()
52+
#endif
53+
=> new();
54+
55+
#if NET8_0_OR_GREATER
56+
/// <inheritdoc/>
57+
public override bool CanCreateParameter
58+
#else
59+
/// <summary>
60+
/// Returns whether the <see cref="NpgsqlBatchCommand.CreateParameter"/> method is implemented.
61+
/// </summary>
62+
public bool CanCreateParameter
63+
#endif
64+
=> true;
65+
66+
#pragma warning restore CA1822 // Mark members as static
67+
4168
/// <summary>
4269
/// Appends an error barrier after this batch command. Defaults to the value of <see cref="NpgsqlBatch.EnableErrorBarriers" /> on the
4370
/// batch.

src/Npgsql/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#nullable enable
1+
#nullable enable
22
const Npgsql.PostgresErrorCodes.IdleSessionTimeout = "57P05" -> string!
33
Npgsql.ChannelBinding
44
Npgsql.ChannelBinding.Disable = 0 -> Npgsql.ChannelBinding
@@ -104,6 +104,8 @@ override Npgsql.NpgsqlBatch.Dispose() -> void
104104
*REMOVED*Npgsql.Replication.PhysicalReplicationConnection.StartReplication(NpgsqlTypes.NpgsqlLogSequenceNumber walLocation, System.Threading.CancellationToken cancellationToken, ulong timeline = 0) -> System.Collections.Generic.IAsyncEnumerable<Npgsql.Replication.XLogDataMessage!>!
105105
*REMOVED*Npgsql.Replication.PhysicalReplicationSlot.PhysicalReplicationSlot(string! slotName, NpgsqlTypes.NpgsqlLogSequenceNumber? restartLsn = null, ulong? restartTimeline = null) -> void
106106
*REMOVED*Npgsql.Replication.PhysicalReplicationSlot.RestartTimeline.get -> ulong?
107+
override Npgsql.NpgsqlBatchCommand.CanCreateParameter.get -> bool
108+
override Npgsql.NpgsqlBatchCommand.CreateParameter() -> Npgsql.NpgsqlParameter!
107109
override NpgsqlTypes.NpgsqlCidr.ToString() -> string!
108110
*REMOVED*static NpgsqlTypes.NpgsqlInet.operator !=(NpgsqlTypes.NpgsqlInet x, NpgsqlTypes.NpgsqlInet y) -> bool
109111
*REMOVED*static NpgsqlTypes.NpgsqlInet.operator ==(NpgsqlTypes.NpgsqlInet x, NpgsqlTypes.NpgsqlInet y) -> bool

test/Npgsql.Tests/BatchTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ public async Task StatementOID()
288288
Assert.That(batch.BatchCommands[1].OID, Is.EqualTo(0));
289289
}
290290

291+
[Test]
292+
public void CanCreateParameter() => Assert.True(new NpgsqlBatchCommand().CanCreateParameter);
293+
294+
[Test]
295+
public void CreateParameter() => Assert.NotNull(new NpgsqlBatchCommand().CreateParameter());
296+
291297
#endregion NpgsqlBatchCommand
292298

293299
#region Command behaviors

0 commit comments

Comments
 (0)