~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/storedproc/storedproc_03.inc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#### suite/funcs_1/storedproc/storedproc_03.inc
 
2
#
 
3
--source suite/funcs_1/storedproc/load_sp_tb.inc
 
4
 
 
5
# ==============================================================================
 
6
# (numbering from requirement document TP v1.0, Last updated: 25 Jan 2005 01:00)
 
7
#
 
8
# 3.1.3 Syntax checks for the stored procedure-specific flow control statements IF, CASE, LOOP, LEAVE, ITERATE, REPEAT, WHILE:
 
9
#
 
10
#-  1. Ensure that all subclauses that should be supported are supported.
 
11
#-  2. Ensure that all subclauses that should not be supported are disallowed with an appropriate error message.
 
12
#-  3. Ensure that all supported subclauses are supported only in the correct order.
 
13
#-  4. Ensure that an appropriate error message is returned if a subclause is out-of-order in a stored procedure definition.
 
14
#-  5. Ensure that all subclauses that are defined to be mandatory are indeed required to be mandatory by the MySQL server and tools.
 
15
#-  6. Ensure that any subclauses that are defined to be optional are indeed treated as optional by the MySQL server and tools.
 
16
##  7. Ensure that the IF statement acts correctly for all variants, including cases where statements are nested.
 
17
##  8. Ensure that the CASE statement acts correctly for all variants, including cases where statements are nested.
 
18
##  9. Ensure that the LOOP statement acts correctly for all variants, including cases where statements are nested.
 
19
#- 10. Ensure that the labels enclosing each LOOP statement must match.
 
20
#- 11. Ensure that it is possible to put a beginning label at the start of a LOOP statement without also requiring an ending label at the end of the same statement.
 
21
#- 12. Ensure that it is not possible to put an ending label at the end of a LOOP statement without also requiring a matching beginning label at the start of the same statement.
 
22
#- 13. Ensure that every beginning label must end with a colon (:).
 
23
#- 14. Ensure that every beginning label with the same scope must be unique.
 
24
## 15. Ensure that the LEAVE statement acts correctly for all variants, including cases where statements are nested.
 
25
## 16. Ensure that the ITERATE statement acts correctly for all variants, including cases where statements are nested.
 
26
#- 17. Ensure that the ITERATE statement fails, with an appropriate error message, if it appears in any context other than within LOOP, REPEAT, or WHILE statements.
 
27
## 18. Ensure that the REPEAT statement acts correctly for all variants, including cases where statements are nested.
 
28
#- 19. Ensure that the labels enclosing each REPEAT statement must match.
 
29
#- 20. Ensure that it is possible to put a beginning label at the start of a REPEAT statement without also requiring an ending label at the end of the same statement.
 
30
#- 21. Ensure that it is not possible to put an ending label at the end of a REPEAT statement without also requiring a matching beginning label at the start of the same statement.
 
31
#- 22. Ensure that every beginning label must end with a colon (:).
 
32
#- 23. Ensure that every beginning label with the same scope must be unique.
 
33
## 24. Ensure that the WHILE statement acts correctly for all variants, including cases where statements are nested.
 
34
#- 25. Ensure that the labels enclosing each WHILE statement must match.
 
35
#- 26. Ensure that it is possible to put a beginning label at the start of a WHILE statement without also requiring an ending label at the end of the same statement.
 
36
#- 27. Ensure that it is not possible to put an ending label at the end of a WHILE statement without also requiring a matching beginning label at the start of the same statement.
 
37
#- 28. Ensure that every beginning label must end with a colon (:).
 
38
#- 29. Ensure that every beginning label with the same scope must be unique.
 
39
## 30. Ensure that multiple cases of all possible combinations of the control flow statements, nested within multiple compound statements within a stored procedure, always act correctly and return the expected result.
 
40
#
 
41
# ==============================================================================
 
42
let $message= Section 3.1.3 - Syntax checks for the stored procedure-specific flow
 
43
control statements IF, CASE, LOOP, LEAVE, ITERATE, REPEAT, WHILE:;
 
