summaryrefslogtreecommitdiff
path: root/mysql-test/t/sp-goto.test
blob: e770dd285ff766a38de558f04907f14a51d20525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#
# The non-standard GOTO, for compatibility
#
# QQQ The "label" syntax is temporary, it will (hopefully)
#     change to the more common "L:" syntax soon.
#     For the time being, this feature is disabled, until
#     the syntax (and some other known bugs) can be fixed.
#
# Test cases for bugs are added at the end. See template there.
#

--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1 (
	id   char(16) not null default '',
        data int not null
);

delimiter //;

--disable_warnings
drop procedure if exists goto1//
--enable_warnings
create procedure goto1()
begin
  declare y int;

label a;
  select * from t1;
  select count(*) into y from t1;
  if y > 2 then
    goto b;
  end if;
  insert into t1 values ("j", y);
  goto a;
label b;
end//

call goto1()//
drop procedure goto1//

# With dummy handlers, just to test restore of contexts with jumps
--disable_warnings
drop procedure if exists goto2//
--enable_warnings
create procedure goto2(a int)
begin
  declare x int default 0;
  declare continue handler for sqlstate '42S98' set x = 1;

label a;
  select * from t1;
b:
  while x < 2 do
    begin
      declare continue handler for sqlstate '42S99' set x = 2;

      if a = 0 then
        set x = x + 1;
        iterate b;
      elseif a = 1 then
        leave b;
      elseif a = 2 then
        set a = 1;
        goto a;
      end if;
    end;
  end while b;

  select * from t1;
end//

call goto2(0)//
call goto2(1)//
call goto2(2)//

drop procedure goto2//
delete from t1//

# Check label visibility for some more cases. We don't call these.
--disable_warnings
drop procedure if exists goto3//
--enable_warnings
create procedure goto3()
begin
 label L1;
   begin
   end;
 goto L1;
end//
drop procedure goto3//

--disable_warnings
drop procedure if exists goto4//
--enable_warnings
create procedure goto4()
begin
  begin
   label lab1;
    begin
      goto lab1;
    end;
  end;
end//
drop procedure goto4//

--disable_warnings
drop procedure if exists goto5//
--enable_warnings
create procedure goto5()
begin
  begin
    begin
      goto lab1;
    end;
   label lab1;
  end;
end//
drop procedure goto5//

--disable_warnings
drop procedure if exists goto6//
--enable_warnings
create procedure goto6()
begin
  label L1;
  goto L5;
  begin
    label L2;
    goto L1;
    goto L5;
    begin
      label L3;
      goto L1;
      goto L2;
      goto L3;
      goto L4;
      goto L5;
    end;
    goto L2;
    goto L4;
    label L4;
  end;
  label L5;
  goto L1;
end//
drop procedure goto6//

# Mismatching labels
--error 1308
create procedure foo()
begin
  goto foo;
end//
--error 1308
create procedure foo()
begin
  begin
    label foo;
  end;
  goto foo;
end//
--error 1308
create procedure foo()
begin
  goto foo;
  begin
    label foo;
  end;
end//
--error 1308
create procedure foo()
begin
  begin
    goto foo;
  end;
  begin
    label foo;
  end;
end//
--error 1308
create procedure foo()
begin
  begin
    label foo;
  end;
  begin
    goto foo;
  end;
end//

# No goto in a handler
--error 1358
create procedure p()
begin
  declare continue handler for sqlexception
    begin
      goto L1;
    end;

  select field from t1;
  label L1;
end//


#
# Test cases for old bugs
#

#
# BUG#6898: Stored procedure crash if GOTO statements exist
#
--disable_warnings
drop procedure if exists bug6898//
--enable_warnings
create procedure bug6898()
begin
  goto label1;
  label label1;
  begin end;
  goto label1;
end//
drop procedure bug6898//

#
# BUG#NNNN: New bug synopsis
#
#--disable_warnings
#drop procedure if exists bugNNNN//
#--enable_warnings
#create procedure bugNNNN...


# Add bugs above this line. Use existing tables t1 and t2 when
# practical, or create table t3, t4 etc temporarily (and drop them).
delimiter ;//
drop table t1;