| 1 |
drop table if exists t1; |
| 2 |
drop table if exists t2; |
| 3 |
create table t1 ( |
| 4 |
a int not null primary key, |
| 5 |
b int not null |
| 6 |
) engine=ndb; |
| 7 |
create table t2 ( |
| 8 |
a int not null primary key, |
| 9 |
b int not null |
| 10 |
) engine=ndb; |
| 11 |
insert into t1 values (1,10), (2,20), (3,30), (4, 40); |
| 12 |
create procedure test_cursor () |
| 13 |
begin |
| 14 |
declare done int default 0; |
| 15 |
declare temp_a int; |
| 16 |
declare temp_b int; |
| 17 |
declare cur1 cursor for select a,b from t1; |
| 18 |
declare continue handler for sqlstate '02000' set done = 1; |
| 19 |
open cur1; |
| 20 |
repeat |
| 21 |
fetch cur1 into temp_a, temp_b; |
| 22 |
if not done then |
| 23 |
insert into t2 values (temp_a, temp_b); |
| 24 |
end if; |
| 25 |
until done end repeat; |
| 26 |
close cur1; |
| 27 |
end; |
| 28 |
// |
| 29 |
select * from t2 order by a; |
| 30 |
a b |
| 31 |
call test_cursor(); |
| 32 |
select * from t2 order by a; |
| 33 |
a b |
| 34 |
1 10 |
| 35 |
2 20 |
| 36 |
3 30 |
| 37 |
4 40 |
| 38 |
drop procedure test_cursor; |
| 39 |
drop table t1,t2; |
| 40 |
end of 5.1 tests |