44
--source include/show_msg80.inc
 
45
 
 
46
#FIXME # 3.1.3: enhance syntax checks with very complicated checks
 
47
 
 
48
# ------------------------------------------------------------------------------
 
49
let $message= Testcase 3.1.3.7:;
 
50
--source include/show_msg.inc
 
51
let $message=
 
52
Ensure that the IF statement acts correctly for all variants, including cases
 
53
where statements are nested.;
 
54
--source include/show_msg80.inc
 
55
 
 
56
--disable_warnings
 
57
DROP TABLE IF EXISTS res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
58
DROP PROCEDURE IF EXISTS sp9;
 
59
--enable_warnings
 
60
 
 
61
CREATE TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742( f1 CHAR(20), f2 VARCHAR(20), f3 SMALLINT);
 
62
 
 
63
delimiter //;
 
64
CREATE PROCEDURE sp9( action char(20), subaction char(20) )
 
65
BEGIN
 
66
   if action = 'action' then
 
67
      if subaction = 'subaction' then
 
68
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'action', 'subaction' , 1);
 
69
      else
 
70
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'action', 'none' , 2);
 
71
      END if;
 
72
   else
 
73
      if subaction = 'subaction'
 
74
      then
 
75
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'none', 'subaction' , 3);
 
76
      elseif subaction = 'subaction1'
 
77
      then
 
78
         BEGIN
 
79
            insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values ('none', 'subaction1', 4);
 
80
         END;
 
81
      else
 
82
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'none', 'none' , 5);
 
83
      END if;
 
84
   END if;
 
85
END//
 
86
delimiter ;//
 
87
 
 
88
CALL sp9( 'action', 'subaction' );
 
89
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742 where f3=1;
 
90
 
 
91
CALL sp9( 'temp', 'subaction' );
 
92
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742 where f3=3;
 
93
 
 
94
CALL sp9( 'temp', 'subaction1' );
 
95
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742 where f3=4;
 
96
 
 
97
CALL sp9( 'action', 'temp' );
 
98
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742 where f3=2;
 
99
 
 
100
CALL sp9( 'temp', 'temp' );
 
101
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742 where f3=5;
 
102
 
 
103
# cleanup 3.1.3.7
 
104
DROP PROCEDURE sp9;
 
105
DROP TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
106
 
 
107
 
 
108
# ------------------------------------------------------------------------------
 
109
let $message= Testcase 3.1.3.8.:;
 
110
--source include/show_msg.inc
 
111
let $message=
 
112
Ensure that the CASE statement acts correctly for all variants, including cases
 
113
where statements are nested.;
 
114
--source include/show_msg80.inc
 
115
 
 
116
--disable_warnings
 
117
drop table IF EXISTS res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
118
DROP PROCEDURE IF EXISTS sp10;
 
119
--enable_warnings
 
120
 
 
121
create table res_t3_itisalongname_1381742_itsaverylongname_1381742( f1 char(20), f2 varchar(20), f3 smallint);
 
122
 
 
123
delimiter //;
 
124
CREATE PROCEDURE sp10( action char(20), subaction char(20) )
 
125
BEGIN
 
126
   case action
 
127
   when 'action' then
 
128
      case
 
129
      when subaction = 'subaction_1' then
 
130
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'action', 'subaction_2' , 1);
 
131
      when subaction = 'subaction_2' then
 
132
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'action', 'subaction_2' , 2);
 
133
      else
 
134
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'action', 'none' , 3);
 
135
      END case;
 
136
    else
 
137
      case
 
138
      when subaction = 'subaction_1' then
 
139
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'none', 'subaction_1' , 4);
 
140
      when subaction = 'subaction_2' then
 
141
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'none', 'subaction_2' , 5);
 
142
      else
 
143
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'none', 'none' , 6);
 
144
      END case;
 
145
   END case;
 
146
END//
 
147
delimiter ;//
 
148
 
 
149
CALL sp10( 'action', 'subaction_1' );
 
