Skip to content
Merged
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 ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,6 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
wrapper->active_fiber = Qnil;
rb_raise_mysql2_error(wrapper);
}
wrapper->affected_rows = mysql_affected_rows(wrapper->client);

is_streaming = rb_hash_aref(rb_ivar_get(self, intern_current_query_options), sym_stream);
if (is_streaming == Qtrue) {
Expand All @@ -682,6 +681,8 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
result = (MYSQL_RES *)rb_thread_call_without_gvl(nogvl_store_result, wrapper, RUBY_UBF_IO, 0);
}

wrapper->affected_rows = mysql_affected_rows(wrapper->client);

if (result == NULL) {
if (mysql_errno(wrapper->client) != 0) {
wrapper->active_fiber = Qnil;
Expand Down Expand Up @@ -1165,7 +1166,7 @@ static VALUE rb_mysql_client_affected_rows(VALUE self) {

REQUIRE_CONNECTED(wrapper);
retVal = wrapper->affected_rows;
if (retVal == (uint64_t)-1) {
if (retVal == (my_ulonglong)-1) {
rb_raise_mysql2_error(wrapper);
}
return ULL2NUM(retVal);
Expand Down
5 changes: 5 additions & 0 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,11 @@ def run_gc
end
end

it "#affected_rows when no rows were affected returns 1" do
@client.query "SELECT sleep(0.01)"
expect(@client.affected_rows).to eq(1)
end

it "should respond to #thread_id" do
expect(@client).to respond_to(:thread_id)
end
Expand Down
Loading