Repository navigation
Clamp RecordsAffected to int.MaxValue instead of throwing #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,8 +208,10 @@ public override bool HasRows | |
| /// </summary> | ||
| /// <remarks>For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. | ||
| /// For stored procedures, the return value is the number of rows affected by the last statement in the stored procedure, | ||
| /// or zero if the last statement is a SELECT. For all other types of statements, the return value is -1.</remarks> | ||
| public override int RecordsAffected => RealRecordsAffected is ulong recordsAffected ? checked((int) recordsAffected) : -1; | ||
| /// or zero if the last statement is a SELECT. For all other types of statements, the return value is -1. | ||
| /// If the number of affected rows exceeds <see cref="int.MaxValue"/>, the return value is <see cref="int.MaxValue"/>; | ||
| /// use <see cref="RealRecordsAffected"/> to get the exact count.</remarks> | ||
| public override int RecordsAffected => RealRecordsAffected is ulong recordsAffected ? (int) Math.Min(recordsAffected, int.MaxValue) : -1; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the fix! one thing to keep in mind is that previously the that's why I think it makes sense to make got this idea from Npsql connector -- https://github.com/npgsql/npgsql/blob/af6676e70ea51699df13b9f97db8f02bb9b6f629/src/Npgsql/NpgsqlDataReader.cs#L885-L905
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're welcome and good call! |
||
| public override int GetOrdinal(string name) => GetResultSet().GetOrdinal(name); | ||
|
|
||
| public override bool GetBoolean(int ordinal) => GetResultSet().GetCurrentRow().GetBoolean(ordinal); | ||
|
|
@@ -463,7 +465,11 @@ protected override void Dispose(bool disposing) | |
| internal Activity? Activity { get; private set; } | ||
| internal ISingleStoreCommand? Command { get; private set; } | ||
| internal SingleStoreConnection? Connection => Command?.Connection; | ||
| internal ulong? RealRecordsAffected { get; set; } | ||
| /// <summary> | ||
| /// Gets the number of rows changed, inserted, or deleted by execution of the SQL statement, without truncation to <see cref="int"/>. | ||
| /// </summary> | ||
| /// <remarks>Returns <c>null</c> when <see cref="RecordsAffected"/> would return -1.</remarks> | ||
| public ulong? RealRecordsAffected { get; internal set; } | ||
| internal ServerSession? Session => Command?.Connection!.Session; | ||
|
|
||
| internal async Task InitAsync(CommandListPosition commandListPosition, ICommandPayloadCreator payloadCreator, IDictionary<string, CachedProcedure?>? cachedProcedures, ISingleStoreCommand command, CommandBehavior behavior, Activity? activity, IOBehavior ioBehavior, CancellationToken cancellationToken) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,10 @@ public async Task RunAsync(TcpClient client, CancellationToken token) | |
| var wasSet = CancelQueryEvent.Wait(0, token); | ||
| await SendAsync(stream, 1, WriteOk); | ||
| } | ||
| else if (query == "ALTER TABLE big_table ADD COLUMN c INT") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this duplicates
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WriteOk is passed as a method group in several places, so an optional parameter didn't want to compile.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point! optional parameters aren't considered in method group conversion, so an overload |
||
| { | ||
| await SendAsync(stream, 1, x => WriteOk(x, 4_000_000_000UL)); | ||
| } | ||
| else if (query == "select infinity") | ||
| { | ||
| var packets = new[] | ||
|
|
@@ -295,10 +299,20 @@ private void WriteInitialHandshake(BinaryWriter writer) | |
| writer.Write((byte) 0); | ||
| } | ||
|
|
||
| private static void WriteOk(BinaryWriter writer) | ||
| private static void WriteOk(BinaryWriter writer) => WriteOk(writer, 0); | ||
|
|
||
| private static void WriteOk(BinaryWriter writer, ulong affectedRows) | ||
| { | ||
| writer.Write((byte) 0); // signature | ||
| writer.Write((byte) 0); // 0 rows affected | ||
| if (affectedRows < 251) | ||
| { | ||
| writer.Write((byte) affectedRows); // rows affected | ||
| } | ||
| else | ||
| { | ||
| writer.Write((byte) 0xFE); // 8-byte length-encoded integer | ||
| writer.Write(affectedRows); // rows affected | ||
| } | ||
| writer.Write((byte) 0); // last insert ID | ||
| writer.Write((ushort) 0); // server status | ||
| writer.Write((ushort) 0); // warning count | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for updating these!
one detail though:
ExecuteNonQuery() creates and disposes the reader internally, so users can't accessRealRecordsAffected. could we add this info here and inExecuteNonQueryAsync()? smth like:If the number of affected rows exceeds int.MaxValue, the return value is int.MaxValue. To obtain the exact count, use ExecuteReader(), call SingleStoreDataReader.NextResult until it returns false, then read SingleStoreDataReader.RealRecordsAffectedfor the async version we should use
ExecuteReaderAsync()andNextResultAsync()