Bug #65330 cursors repeat last row
Submitted: 16 May 2012 11:14 Modified: 16 May 2012 20:46
Reporter: Rami Jamleh Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.5.24 OS:Windows (7 sp1)
Assigned to: CPU Architecture:Any
Tags: Cursors, duplicate, last row

[16 May 2012 11:14] Rami Jamleh
Description:
\d $ create procedure p()
-- t1 is exactly like t2 (int,int) no indexes 
BEGIN
declare a,b,done int;
declare c cursor for select * from t1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
set done = FALSE;
open c;
lbl:loop
fetch c into a,b;
insert into t2(a,b) values(a,b);
if done then
leave lbl;
end if;

end loop;
close c;
END$

in lubuntu 12.4 same case
mysql> \u cur
Database changed
mysql> create table t1(a int,b int);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t1 values(1,1),(3,4);
Query OK, 2 rows affected (0.06 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> \d $ create procedure p() 
    -> begin
    -> declare a,b,done int;
    -> declare c cursor for select * from t1;
    -> declare continue handler for not found set done =true;
    -> open c;
    -> lbl:
    -> loop
    -> fetch c into a,b;
    -> insert into t2(a,b) values(a,b);
    -> if done then
    -> leave lbl;
    -> end if;
    -> end loop;
    -> close c;
    -> end$
Query OK, 0 rows affected (0.35 sec)

mysql> create table t2 like t1;
    -> $
Query OK, 0 rows affected (0.08 sec)

mysql> call p$
Query OK, 1 row affected (0.06 sec)

mysql> select * from t2;
    -> $
+------+------+
| a    | b    |
+------+------+
|    1 |    1 |
|    3 |    4 |
|    3 |    4 |
+------+------+
3 rows in set (0.00 sec)
 

How to repeat:
when ever i call the procedure
[16 May 2012 20:46] Rami Jamleh
i am mistaken sorry