Skip to content

Commit fd797d0

Browse files
committed
Document return value of ExecuteNonQuery. Fixes #1136
1 parent 861212f commit fd797d0

File tree

8 files changed

+56
-4
lines changed

8 files changed

+56
-4
lines changed

docs/content/api/MySqlConnector/MySqlCommand/ExecuteNonQuery.md

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlCommand/ExecuteNonQueryAsync.md

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlCommandType.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlDataReader/RecordsAffected.md

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/api/MySqlConnector/MySqlDataReaderType.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/overview/version-history.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ weight: 30
3636

3737
* Fix `Use Compression = True` when running under .NET 6.0: [#1120](https://github.com/mysql-net/MySqlConnector/issues/1120).
3838
* Fix calculation of affected rows (the return value of `ExecuteNonQuery`) for compound statements: [#1096](https://github.com/mysql-net/MySqlConnector/issues/1096).
39+
* **Breaking** For a stored procedure, the return value of `ExecuteNonQuery` will be the number of rows affected by the last statement in the procedure, or zero if the last statement was a `SELECT`.
3940
* Use a better `FormatException` message when a GUID can't be read: [#1114](https://github.com/mysql-net/MySqlConnector/issues/1114).
4041
* Use cryptographic one-shot operations on .NET 5.0 and later.
4142
* Performance: Use `SkipLocalsInit` where possible.

src/MySqlConnector/MySqlCommand.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ private MySqlCommand(MySqlCommand other)
9797
/// <inheritdoc/>
9898
public override void Cancel() => Connection?.Cancel(this, m_commandId, true);
9999

100-
/// <inheritdoc/>
100+
/// <summary>
101+
/// Executes this command on the associated <see cref="MySqlConnection"/>.
102+
/// </summary>
103+
/// <returns>The number of rows affected.</returns>
104+
/// <remarks>For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.
105+
/// For stored procedures, the return value is the number of rows affected by the last statement in the stored procedure,
106+
/// or zero if the last statement is a SELECT. For all other types of statements, the return value is -1.</remarks>
101107
public override int ExecuteNonQuery() => ExecuteNonQueryAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
102108

103109
/// <inheritdoc/>
@@ -271,6 +277,14 @@ protected override DbTransaction? DbTransaction
271277
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) =>
272278
ExecuteReaderAsync(behavior, IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
273279

280+
/// <summary>
281+
/// Executes this command asynchronously on the associated <see cref="MySqlConnection"/>.
282+
/// </summary>
283+
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
284+
/// <returns>A task representing the asynchronous operation.</returns>
285+
/// <remarks>For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.
286+
/// For stored procedures, the return value is the number of rows affected by the last statement in the stored procedure,
287+
/// or zero if the last statement is a SELECT. For all other types of statements, the return value is -1.</remarks>
274288
public override Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken) =>
275289
ExecuteNonQueryAsync(AsyncIOBehavior, cancellationToken);
276290

src/MySqlConnector/MySqlDataReader.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ public override bool HasRows
204204
}
205205

206206
public override bool IsClosed => Command is null;
207+
208+
/// <summary>
209+
/// Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
210+
/// </summary>
211+
/// <remarks>For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.
212+
/// For stored procedures, the return value is the number of rows affected by the last statement in the stored procedure,
213+
/// or zero if the last statement is a SELECT. For all other types of statements, the return value is -1.</remarks>
207214
public override int RecordsAffected => RealRecordsAffected is ulong recordsAffected ? checked((int) recordsAffected) : -1;
208215

209216
public override int GetOrdinal(string name) => GetResultSet().GetOrdinal(name);

0 commit comments

Comments
 (0)