File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -1282,6 +1282,7 @@ static VALUE rb_mysql_client_next_result(VALUE self)
12821282 int ret ;
12831283 GET_CLIENT (self );
12841284 ret = mysql_next_result (wrapper -> client );
1285+ wrapper -> affected_rows = mysql_affected_rows (wrapper -> client );
12851286 if (ret > 0 ) {
12861287 rb_raise_mysql2_error (wrapper );
12871288 return Qfalse ;
Original file line number Diff line number Diff line change @@ -1064,12 +1064,23 @@ def run_gc
10641064 end
10651065
10661066 it "#affected_rows should return a Fixnum, from the last INSERT/UPDATE" do
1067- @client . query "INSERT INTO lastIdTest (blah) VALUES (1234)"
1068- expect ( @client . affected_rows ) . to eql ( 1 )
1067+ @client . query "INSERT INTO lastIdTest (blah) VALUES (1234), (5678) "
1068+ expect ( @client . affected_rows ) . to eql ( 2 )
10691069 @client . query "UPDATE lastIdTest SET blah=4321 WHERE id=1"
10701070 expect ( @client . affected_rows ) . to eql ( 1 )
10711071 end
10721072
1073+ it "#affected_rows with multi statements returns the last result's affected_rows" do
1074+ @client . set_server_option ( Mysql2 ::Client ::OPTION_MULTI_STATEMENTS_ON )
1075+
1076+ @client . query ( "INSERT INTO lastIdTest (blah) VALUES (1234), (5678); UPDATE lastIdTest SET blah=4321 WHERE id=1" )
1077+ expect ( @client . affected_rows ) . to eq ( 2 )
1078+ expect ( @client . next_result ) . to eq ( true )
1079+ expect ( @client . affected_rows ) . to eq ( 1 )
1080+ ensure
1081+ @client . set_server_option ( Mysql2 ::Client ::OPTION_MULTI_STATEMENTS_OFF )
1082+ end
1083+
10731084 it "#affected_rows isn't cleared by Statement#close" do
10741085 stmt = @client . prepare ( "INSERT INTO lastIdTest (blah) VALUES (1234)" )
10751086
You can’t perform that action at this time.
0 commit comments