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
1 change: 1 addition & 0 deletions ext/mysql2/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ static VALUE rb_mysql_client_next_result(VALUE self)
int ret;
GET_CLIENT(self);
ret = mysql_next_result(wrapper->client);
wrapper->affected_rows = mysql_affected_rows(wrapper->client);
if (ret > 0) {
rb_raise_mysql2_error(wrapper);
return Qfalse;
Expand Down
15 changes: 13 additions & 2 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,23 @@ def run_gc
end

it "#affected_rows should return a Fixnum, from the last INSERT/UPDATE" do
@client.query "INSERT INTO lastIdTest (blah) VALUES (1234)"
expect(@client.affected_rows).to eql(1)
@client.query "INSERT INTO lastIdTest (blah) VALUES (1234), (5678)"
expect(@client.affected_rows).to eql(2)
@client.query "UPDATE lastIdTest SET blah=4321 WHERE id=1"
expect(@client.affected_rows).to eql(1)
end

it "#affected_rows with multi statements returns the last result's affected_rows" do
@client.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)

@client.query("INSERT INTO lastIdTest (blah) VALUES (1234), (5678); UPDATE lastIdTest SET blah=4321 WHERE id=1")
expect(@client.affected_rows).to eq(2)
expect(@client.next_result).to eq(true)
expect(@client.affected_rows).to eq(1)
ensure
@client.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)
end

it "#affected_rows isn't cleared by Statement#close" do
stmt = @client.prepare("INSERT INTO lastIdTest (blah) VALUES (1234)")

Expand Down
Loading