150
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
151
delete from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
152
 
 
153
CALL sp10( 'action', 'subaction_2' );
 
154
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
155
delete from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
156
 
 
157
CALL sp10( 'temp', 'subaction_1' );
 
158
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
159
delete from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
160
 
 
161
CALL sp10( 'temp', 'subaction_2' );
 
162
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
163
delete from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
164
 
 
165
CALL sp10( 'action', 'temp' );
 
166
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
167
delete from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
168
 
 
169
CALL sp10( 'temp', 'temp' );
 
170
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
171
 
 
172
# cleanup 3.1.3.8
 
173
DROP PROCEDURE sp10;
 
174
DROP TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
175
 
 
176
 
 
177
# ------------------------------------------------------------------------------
 
178
let $message= Testcase 3.1.3.9 + 3.1.3.15:;
 
179
--source include/show_msg.inc
 
180
let $message=
 
181
09. Ensure that the LOOP statement acts correctly for all variants, including
 
182
.   cases where statements are nested.
 
183
15. Ensure that the LEAVE statement acts correctly for all variants, including
 
184
.   cases where statements are nested.;
 
185
--source include/show_msg80.inc
 
186
 
 
187
--disable_warnings
 
188
DROP TABLE IF EXISTS res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
189
DROP PROCEDURE IF EXISTS sp11;
 
190
--enable_warnings
 
191
 
 
192
CREATE TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742( f1 CHAR(20), f2 VARCHAR(20), f3 SMALLINT);
 
193
 
 
194
delimiter //;
 
195
CREATE PROCEDURE sp11( )
 
196
BEGIN
 
197
   declare count1 integer default 1;
 
198
   declare count2 integer default 1;
 
199
   label1: loop
 
200
      if count2 > 3 then leave label1;
 
201
      END if;
 
202
      set count1 = 1;
 
203
      label2: loop
 
204
         if count1 > 4 then leave label2;
 
205
         END if;
 
206
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'xyz' , 'pqr', count1);
 
207
         set count1 = count1 + 1;
 
208
         iterate label2;
 
209
      END loop label2;
 
210
      set count2 = count2 + 1;
 
211
      iterate label1;
 
212
   END loop label1;
 
213
END//
 
214
delimiter ;//
 
215
 
 
216
CALL sp11();
 
217
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
218
 
 
219
# cleanup 3.1.3.9
 
220
DROP PROCEDURE sp11;
 
221
DROP TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
222
 
 
223
 
 
224
# ------------------------------------------------------------------------------
 
225
let $message= Testcase 3.1.3.16:;
 
226
--source include/show_msg.inc
 
227
let $message=
 
228
Ensure that the ITERATE statement acts correctly for all variants, including
 
229
cases where statements are nested.
 
230
(tests for this testcase are also included in other testcases);
 
231
--source include/show_msg80.inc
 
232
 
 
233
--disable_warnings
 
234
DROP PROCEDURE IF EXISTS sp31316;
 
235
--enable_warnings
 
236
 
 
237
delimiter //;
 
238
 
 
239
# wrong label at iterate
 
240
#Error: 1308 SQLSTATE: 42000 (ER_SP_LILABEL_MISMATCH) Message: %s with no matching label: %s
 
241
--error 1308
 
242
CREATE PROCEDURE sp31316( )
 
243
BEGIN
 
244
   declare count1 integer default 1;
 
245
   declare count2 integer default 1;
 
246
   label1: loop
 
247
      if count2 > 3 then leave label1;
 
248
      END if;
 
249
      set count1 = 1;
 
250
      label2: loop
 
251
         if count1 > 4 then leave label2;
 
252
         END if;
 
253
         insert into temp values( count1, count2);
 
254
         set count1 = count1 + 1;
 
255
         iterate label3;
 
256
      END loop label2;
 
257
      set count2 = count2 + 1;
 
258
      iterate label1;
 
259
   END loop label1;
 
260
END//
 
261
delimiter ;//
 
