Skip to content

Commit a7e7aa7

Browse files
committed
Support CommandBehavior.SingleResult.
1 parent c1edd0f commit a7e7aa7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlDataReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal async Task<bool> NextResultAsync(IOBehavior ioBehavior, CancellationTok
9191
ActivateResultSet();
9292
}
9393
}
94-
while (m_hasMoreResults && (Command!.CommandBehavior & CommandBehavior.SingleRow) != 0);
94+
while (m_hasMoreResults && (Command!.CommandBehavior & (CommandBehavior.SingleResult | CommandBehavior.SingleRow)) != 0);
9595

9696
if (!m_hasMoreResults)
9797
m_resultSet.Reset();

tests/SideBySide/QueryTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,30 @@ public async Task CommandBehaviorSingleRowMultipleResultSets()
10971097
}
10981098
}
10991099

1100+
[Fact]
1101+
public async Task CommandBehaviorSingleResultMultipleResultSets()
1102+
{
1103+
using var connection = new MySqlConnection(AppConfig.ConnectionString);
1104+
connection.Open();
1105+
connection.Execute(@"drop table if exists command_behavior_single_result;
1106+
create table command_behavior_single_result(id integer not null primary key);");
1107+
1108+
using (var cmd = new MySqlCommand("SELECT 1; insert into command_behavior_single_result(id) values(1); SELECT 2;", connection))
1109+
{
1110+
using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult);
1111+
Assert.True(await reader.ReadAsync());
1112+
Assert.Equal(1, reader.GetInt32(0));
1113+
Assert.False(await reader.ReadAsync());
1114+
Assert.False(await reader.NextResultAsync());
1115+
}
1116+
1117+
// subsequent commands were still executed (and had effects) even though they didn't return results
1118+
using (var cmd = new MySqlCommand("select count(*) from command_behavior_single_result;", connection))
1119+
{
1120+
Assert.Equal(1L, await cmd.ExecuteScalarAsync());
1121+
}
1122+
}
1123+
11001124
#if !BASELINE
11011125
[Fact]
11021126
public void NoBackslashEscapes()

0 commit comments

Comments
 (0)