Commit 94bbe8ad authored by Michael Widenius's avatar Michael Widenius Committed by Sergei Golubchik

Affected rows for a SP now includes affected rows for all statements

The old behavior of returning the affected rows for the last statement
in a stored procedure was more an accident than design. Having the number
of affected rows for all sub statements is more useful and will not change
just because on changes the order of statements in the stored procedure.
parent 4be15fe0
......@@ -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;
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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;
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment