Skip to content
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

HasRows return value is inconsistent #348

Closed
bgrainger opened this issue Oct 6, 2017 · 4 comments
Closed

HasRows return value is inconsistent #348

bgrainger opened this issue Oct 6, 2017 · 4 comments
Assignees
Labels
Milestone

Comments

@bgrainger
Copy link
Member

@jovana writes (split from #327):

I want to add something to the HasRows property.
I found a very strange behavior.

The value of MySqlDataReader.HasRows has changed the moment you request the value of the property. In my opinion it should always the same, right? It seems like it only changed the first and second time you request the value.

Dim rs As MySqlDataReader = cmd.ExecuteReader
Dim HasRows As Boolean
HasRows = rs.HasRows    ' <-- this will returns True (this is good)
HasRows = rs.HasRows    ' <-- this will returns False (why, what is changed on the first call?)
HasRows = rs.HasRows    ' <-- this will returns True (again, this is good)
HasRows = rs.HasRows    ' <-- this will returns True (again, now it keeps True al the checkes)
@bgrainger bgrainger added the bug label Oct 6, 2017
bgrainger added a commit to bgrainger/MySqlConnector that referenced this issue Oct 6, 2017
@bgrainger bgrainger self-assigned this Oct 6, 2017
@bgrainger bgrainger added this to the 1.0 milestone Oct 6, 2017
@jovana
Copy link

jovana commented Oct 7, 2017

Thanks for the fix!

@bgrainger
Copy link
Member Author

Fixed in 0.28.0.

@Topcoder01
Copy link

I don't think this is fixed, I'm getting the same behavior on the latest version

@bgrainger
Copy link
Member Author

@Topcoder01 There's a test that verifies that the OP's bug is fixed:

[Fact]
public void HasRowsRepeated()
{
m_database.Connection.Execute(@"drop table if exists has_rows;
create table has_rows(value int not null);
insert into has_rows(value) values(1),(2),(3);");
using (var cmd = m_database.Connection.CreateCommand())
{
cmd.CommandText = "select * from has_rows where value = 1;";
using (var reader = cmd.ExecuteReader())
{
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
Assert.True(reader.Read());
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
Assert.False(reader.Read());
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
Assert.True(reader.HasRows);
}
}
}

Do you have steps to reproduce the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants