Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/SingleStoreConnector/SingleStoreDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ 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"/>.</remarks>
public override int RecordsAffected => RealRecordsAffected is ulong recordsAffected ? (int) Math.Min(recordsAffected, int.MaxValue) : -1;
public override int GetOrdinal(string name) => GetResultSet().GetOrdinal(name);

public override bool GetBoolean(int ordinal) => GetResultSet().GetCurrentRow().GetBoolean(ordinal);
Expand Down
9 changes: 9 additions & 0 deletions tests/SingleStoreConnector.Tests/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public void Dispose()
m_server.Stop();
}

[Fact]
public void RecordsAffectedAboveInt32MaxValueIsClamped()
{
using var connection = new SingleStoreConnection(m_csb.ConnectionString);
connection.Open();
using var command = new SingleStoreCommand("ALTER TABLE big_table ADD COLUMN c INT", connection);
Assert.Equal(int.MaxValue, command.ExecuteNonQuery());
}

[Fact]
public void PooledConnectionIsReturnedToPool()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ 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")
{
await SendAsync(stream, 1, x =>
{
x.Write((byte) 0); // signature
x.Write((byte) 0xFE); // 8-byte length-encoded integer
x.Write(4_000_000_000UL); // rows affected
x.Write((byte) 0); // last insert ID
x.Write((ushort) 0); // server status
x.Write((ushort) 0); // warning count
});
}
else if (query == "select infinity")
{
var packets = new[]
Expand Down