262
 
 
263
# cleanup 3.1.3.16
 
264
#DROP PROCEDURE sp31316;
 
265
 
 
266
 
 
267
# ------------------------------------------------------------------------------
 
268
let $message= Testcase 3.1.3.18:;
 
269
--source include/show_msg.inc
 
270
let $message=
 
271
Ensure that the REPEAT statement acts correctly for all variants, including
 
272
cases where statements are nested.;
 
273
--source include/show_msg80.inc
 
274
 
 
275
--disable_warnings
 
276
DROP PROCEDURE IF EXISTS sp17;
 
277
DROP TABLE IF EXISTS res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
278
--enable_warnings
 
279
 
 
280
CREATE TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742( f1 CHAR(20), f2 VARCHAR(20), f3 SMALLINT);
 
281
 
 
282
delimiter //;
 
283
CREATE PROCEDURE sp17( )
 
284
BEGIN
 
285
   declare count1 integer default 1;
 
286
   declare count2 integer default 1;
 
287
   repeat
 
288
      set count1 = count1 + 1;
 
289
      set count2 = 1;
 
290
      label1: repeat
 
291
         set count2 = count2 + 1;
 
292
         insert into res_t3_itisalongname_1381742_itsaverylongname_1381742 values( 'xyz' , 'pqr', count1);
 
293
         until count2 > 3
 
294
      END repeat label1;
 
295
      until count1 > 3
 
296
   END repeat;
 
297
END//
 
298
delimiter ;//
 
299
 
 
300
CALL sp17();
 
301
SELECT * from res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
302
 
 
303
# cleanup 3.1.3.18
 
304
DROP PROCEDURE sp17;
 
305
DROP TABLE res_t3_itisalongname_1381742_itsaverylongname_1381742;
 
306
 
 
307
 
 
308
 
 
309
# ------------------------------------------------------------------------------
 
310
let $message= Testcase 3.1.3.24:;
 
311
--source include/show_msg.inc
 
312
let $message=
 
313
Ensure that the WHILE statement acts correctly for all variants, including cases
 
314
where statements are nested.;
 
315
--source include/show_msg80.inc
 
316
 
 
317
--disable_warnings
 
318
drop table IF EXISTS res_t21;
 
319
DROP PROCEDURE IF EXISTS sp21;
 
320
--enable_warnings
 
321
 
 
322
create table res_t21(name text(10), surname blob(20), age_averylongfieldname_averylongname_1234569 smallint);
 
323
insert into res_t21 values('ashwin', 'mokadam', 25);
 
324
 
 
325
delimiter //;
 
326
CREATE PROCEDURE sp21( )
 
327
BEGIN
 
328
   declare count1 integer default 0;
 
329
   declare count2 integer default 0;
 
330
   while count1 < 3 do
 
331
      BEGIN
 
332
         declare ithisissamevariablename int default 100;
 
333
         SELECT ithisissamevariablename;
 
334
         BEGIN
 
335
            declare ithisissamevariablename int default 200;
 
336
            SELECT ithisissamevariablename;
 
337
         END;
 
338
         set count2 = 0;
 
339
         label1: while count2 < 3 do
 
340
            BEGIN
 
341
               declare count1 integer default 7;
 
342
               set count2 = count2 + 1;
 
343
               insert into res_t21 values( 'xyz' , 'pqr', count2);
 
344
               label2: while count1 < 10 do
 
345
                  set count1 = count1 + 1;
 
346
                  insert into res_t21 values( 'xyz' , 'pqr', count1);
 
347
               END while label2;
 
348
            END;
 
349
         END while label1;
 
350
         set count1 = count1 + 1;
 
351
      END;
 
352
   END while;
 
353
END//
 
354
delimiter ;//
 
355
 
 
356
CALL sp21();
 
357
SELECT * from res_t21;
 
358
 
 
359
# cleanup 3.1.3.
 
360
DROP PROCEDURE sp21;
 
361
drop table res_t21;
 
