diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 53626d8013e..275e5ff502e 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5742,7 +5742,7 @@ SELECT @@max_sp_recursion_depth| CALL bug23760_test_row_count2(2)| SELECT ROW_COUNT()| ROW_COUNT() -1 +16 SELECT * FROM bug23760_log ORDER BY id| id reason ammount 1 Test is working 7 @@ -8234,3 +8234,28 @@ rec=(10) c rec=(20) DROP PROCEDURE p1; +# Test affected rows from an sp +create table t1 (a int); +create procedure p1() +begin +insert into t1 values(1); +insert into t1 values(2); +end; +$$ +create procedure p2() +begin +insert into t1 values(1); +call p1(); +select row_count(); +insert into t1 values(2); +insert into t1 values(2); +end; +$$ +CALL p2(); +row_count() +2 +affected rows: 1 +affected rows: 5 +DROP PROCEDURE p1; +DROP PROCEDURE p2; +drop table t1; diff --git a/mysql-test/suite/funcs_1/r/innodb_storedproc_10.result b/mysql-test/suite/funcs_1/r/innodb_storedproc_10.result index 405b7ab62b0..ffa30f4d012 100644 --- a/mysql-test/suite/funcs_1/r/innodb_storedproc_10.result +++ b/mysql-test/suite/funcs_1/r/innodb_storedproc_10.result @@ -264,7 +264,7 @@ agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993 CALL sp_ins_3(); SELECT row_count(); row_count() -1 +3 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992 @@ -317,7 +317,7 @@ COUNT( f1 ) f1 4 updated SELECT row_count(); row_count() -3 +7 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992 @@ -380,7 +380,7 @@ row_count() after delete 2 SELECT row_count(); row_count() -0 +8 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 qwe xyz 1998-03-26 100 uvw 1000 diff --git a/mysql-test/suite/funcs_1/r/memory_storedproc_10.result b/mysql-test/suite/funcs_1/r/memory_storedproc_10.result index 0f5fe7cf34c..ef5aa4c8570 100644 --- a/mysql-test/suite/funcs_1/r/memory_storedproc_10.result +++ b/mysql-test/suite/funcs_1/r/memory_storedproc_10.result @@ -265,7 +265,7 @@ agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993 CALL sp_ins_3(); SELECT row_count(); row_count() -1 +3 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992 @@ -318,7 +318,7 @@ COUNT( f1 ) f1 4 updated SELECT row_count(); row_count() -3 +7 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992 @@ -381,7 +381,7 @@ row_count() after delete 2 SELECT row_count(); row_count() -0 +8 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 qwe xyz 1998-03-26 100 uvw 1000 diff --git a/mysql-test/suite/funcs_1/r/myisam_storedproc_10.result b/mysql-test/suite/funcs_1/r/myisam_storedproc_10.result index 0f5fe7cf34c..ef5aa4c8570 100644 --- a/mysql-test/suite/funcs_1/r/myisam_storedproc_10.result +++ b/mysql-test/suite/funcs_1/r/myisam_storedproc_10.result @@ -265,7 +265,7 @@ agaaaaaaa agaaaaaaa 1000-01-08 -4993 agaaaaaaa -4993 CALL sp_ins_3(); SELECT row_count(); row_count() -1 +3 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992 @@ -318,7 +318,7 @@ COUNT( f1 ) f1 4 updated SELECT row_count(); row_count() -3 +7 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 a^aaaaaaaa a^aaaaaaaa 1000-01-09 -4992 a^aaaaaaaa -4992 @@ -381,7 +381,7 @@ row_count() after delete 2 SELECT row_count(); row_count() -0 +8 SELECT * FROM temp; f1 f2 f3 f4 f5 f6 qwe xyz 1998-03-26 100 uvw 1000 diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 7eedc67acd9..6b969e3b4a0 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -9702,3 +9702,32 @@ $$ DELIMITER ;$$ CALL p1(); DROP PROCEDURE p1; + +--echo # Test affected rows from an sp + +create table t1 (a int); + +DELIMITER $$; +create procedure p1() +begin +insert into t1 values(1); +insert into t1 values(2); +end; +$$ +create procedure p2() +begin +insert into t1 values(1); +call p1(); +select row_count(); +insert into t1 values(2); +insert into t1 values(2); +end; +$$ +DELIMITER ;$$ + +--enable_info +CALL p2(); +--disable_info +DROP PROCEDURE p1; +DROP PROCEDURE p2; +drop table t1; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3a47612fa65..2370c1e4684 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2919,8 +2919,7 @@ static bool do_execute_sp(THD *thd, sp_head *sp) affected_rows= thd->affected_rows; // Affected rows for all sub statements thd->affected_rows= 0; // Reset total, as my_ok() adds to it - my_ok(thd, (thd->get_row_count_func() < 0) ? 0 : thd->get_row_count_func()); - thd->affected_rows= affected_rows; // Restore original value + my_ok(thd, affected_rows); return 0; }