362
 
 
363
 
 
364
# ------------------------------------------------------------------------------
 
365
let $message= Testcase 3.1.3.30:;
 
366
--source include/show_msg.inc
 
367
let $message=
 
368
Ensure that multiple cases of all possible combinations of the control flow
 
369
statements, nested within multiple compound statements within a stored
 
370
procedure, always act correctly and return the expected result.;
 
371
--source include/show_msg80.inc
 
372
 
 
373
--disable_warnings
 
374
DROP TABLE IF EXISTS res_tbl;
 
375
DROP PROCEDURE IF EXISTS sp31330;
 
376
--enable_warnings
 
377
 
 
378
create table res_tbl (f1 int, f2 text, f3 blob, f4 date,
 
379
      f5 set('one', 'two', 'three', 'four', 'five') default 'one');
 
380
 
 
381
delimiter //;
 
382
#FIXME: can be enhanced more and more ...
 
383
CREATE PROCEDURE sp31330 (path int)
 
384
BEGIN
 
385
   declare count int default 1;
 
386
   declare var1 text;
 
387
   declare var2 blob;
 
388
   declare var3 date;
 
389
   declare var4 set('one', 'two', 'three', 'four', 'five') DEFAULT 'five';
 
390
   case
 
391
      when path=1 then
 
392
         set var3 = '2000-11-09';
 
393
         set var1 = 'flowing through case 1';
 
394
         label1: loop
 
395
            if count > 5 then
 
396
               if var4=1000 then
 
397
                  set var2 = 'exiting out of case 1 - invalid SET';
 
398
               END if;
 
399
               if var4='two' then
 
400
                  set var2 = 'exiting out of case 1';
 
401
               END if;
 
402
               insert into res_tbl values (1, var1, var2, var3, (count-2));
 
403
               leave label1;
 
404
            elseif count = 5 then
 
405
               set count= count + 2;
 
406
               set var4='two';
 
407
               iterate label1;
 
408
            else
 
409
               set count= count + 1;
 
410
            END if;
 
411
            set var4='one';
 
412
         END loop label1;
 
413
      when path=2 then
 
414
         set var3 = '1989-11-09';
 
415
         set var1 = 'flowing through case 2';
 
416
         set @count3=0;
 
417
         label2: repeat
 
418
            set count=count + 1;
 
419
            set @count2=1;
 
420
            while @count2 <= 5 do
 
421
               set @count2 = @count2 + 1;
 
422
            END while;
 
423
            SELECT @count2;
 
424
            set @count3=@count3 + @count2;
 
425
            until count > 5
 
426
         END repeat label2;
 
427
         set var2 = 'exiting out of case 2';
 
428
         set var4 = count-3;
 
429
         SELECT @count3;
 
430
         insert into res_tbl values (2, var1, var2, var3, var4);
 
431
      ELSE BEGIN
 
432
         set @error_opt='undefined path specified';
 
433
         SELECT @error_opt;
 
434
      END;
 
435
   END case;
 
436
END//
 
437
delimiter ;//
 
438
 
 
439
#Error: 1318 SQLSTATE: 42000 (ER_SP_WRONG_NO_OF_ARGS) Message: Incorrect number of arguments for %s %s; expected %u, got %u
 
440
--error 1318
 
441
CALL sp31330();
 
442
 
 
443
CALL sp31330(1);
 
444
SELECT * from res_tbl;
 
445
 
 
446
CALL sp31330(2);
 
447
SELECT * from res_tbl;
 
448
 
 
449
CALL sp31330(4);
 
450
 
 
451
# cleanup 3.1.3.30
 
452
DROP PROCEDURE sp31330;
 
453
drop table res_tbl;
 
454
 
 
455
 
 
456
 
 
457
# ==============================================================================
 
458
# USE the same .inc to cleanup before and after the test
 
459
--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
 
460
 
 
461
# ==============================================================================
 
462
let $message= .                               +++ END OF SCRIPT +++;
 
463
--source include/show_msg80.inc
 
464
# ==============================================================================