~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/r/innodb_storedproc_02.result

  • 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
 
 
2
--source suite/funcs_1/storedproc/load_sp_tb.inc
 
3
--------------------------------------------------------------------------------
 
4
 
 
5
--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
 
6
--------------------------------------------------------------------------------
 
7
DROP DATABASE IF EXISTS db_storedproc;
 
8
DROP DATABASE IF EXISTS db_storedproc_1;
 
9
CREATE DATABASE db_storedproc;
 
10
CREATE DATABASE db_storedproc_1;
 
11
USE db_storedproc;
 
12
create table t1(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = innodb;
 
13
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t1;
 
14
create table t2(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = innodb;
 
15
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t2;
 
16
create table t3(f1 char(20),f2 char(20),f3 integer) engine = innodb;
 
17
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t3.txt' into table t3;
 
18
create table t4(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = innodb;
 
19
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t4;
 
20
USE db_storedproc_1;
 
21
create table t6(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = innodb;
 
22
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t6;
 
23
USE db_storedproc;
 
24
create table t7 (f1 char(20), f2 char(25), f3 date, f4 int) engine = innodb;
 
25
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t7.txt' into table t7;
 
26
Warnings:
 
27
Warning 1265    Data truncated for column 'f3' at row 1
 
28
Warning 1265    Data truncated for column 'f3' at row 2
 
29
Warning 1265    Data truncated for column 'f3' at row 3
 
30
Warning 1265    Data truncated for column 'f3' at row 4
 
31
Warning 1265    Data truncated for column 'f3' at row 5
 
32
Warning 1265    Data truncated for column 'f3' at row 6
 
33
Warning 1265    Data truncated for column 'f3' at row 7
 
34
Warning 1265    Data truncated for column 'f3' at row 8
 
35
Warning 1265    Data truncated for column 'f3' at row 9
 
36
Warning 1265    Data truncated for column 'f3' at row 10
 
37
create table t8 (f1 char(20), f2 char(25), f3 date, f4 int) engine = innodb;
 
38
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t7.txt' into table t8;
 
39
Warnings:
 
40
Warning 1265    Data truncated for column 'f3' at row 1
 
41
Warning 1265    Data truncated for column 'f3' at row 2
 
42
Warning 1265    Data truncated for column 'f3' at row 3
 
43
Warning 1265    Data truncated for column 'f3' at row 4
 
44
Warning 1265    Data truncated for column 'f3' at row 5
 
45
Warning 1265    Data truncated for column 'f3' at row 6
 
46
Warning 1265    Data truncated for column 'f3' at row 7
 
47
Warning 1265    Data truncated for column 'f3' at row 8
 
48
Warning 1265    Data truncated for column 'f3' at row 9
 
49
Warning 1265    Data truncated for column 'f3' at row 10
 
50
create table t9(f1 int, f2 char(25), f3 int) engine = innodb;
 
51
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t9.txt' into table t9;
 
52
create table t10(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = innodb;
 
53
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t10;
 
54
create table t11(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int) engine = innodb;
 
55
load data infile 'MYSQL_TEST_DIR/suite/funcs_1/data/t4.txt' into table t11;
 
56
 
 
57
Section 3.1.2 - Syntax checks for the stored procedure-specific
 
58
programming statements BEGIN/END, DECLARE, SET, SELECT/INTO, OPEN, FETCH, CLOSE:
 
59
--------------------------------------------------------------------------------
 
60
 
 
61
Testcase 3.1.2.8:
 
62
-----------------
 
63
 
 
64
Ensure that the scope of each BEGIN/END compound statement within a stored
 
65
procedure definition is properly applied
 
66
--------------------------------------------------------------------------------
 
67
DROP PROCEDURE IF EXISTS sp1;
 
68
CREATE PROCEDURE sp1( )
 
69
begin_label: BEGIN
 
70
declare x char DEFAULT 'x';
 
71
declare y char DEFAULT 'y';
 
72
set x = '1';
 
73
set y = '2';
 
74
label1: BEGIN
 
75
declare x char DEFAULT 'X';
 
76
declare y char DEFAULT 'Y';
 
77
SELECT f1, f2 into x, y from t2 limit 1;
 
78
SELECT '1.1', x, y;
 
79
label2: BEGIN
 
80
declare x char default 'a';
 
81
declare y char default 'b';
 
82
label3: BEGIN
 
83
declare x char default 'c';
 
84
declare y char default 'd';
 
85
label4: BEGIN
 
86
declare x char default 'e';
 
87
declare y char default 'f';
 
88
label5: BEGIN
 
89
declare x char default 'g';
 
90
declare y char default 'h';
 
91
SELECT 5, x, y;
 
92
END label5;
 
93
SELECT 4, x, y;
 
94
END label4;
 
95
SELECT 3, x, y;
 
96
END label3;
 
97
SELECT 2, x, y;
 
98
END label2;
 
99
END label1;
 
100
set @v1 = x;
 
101
set @v2 = y;
 
102
SELECT '1.2', @v1, @v2;
 
103
END begin_label//
 
104
CALL sp1();
 
105
1.1     x       y
 
106
1.1     a       a
 
107
5       x       y
 
108
5       g       h
 
109
4       x       y
 
110
4       e       f
 
111
3       x       y
 
112
3       c       d
 
113
2       x       y
 
114
2       a       b
 
115
1.2     @v1     @v2
 
116
1.2     1       2
 
117
Warnings:
 
118
Warning 1265    Data truncated for column 'x' at row 1
 
119
Warning 1265    Data truncated for column 'y' at row 1
 
120
DROP PROCEDURE IF EXISTS sp1;
 
121
 
 
122
Testcase 3.1.2.26:
 
123
------------------
 
124
 
 
125
Ensure that the initial value of every variable declared for a stored procedure
 
126
is either NULL or its DEFAULT value, as appropriate.
 
127
--------------------------------------------------------------------------------
 
128
DROP PROCEDURE IF EXISTS sp1;
 
129
set @v1=0;
 
130
set @v2=0;
 
131
CREATE PROCEDURE sp1( )
 
132
BEGIN
 
133
declare x1 char default 'x';
 
134
declare y1 char;
 
135
declare x2 tinytext default 'tinytext';
 
136
declare y2 tinytext;
 
137
declare x3 datetime default '2005-10-03 12:13:14';
 
138
declare y3 datetime;
 
139
declare x4 float default 1.2;
 
140
declare y4 float;
 
141
declare x5 blob default 'b';
 
142
declare y5 blob;
 
143
declare x6 smallint default 127;
 
144
declare y6 smallint;
 
145
SELECT x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;
 
146
END//
 
147
CALL sp1();
 
148
x1      x2      x3      x4      x5      x6      y1      y2      y3      y4      y5      y6
 
149
x       tinytext        2005-10-03 12:13:14     1.2     b       127     NULL    NULL    NULL    NULL    NULL    NULL
 
150
DROP PROCEDURE sp1;
 
151
 
 
152
Testcase 3.1.2.30:
 
153
------------------
 
154
 
 
155
Ensure that, when a stored procedure is called/executed, every variable always
 
156
uses the correct value: either the value with which it is initialized or the
 
157
value to which it is subsequently SET or otherwise assigned, as appropriate.
 
158
--------------------------------------------------------------------------------
 
159
DROP PROCEDURE IF EXISTS sp1;
 
160
CREATE PROCEDURE sp1( IN invar INT, OUT outvar INT )
 
161
BEGIN
 
162
declare x integer;
 
163
declare y integer default 1;
 
164
set @x = x;
 
165
set @y = y;
 
166
set @z = 234;
 
167
SELECT f1, f2 into @x, @y from t2 where f1='a`' and f2='a`' limit 1;
 
168
SELECT @x, @y, @z, invar;
 
169
BEGIN
 
170
set @x = 2;
 
171
SELECT @x, @y, @z;
 
172
SET outvar = @x * invar + @z * @f;
 
173
SET invar = outvar;
 
174
BEGIN
 
175
set @y = null, @z = 'abcd';
 
176
SELECT @x, @y, @z;
 
177
END;
 
178
END;
 
179
END//
 
180
SET @invar  = 100;
 
181
SET @outvar = @invar;
 
182
SET @f      = 10;
 
183
SELECT @x, @y, @z, @invar, @outvar;
 
184
@x      @y      @z      @invar  @outvar
 
185
NULL    NULL    NULL    100     100
 
186
CALL sp1( @invar, @outvar );
 
187
@x      @y      @z      invar
 
188
a`      a`      234     100
 
189
@x      @y      @z
 
190
2       a`      234
 
191
@x      @y      @z
 
192
2       NULL    abcd
 
193
SELECT @x, @y, @z, @invar, @outvar;
 
194
@x      @y      @z      @invar  @outvar
 
195
2       NULL    abcd    100     2540
 
196
DROP PROCEDURE sp1;
 
197
 
 
198
Testcase 3.1.2.31:
 
199
------------------
 
200
 
 
201
Ensure that the SELECT ... INTO statement properly assigns values to the
 
202
variables in its variable list.
 
203
--------------------------------------------------------------------------------
 
204
DROP PROCEDURE IF EXISTS sp1;
 
205
CREATE PROCEDURE sp1( )
 
206
BEGIN
 
207
declare x integer; declare y integer;
 
208
set @x=x;
 
209
set @y=y;
 
210
SELECT f4, f3 into @x, @y from t2 where f4=-5000 and f3='1000-01-01' limit 1;
 
211
SELECT @x, @y;
 
212
END//
 
213
CALL sp1();
 
214
@x      @y
 
215
-5000   1000-01-01
 
216
DROP PROCEDURE sp1;
 
217
 
 
218
Testcase 3.1.2.32:
 
219
------------------
 
220
 
 
221
Ensure that a SELECT ... INTO statement that retrieves multiple rows is
 
222
rejected, with an appropriate error message.
 
223
--------------------------------------------------------------------------------
 
224
DROP PROCEDURE IF EXISTS sp1;
 
225
CREATE PROCEDURE sp1( )
 
226
BEGIN
 
227
declare x integer; declare y integer;
 
228
set @x=x;
 
229
set @y=y;
 
230
SELECT f4, f3 into @x, @y from t2;
 
231
END//
 
232
CALL sp1();
 
233
ERROR 42000: Result consisted of more than one row
 
234
DROP PROCEDURE sp1;
 
235
 
 
236
Testcase 3.1.2.33:
 
237
------------------
 
238
 
 
239
Ensure that a SELECT ... INTO statement that retrieves too many columns for the
 
240
number of variables in its variable list is rejected, with an appropriate error
 
241
message.
 
242
--------------------------------------------------------------------------------
 
243
DROP PROCEDURE IF EXISTS sp1;
 
244
CREATE PROCEDURE sp1( )
 
245
BEGIN
 
246
declare x integer; declare y integer;
 
247
set @x=x;
 
248
set @y=y;
 
249
SELECT f4, f3, f2, f1 into @x, @y from t2;
 
250
END//
 
251
CALL sp1();
 
252
ERROR 21000: The used SELECT statements have a different number of columns
 
253
DROP PROCEDURE sp1;
 
254
 
 
255
Testcase 3.1.2.34:
 
256
------------------
 
257
 
 
258
Ensure that a SELECT ... INTO statement that retrieves too few columns for the
 
259
number of variables in its variable list is rejected, with an appropriate error
 
260
message.
 
261
--------------------------------------------------------------------------------
 
262
DROP PROCEDURE IF EXISTS sp1;
 
263
CREATE PROCEDURE sp1( )
 
264
BEGIN
 
265
declare x integer; declare y integer; declare z integer;
 
266
set @x=x;
 
267
set @y=y;
 
268
set @z=z;
 
269
SELECT f4 into @x, @y, @z from t2;
 
270
END//
 
271
CALL sp1();
 
272
ERROR 21000: The used SELECT statements have a different number of columns
 
273
DROP PROCEDURE sp1;
 
274
 
 
275
Testcase 3.1.2.38:
 
276
------------------
 
277
 
 
278
Ensure that the scope of every condition declared is properly applied.
 
279
--------------------------------------------------------------------------------
 
280
DROP PROCEDURE IF EXISTS h1;
 
281
DROP TABLE IF EXISTS res_t1;
 
282
create table res_t1(w char unique, x char);
 
283
insert into res_t1 values('a', 'b');
 
284
CREATE PROCEDURE h1 ()
 
285
BEGIN
 
286
declare x1, x2, x3, x4, x5, x6 int default 0;
 
287
SELECT '-1-', x1, x2, x3, x4, x5, x6;
 
288
BEGIN
 
289
declare condname condition for sqlstate '23000';
 
290
declare continue handler for condname set x5 = 1;
 
291
set x6 = 0;
 
292
insert into res_t1 values ('a', 'b');
 
293
set x6 = 1;
 
294
SELECT '-2-', x1, x2, x3, x4, x5, x6;
 
295
END;
 
296
begin1_label: BEGIN
 
297
BEGIN
 
298
declare condname condition for sqlstate '20000';
 
299
declare continue handler for condname set x1 = 1;
 
300
set x2 = 0;
 
301
case x2
 
302
when 1 then set x2=10;
 
303
when 2 then set x2=11;
 
304
END case;
 
305
set x2 = 1;
 
306
SELECT '-3-', x1, x2, x3, x4, x5, x6;
 
307
begin2_label: BEGIN
 
308
BEGIN
 
309
declare condname condition for sqlstate '23000';
 
310
declare exit handler for condname set x3 = 1;
 
311
set x4= 1;
 
312
SELECT '-4a', x1, x2, x3, x4, x5, x6;
 
313
insert into res_t1 values ('a', 'b');
 
314
set x4= 2;
 
315
SELECT '-4b', x1, x2, x3, x4, x5, x6;
 
316
END;
 
317
SELECT '-5-', x1, x2, x3, x4, x5, x6;
 
318
END begin2_label;
 
319
SELECT '-6-', x1, x2, x3, x4, x5, x6;
 
320
END;
 
321
SELECT '-7-', x1, x2, x3, x4, x5, x6;
 
322
END begin1_label;
 
323
SELECT 'END', x1, x2, x3, x4, x5, x6;
 
324
END//
 
325
CALL h1();
 
326
-1-     x1      x2      x3      x4      x5      x6
 
327
-1-     0       0       0       0       0       0
 
328
-2-     x1      x2      x3      x4      x5      x6
 
329
-2-     0       0       0       0       1       1
 
330
-3-     x1      x2      x3      x4      x5      x6
 
331
-3-     1       1       0       0       1       1
 
332
-4a     x1      x2      x3      x4      x5      x6
 
333
-4a     1       1       0       1       1       1
 
334
-5-     x1      x2      x3      x4      x5      x6
 
335
-5-     1       1       1       1       1       1
 
336
-6-     x1      x2      x3      x4      x5      x6
 
337
-6-     1       1       1       1       1       1
 
338
-7-     x1      x2      x3      x4      x5      x6
 
339
-7-     1       1       1       1       1       1
 
340
END     x1      x2      x3      x4      x5      x6
 
341
END     1       1       1       1       1       1
 
342
DROP TABLE IF EXISTS tnull;
 
343
DROP PROCEDURE IF EXISTS sp1;
 
344
CREATE TABLE tnull(f1 int);
 
345
CREATE PROCEDURE sp1()
 
346
BEGIN
 
347
declare cond1 condition for sqlstate '42S02';
 
348
declare continue handler for cond1 set @var2 = 1;
 
349
BEGIN
 
350
declare cond1 condition for sqlstate '23000';
 
351
declare continue handler for cond1 set @var2 = 1;
 
352
END;
 
353
insert into tnull values(1);
 
354
END//
 
355
CALL sp1();
 
356
DROP PROCEDURE h1;
 
357
drop table res_t1;
 
358
DROP PROCEDURE sp1;
 
359
DROP TABLE tnull;
 
360
 
 
361
Testcase 3.1.2.43:
 
362
------------------
 
363
 
 
364
Ensure that the DECLARE ... HANDLER FOR statement can not declare any handler
 
365
for a condition declared outside of the scope of the handler.
 
366
--------------------------------------------------------------------------------
 
367
DROP PROCEDURE IF EXISTS h1;
 
368
DROP PROCEDURE IF EXISTS h2;
 
369
drop table IF EXISTS res_t1;
 
370
create table res_t1(w char unique, x char);
 
371
insert into res_t1 values ('a', 'b');
 
372
CREATE PROCEDURE h1 ()
 
373
BEGIN
 
374
declare x1, x2, x3, x4, x5, x6 int default 0;
 
375
BEGIN
 
376
declare cond_1 condition for sqlstate '23000';
 
377
declare continue handler for cond_1 set x5 = 1;
 
378
BEGIN
 
379
declare cond_2 condition for sqlstate '20000';
 
380
declare continue handler for cond_1 set x1 = 1;
 
381
BEGIN
 
382
declare continue handler for cond_2 set x3 = 1;
 
383
set x2 = 1;
 
384
END;
 
385
set x6 = 0;
 
386
END;
 
387
BEGIN
 
388
declare continue handler for cond_1 set x1 = 1;
 
389
BEGIN
 
390
declare continue handler for cond_2 set x3 = 1;
 
391
set x2 = 1;
 
392
END;
 
393
set x6 = 0;
 
394
END;
 
395
END;
 
396
SELECT x1, x2, x3, x4, x5, x6;
 
397
END//
 
398
ERROR 42000: Undefined CONDITION: cond_2
 
399
CREATE PROCEDURE h2 ()
 
400
BEGIN
 
401
declare x1, x2, x3, x4, x5, x6 int default 0;
 
402
BEGIN
 
403
declare condname condition for sqlstate '23000';
 
404
declare continue handler for condname set x5 = 1;
 
405
BEGIN
 
406
declare condname condition for sqlstate '20000';
 
407
declare continue handler for condname set x1 = 1;
 
408
BEGIN
 
409
declare condname condition for sqlstate '42000';
 
410
declare continue handler for condname set x3 = 1;
 
411
set x6 = 0;
 
412
insert into res_t1 values ('a', 'b');
 
413
set x6 = 1;
 
414
set x4= 0;
 
415
CALL sp1();
 
416
set x4= 1;
 
417
set x2 = 0;
 
418
case x2
 
419
when 1 then set x2=10;
 
420
when 2 then set x2=11;
 
421
END case;
 
422
set x2 = 1;
 
423
END;
 
424
set x2 = 0;
 
425
case x2
 
426
when 1 then set x2=10;
 
427
when 2 then set x2=11;
 
428
END case;
 
429
set x2 = 1;
 
430
set x6 = 0;
 
431
insert into res_t1 values ('a', 'b');
 
432
set x6 = 1;
 
433
END;
 
434
END;
 
435
SELECT x1, x2, x3, x4, x5, x6;
 
436
END//
 
437
CALL h2();
 
438
x1      x2      x3      x4      x5      x6
 
439
1       1       1       1       1       1
 
440
SELECT * FROM res_t1;
 
441
w       x
 
442
a       b
 
443
DROP PROCEDURE h2;
 
444
drop table res_t1;
 
445
 
 
446
Testcase 3.1.2.44:
 
447
------------------
 
448
 
 
449
Ensure that the DECLARE ... HANDLER FOR statement cannot declare a handler for
 
450
any invalid, or undeclared, condition.
 
451
--------------------------------------------------------------------------------
 
452
DROP PROCEDURE IF EXISTS h1;
 
453
CREATE PROCEDURE h1 ()
 
454
BEGIN
 
455
declare x1, x2, x3, x4, x5, x6 int default 0;
 
456
BEGIN
 
457
declare condname1 condition for sqlstate '23000';
 
458
BEGIN
 
459
declare condname2 condition for sqlstate '20000';
 
460
declare continue handler for condname1 set x3 = 1;
 
461
declare continue handler for condname2 set x1 = 1;
 
462
END;
 
463
END;
 
464
BEGIN
 
465
declare condname3 condition for sqlstate '42000';
 
466
declare continue handler for condname1 set x3 = 1;
 
467
declare continue handler for condname2 set x5 = 1;
 
468
declare continue handler for condname3 set x1 = 1;
 
469
END;
 
470
END//
 
471
ERROR 42000: Undefined CONDITION: condname1
 
472
CREATE PROCEDURE h1 ()
 
473
BEGIN
 
474
DECLARE x1 INT DEFAULT 0;
 
475
BEGIN
 
476
DECLARE condname1 CONDITION CHECK SQLSTATE '23000';
 
477
END;
 
478
DECLARE CONTINUE HANDLER FOR condname1 SET x1 = 1;
 
479
END//
 
480
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHECK SQLSTATE '23000';
 
481
END;
 
482
DECLARE CONTINUE HANDLER FOR condname1 SET x1 = 1;
 
483
' at line 5
 
484
CREATE PROCEDURE h1 ()
 
485
BEGIN
 
486
DECLARE x1 INT DEFAULT 0;
 
487
BEGIN
 
488
DECLARE condname1 CONDITION FOR SQLSTATE 'qwert';
 
489
END;
 
490
DECLARE CONTINUE HANDLER FOR condname1 SET x1 = 1;
 
491
END//
 
492
ERROR 42000: Bad SQLSTATE: 'qwert'
 
493
 
 
494
Testcase 3.1.2.45 + 3.1.2.50:
 
495
-----------------------------
 
496
 
 
497
45. Ensure that the scope of every handler declared is properly applied.
 
498
50. Ensure that a CONTINUE handler allows the execution of the stored procedure
 
499
.   to continue once the handler statement has completed its own execution (that
 
500
.   is, once the handler action statement has been executed).
 
501
--------------------------------------------------------------------------------
 
502
DROP PROCEDURE IF EXISTS p1;
 
503
DROP PROCEDURE IF EXISTS p1undo;
 
504
DROP PROCEDURE IF EXISTS h1;
 
505
DROP PROCEDURE IF EXISTS sp1;
 
506
drop table IF EXISTS res_t1;
 
507
==> 'UNDO' is still not supported.
 
508
create procedure p1undo ()
 
509
begin
 
510
declare undo handler for sqlexception select '1';
 
511
select * from tqq;
 
512
SELECT 'end of 1';
 
513
end;//
 
514
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'undo handler for sqlexception select '1';
 
515
select * from tqq;
 
516
SELECT 'end of 1';
 
517
' at line 3
 
518
create procedure p1 ()
 
519
begin
 
520
declare exit handler for sqlexception select 'exit handler 1';
 
521
begin
 
522
declare exit handler for sqlexception select 'exit handler 2';
 
523
begin
 
524
declare continue handler for sqlexception select 'continue handler 3';
 
525
drop table if exists tqq;
 
526
select * from tqq;
 
527
SELECT 'end of BEGIN/END 3';
 
528
end;
 
529
drop table if exists tqq;
 
530
select * from tqq;
 
531
SELECT 'end of BEGIN/END 2';
 
532
end;
 
533
select * from tqq;
 
534
SELECT 'end of BEGIN/END 1';
 
535
end;//
 
536
call p1()//
 
537
continue handler 3
 
538
continue handler 3
 
539
end of BEGIN/END 3
 
540
end of BEGIN/END 3
 
541
exit handler 2
 
542
exit handler 2
 
543
exit handler 1
 
544
exit handler 1
 
545
Warnings:
 
546
Note    1051    Unknown table 'tqq'
 
547
Note    1051    Unknown table 'tqq'
 
548
create table res_t1(w char unique, x char);
 
549
insert into res_t1 values ('a', 'b');
 
550
CREATE PROCEDURE h1 ()
 
551
BEGIN
 
552
declare x1, x2, x3, x4, x5, x6 int default 0;
 
553
BEGIN
 
554
declare continue handler for sqlstate '23000' set x5 = 1;
 
555
insert into res_t1 values ('a', 'b');
 
556
set x6 = 1;
 
557
END;
 
558
begin1_label: BEGIN
 
559
BEGIN
 
560
declare continue handler for sqlstate '23000' set x1 = 1;
 
561
insert into res_t1 values ('a', 'b');
 
562
set x2 = 1;
 
563
begin2_label: BEGIN
 
564
BEGIN
 
565
declare exit handler for sqlstate '23000' set x3 = 1;
 
566
set x4= 1;
 
567
insert into res_t1 values ('a', 'b');
 
568
set x4= 0;
 
569
END;
 
570
END begin2_label;
 
571
END;
 
572
END begin1_label;
 
573
SELECT x1, x2, x3, x4, x5, x6;
 
574
END//
 
575
CALL h1();
 
576
x1      x2      x3      x4      x5      x6
 
577
1       1       1       1       1       1
 
578
CREATE PROCEDURE sp1()
 
579
begin1_label:BEGIN
 
580
declare exit handler for sqlstate '00000' set @var1 = 5;
 
581
set @var2 = 6;
 
582
begin2_label:BEGIN
 
583
declare continue handler for sqlstate '00000' set @var3 = 7;
 
584
set @var4 = 8;
 
585
SELECT @var3, @var4;
 
586
END begin2_label;
 
587
SELECT @var1, @var2;
 
588
END begin1_label//
 
589
CALL sp1();
 
590
@var3   @var4
 
591
NULL    8
 
592
@var1   @var2
 
593
NULL    6
 
594
DROP PROCEDURE p1;
 
595
DROP PROCEDURE h1;
 
596
DROP PROCEDURE sp1;
 
597
DROP TABLE res_t1;
 
598
 
 
599
Testcase 3.1.2.50:
 
600
------------------
 
601
DROP PROCEDURE IF EXISTS sp1;
 
602
DROP PROCEDURE IF EXISTS sp2;
 
603
CREATE PROCEDURE sp1 (x int, y int)
 
604
BEGIN
 
605
set @y=0;
 
606
END//
 
607
CREATE PROCEDURE sp2 ()
 
608
BEGIN
 
609
declare continue handler for sqlstate '42000' set @x2 = 1;
 
610
set @x=1;
 
611
SELECT @x2;
 
612
CALL sp1(1);
 
613
set @x=2;
 
614
SELECT @x2, @x;
 
615
END//
 
616
CALL sp2();
 
617
@x2
 
618
NULL
 
619
@x2     @x
 
620
1       2
 
621
DROP PROCEDURE sp1;
 
622
DROP PROCEDURE sp2;
 
623
 
 
624
Testcase 3.2.2.51:
 
625
------------------
 
626
 
 
627
Ensure that an EXIT handler causes the execution of the stored procedure to
 
628
terminate, within its scope, once the handler action statement has been
 
629
executed.
 
630
--------------------------------------------------------------------------------
 
631
DROP PROCEDURE IF EXISTS sp1;
 
632
DROP PROCEDURE IF EXISTS sp2;
 
633
CREATE PROCEDURE sp1 (x int, y int)
 
634
BEGIN
 
635
set @x=0;
 
636
END//
 
637
CREATE PROCEDURE sp2 ()
 
638
BEGIN
 
639
declare exit handler for sqlstate '42000' set @x2 = 1;
 
640
set @x2=0;
 
641
set @x=1;
 
642
SELECT '-1-', @x2, @x;
 
643
CALL sp1(1);
 
644
SELECT '-2-', @x2, @x;
 
645
set @x=2;
 
646
END//
 
647
CALL sp1(1);
 
648
ERROR 42000: Incorrect number of arguments for PROCEDURE db_storedproc.sp1; expected 2, got 1
 
649
CALL sp2();
 
650
-1-     @x2     @x
 
651
-1-     0       1
 
652
SELECT '-3-', @x2, @x;
 
653
-3-     @x2     @x
 
654
-3-     1       1
 
655
DROP PROCEDURE sp1;
 
656
DROP PROCEDURE sp2;
 
657
 
 
658
Testcase 3.1.2.52:
 
659
------------------
 
660
 
 
661
Ensure that an EXIT handler does not cause the execution of the stored procedure
 
662
to terminate outside of its scope.
 
663
--------------------------------------------------------------------------------
 
664
DROP PROCEDURE IF EXISTS sp1;
 
665
DROP PROCEDURE IF EXISTS sp2;
 
666
CREATE PROCEDURE sp1 (x int, y int)
 
667
BEGIN
 
668
set @x=0;
 
669
END//
 
670
CREATE PROCEDURE sp2()
 
671
BEGIN
 
672
declare continue handler for sqlstate '42000' set @x2 = 2;
 
673
set @x2 = 1;
 
674
set @x =20;
 
675
SELECT '-1-', @x2, @x;
 
676
BEGIN
 
677
declare exit handler for sqlstate '42000' set @x2 = 11;
 
678
SELECT '-2-', @x2, @x;
 
679
CALL sp1(1);
 
680
SELECT '-3a', @x2, @x;
 
681
set @x=21;
 
682
SELECT '-3b', @x2, @x;
 
683
END;
 
684
set @x=22;
 
685
SELECT '-4-', @x2, @x;
 
686
END//
 
687
CALL sp2();
 
688
-1-     @x2     @x
 
689
-1-     1       20
 
690
-2-     @x2     @x
 
691
-2-     1       20
 
692
-4-     @x2     @x
 
693
-4-     11      22
 
694
DROP PROCEDURE sp1;
 
695
DROP PROCEDURE sp2;
 
696
 
 
697
Testcase 3.1.2.54:
 
698
------------------
 
699
 
 
700
Ensure that a handler with a condition defined with an SQLSTATE that begins with
 
701
ďż˝01ďż˝ is always exactly equivalent in action to a handler with an SQLWARNING
 
702
condition.
 
703
--------------------------------------------------------------------------------
 
704
DROP PROCEDURE IF EXISTS sp0;
 
705
DROP PROCEDURE IF EXISTS sp1;
 
706
DROP PROCEDURE IF EXISTS sp2;
 
707
DROP PROCEDURE IF EXISTS sp3;
 
708
DROP PROCEDURE IF EXISTS sp4;
 
709
DROP TABLE IF EXISTS temp;
 
710
CREATE TABLE temp( f1 CHAR, f2 CHAR);
 
711
CREATE PROCEDURE sp0()
 
712
BEGIN
 
713
set @done=0;
 
714
set @x=0;
 
715
insert into temp values('xxx', 'yy');
 
716
set @x=1;
 
717
END//
 
718
CREATE PROCEDURE sp1()
 
719
BEGIN
 
720
declare continue handler for sqlstate '01000' set @done = 1;
 
721
set @done=0;
 
722
set @x=0;
 
723
insert into temp values('xxx', 'yy');
 
724
set @x=1;
 
725
END//
 
726
CREATE PROCEDURE sp2()
 
727
BEGIN
 
728
declare continue handler for sqlwarning set @done = 1;
 
729
set @done=0;
 
730
set @x=0;
 
731
insert into temp values('xxx', 'yy');
 
732
set @x=1;
 
733
END//
 
734
CREATE PROCEDURE sp3()
 
735
BEGIN
 
736
declare exit handler for sqlstate '01000' set @done = 1;
 
737
set @done=0;
 
738
set @x=0;
 
739
insert into temp values('xxx', 'yy');
 
740
set @x=1;
 
741
END//
 
742
CREATE PROCEDURE sp4()
 
743
BEGIN
 
744
declare exit handler for sqlwarning set @done = 1;
 
745
set @done=0;
 
746
set @x=0;
 
747
insert into temp values('xxx', 'yy');
 
748
set @x=1;
 
749
END//
 
750
INSERT INTO temp VALUES('0', NULL);
 
751
CALL sp0();
 
752
Warnings:
 
753
Warning 1265    Data truncated for column 'f1' at row 1
 
754
Warning 1265    Data truncated for column 'f2' at row 1
 
755
SELECT @done, @x;
 
756
@done   @x
 
757
0       1
 
758
INSERT INTO temp VALUES('1', NULL);
 
759
CALL sp1();
 
760
SELECT @done, @x;
 
761
@done   @x
 
762
1       1
 
763
INSERT INTO temp VALUES('2', NULL);
 
764
CALL sp2();
 
765
SELECT @done, @x;
 
766
@done   @x
 
767
1       1
 
768
INSERT INTO temp VALUES('3', NULL);
 
769
CALL sp3();
 
770
SELECT @done, @x;
 
771
@done   @x
 
772
1       0
 
773
INSERT INTO temp VALUES('4', NULL);
 
774
CALL sp4();
 
775
SELECT @done, @x;
 
776
@done   @x
 
777
1       0
 
778
SELECT * FROM temp;
 
779
f1      f2
 
780
0       NULL
 
781
x       y
 
782
1       NULL
 
783
x       y
 
784
2       NULL
 
785
x       y
 
786
3       NULL
 
787
x       y
 
788
4       NULL
 
789
x       y
 
790
DROP PROCEDURE sp1;
 
791
DROP PROCEDURE sp2;
 
792
DROP PROCEDURE sp3;
 
793
DROP PROCEDURE sp4;
 
794
DROP TABLE temp;
 
795
 
 
796
Testcase 3.1.2.56:
 
797
------------------
 
798
 
 
799
Ensure that a handler with a condition defined with an SQLSTATE that begins with
 
800
ďż˝02ďż˝ is always exactly equivalent in action to a handler with a NOT FOUND
 
801
condition.
 
802
--------------------------------------------------------------------------------
 
803
DROP PROCEDURE IF EXISTS sp0;
 
804
DROP PROCEDURE IF EXISTS sp1;
 
805
DROP PROCEDURE IF EXISTS sp2;
 
806
DROP PROCEDURE IF EXISTS sp3;
 
807
DROP PROCEDURE IF EXISTS sp4;
 
808
CREATE PROCEDURE sp0()
 
809
BEGIN
 
810
DECLARE f1_value CHAR(20);
 
811
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
812
SET @done = 0;
 
813
SET @x = 0;
 
814
OPEN cur1;
 
815
FETCH cur1 INTO f1_value;
 
816
SET @x = 1;
 
817
FETCH cur1 INTO f1_value;
 
818
SET @x = 2;
 
819
CLOSE cur1;
 
820
END//
 
821
CREATE PROCEDURE sp1()
 
822
BEGIN
 
823
DECLARE f1_value CHAR(20);
 
824
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
825
declare continue handler for sqlstate '02000' set @done = 1;
 
826
SET @done = 0;
 
827
SET @x = 0;
 
828
OPEN cur1;
 
829
FETCH cur1 INTO f1_value;
 
830
SET @x = 1;
 
831
FETCH cur1 INTO f1_value;
 
832
SET @x = 2;
 
833
CLOSE cur1;
 
834
END//
 
835
CREATE PROCEDURE sp2()
 
836
BEGIN
 
837
DECLARE f1_value CHAR(20);
 
838
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
839
declare continue handler for not found set @done = 1;
 
840
SET @done = 0;
 
841
SET @x = 0;
 
842
OPEN cur1;
 
843
FETCH cur1 INTO f1_value;
 
844
SET @x = 1;
 
845
FETCH cur1 INTO f1_value;
 
846
SET @x = 2;
 
847
CLOSE cur1;
 
848
END//
 
849
CREATE PROCEDURE sp3()
 
850
BEGIN
 
851
DECLARE f1_value CHAR(20);
 
852
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
853
declare exit handler for sqlstate '02000' set @done = 1;
 
854
SET @done = 0;
 
855
SET @x = 0;
 
856
OPEN cur1;
 
857
FETCH cur1 INTO f1_value;
 
858
SET @x = 1;
 
859
FETCH cur1 INTO f1_value;
 
860
SET @x = 2;
 
861
CLOSE cur1;
 
862
END//
 
863
CREATE PROCEDURE sp4()
 
864
BEGIN
 
865
DECLARE f1_value CHAR(20);
 
866
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
867
declare exit handler for not found set @done = 1;
 
868
SET @done = 0;
 
869
SET @x = 0;
 
870
OPEN cur1;
 
871
FETCH cur1 INTO f1_value;
 
872
SET @x = 1;
 
873
FETCH cur1 INTO f1_value;
 
874
SET @x = 2;
 
875
CLOSE cur1;
 
876
END//
 
877
CALL sp0();
 
878
ERROR 02000: No data - zero rows fetched, selected, or processed
 
879
SELECT @done, @x;
 
880
@done   @x
 
881
0       1
 
882
CALL sp1();
 
883
SELECT @done, @x;
 
884
@done   @x
 
885
1       2
 
886
CALL sp2();
 
887
SELECT @done, @x;
 
888
@done   @x
 
889
1       2
 
890
CALL sp3();
 
891
SELECT @done, @x;
 
892
@done   @x
 
893
1       1
 
894
CALL sp4();
 
895
SELECT @done, @x;
 
896
@done   @x
 
897
1       1
 
898
DROP PROCEDURE sp0;
 
899
DROP PROCEDURE sp1;
 
900
DROP PROCEDURE sp2;
 
901
DROP PROCEDURE sp3;
 
902
DROP PROCEDURE sp4;
 
903
 
 
904
Testcase 3.1.2.58:
 
905
------------------
 
906
 
 
907
Ensure that a handler with a condition defined with an SQLSTATE that begins with
 
908
anything other that ďż˝01ďż˝ or ďż˝02ďż˝ is always exactly equivalent in action to a
 
909
handler with an SQLEXCEPTION condition.
 
910
--------------------------------------------------------------------------------
 
911
DROP PROCEDURE IF EXISTS sp0;
 
912
DROP PROCEDURE IF EXISTS sp1;
 
913
DROP PROCEDURE IF EXISTS sp2;
 
914
DROP PROCEDURE IF EXISTS sp3;
 
915
DROP PROCEDURE IF EXISTS sp4;
 
916
CREATE PROCEDURE sp0()
 
917
BEGIN
 
918
DECLARE f1_value CHAR(20);
 
919
DECLARE cv INT DEFAULT 0;
 
920
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
921
SET @x = 1;
 
922
CASE cv
 
923
WHEN 2 THEN SET @x = 2;
 
924
WHEN 3 THEN SET @x = 3;
 
925
END case;
 
926
SET @x = 4;
 
927
SELECT f1, f2 FROM t2
 
928
UNION
 
929
SELECT f1, f2,3 FROM t2;
 
930
SET @x = 5;
 
931
FETCH cur1 INTO f1_value;
 
932
SET @x = 6;
 
933
END//
 
934
CREATE PROCEDURE sp1()
 
935
BEGIN
 
936
DECLARE f1_value CHAR(20);
 
937
DECLARE cv INT DEFAULT 0;
 
938
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
939
DECLARE continue HANDLER FOR SQLSTATE '20000' SELECT '20000' AS 'SQLSTATE';
 
940
DECLARE continue HANDLER FOR SQLSTATE '21000' SELECT '21000' AS 'SQLSTATE';
 
941
DECLARE continue HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
 
942
SET @x = 1;
 
943
CASE cv
 
944
WHEN 2 THEN SET @x = 2;
 
945
WHEN 3 THEN SET @x = 3;
 
946
END case;
 
947
SET @x = 4;
 
948
SELECT f1, f2 FROM t2
 
949
UNION
 
950
SELECT f1, f2,3 FROM t2;
 
951
SET @x = 5;
 
952
FETCH cur1 INTO f1_value;
 
953
SET @x = 6;
 
954
END//
 
955
CREATE PROCEDURE sp2()
 
956
BEGIN
 
957
DECLARE f1_value CHAR(20);
 
958
DECLARE cv INT DEFAULT 0;
 
959
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
960
DECLARE continue HANDLER FOR SQLEXCEPTION SELECT 'SQLEXCEPTION' AS 'SQLSTATE';
 
961
DECLARE continue HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
 
962
SET @x = 1;
 
963
CASE cv
 
964
WHEN 2 THEN SET @x = 2;
 
965
WHEN 3 THEN SET @x = 3;
 
966
END case;
 
967
SET @x = 4;
 
968
SELECT f1, f2 FROM t2
 
969
UNION
 
970
SELECT f1, f2,3 FROM t2;
 
971
SET @x = 5;
 
972
FETCH cur1 INTO f1_value;
 
973
SET @x = 6;
 
974
END//
 
975
CREATE PROCEDURE sp3()
 
976
BEGIN
 
977
DECLARE f1_value CHAR(20);
 
978
DECLARE cv INT DEFAULT 0;
 
979
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
980
DECLARE EXIT HANDLER FOR SQLSTATE '20000' SELECT '20000' AS 'SQLSTATE';
 
981
DECLARE EXIT HANDLER FOR SQLSTATE '21000' SELECT '21000' AS 'SQLSTATE';
 
982
DECLARE EXIT HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
 
983
SET @x = 1;
 
984
CASE cv
 
985
WHEN 2 THEN SET @x = 2;
 
986
WHEN 3 THEN SET @x = 3;
 
987
END case;
 
988
SET @x = 4;
 
989
SELECT f1, f2 FROM t2
 
990
UNION
 
991
SELECT f1, f2,3 FROM t2;
 
992
SET @x = 5;
 
993
FETCH cur1 INTO f1_value;
 
994
SET @x = 6;
 
995
END//
 
996
CREATE PROCEDURE sp4()
 
997
BEGIN
 
998
DECLARE f1_value CHAR(20);
 
999
DECLARE cv INT DEFAULT 0;
 
1000
DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
 
1001
DECLARE EXIT HANDLER FOR SQLEXCEPTION SELECT 'SQLEXCEPTION' AS 'SQLSTATE';
 
1002
DECLARE EXIT HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
 
1003
SET @x = 1;
 
1004
CASE cv
 
1005
WHEN 2 THEN SET @x = 2;
 
1006
WHEN 3 THEN SET @x = 3;
 
1007
END case;
 
1008
SET @x = 4;
 
1009
SELECT f1, f2 FROM t2
 
1010
UNION
 
1011
SELECT f1, f2,3 FROM t2;
 
1012
SET @x = 5;
 
1013
FETCH cur1 INTO f1_value;
 
1014
SET @x = 6;
 
1015
CLOSE cur1;
 
1016
END//
 
1017
CALL sp0();
 
1018
ERROR 20000: Case not found for CASE statement
 
1019
SELECT '-0-', @x;
 
1020
-0-     @x
 
1021
-0-     1
 
1022
CALL sp1();
 
1023
SQLSTATE
 
1024
20000
 
1025
SQLSTATE
 
1026
21000
 
1027
SQLSTATE
 
1028
24000
 
1029
SELECT '-1-', @x;
 
1030
-1-     @x
 
1031
-1-     6
 
1032
CALL sp2();
 
1033
SQLSTATE
 
1034
SQLEXCEPTION
 
1035
SQLSTATE
 
1036
SQLEXCEPTION
 
1037
SQLSTATE
 
1038
24000
 
1039
SELECT '-2-', @x;
 
1040
-2-     @x
 
1041
-2-     6
 
1042
CALL sp3();
 
1043
SQLSTATE
 
1044
20000
 
1045
SELECT '-3-', @x;
 
1046
-3-     @x
 
1047
-3-     1
 
1048
CALL sp4();
 
1049
SQLSTATE
 
1050
SQLEXCEPTION
 
1051
SELECT '-4-', @x;
 
1052
-4-     @x
 
1053
-4-     1
 
1054
DROP PROCEDURE sp0;
 
1055
DROP PROCEDURE sp1;
 
1056
DROP PROCEDURE sp2;
 
1057
DROP PROCEDURE sp3;
 
1058
DROP PROCEDURE sp4;
 
1059
 
 
1060
Testcase 3.1.2.65:
 
1061
------------------
 
1062
 
 
1063
Ensure that FETCH <cursor name> returns the first row of the cursor_s result set
 
1064
the first time FETCH is executed, that it returns each subsequent row of the
 
1065
cursor_s result set each of the subsequent times FETCH is executed, and that it
 
1066
returns a NOT FOUND warning if it is executed after the last row of the cursor_s
 
1067
result set has already been fetched.
 
1068
--------------------------------------------------------------------------------
 
1069
DROP PROCEDURE IF EXISTS sp1;
 
1070
DROP TABLE IF EXISTS temp;
 
1071
CREATE TABLE temp(
 
1072
cnt INT,
 
1073
f1 CHAR(20),
 
1074
f2 CHAR(20),
 
1075
f3 INT,
 
1076
f4 CHAR(20),
 
1077
f5 INT);
 
1078
INSERT INTO temp VALUES(0, 'onip', 'abc', 8760, 'xyz', 10);
 
1079
CREATE PROCEDURE sp1( )
 
1080
BEGIN
 
1081
declare proceed int default 1;
 
1082
declare count integer default 1;
 
1083
declare f1_value char(20);
 
1084
declare f2_value char(20);
 
1085
declare f5_value char(20);
 
1086
declare f4_value integer;
 
1087
declare f6_value integer;
 
1088
declare cur1 cursor for SELECT f1, f2, f4, f5, f6 from t2
 
1089
where f4 >=-5000 order by f4 limit 3;
 
1090
open cur1;
 
1091
while proceed do
 
1092
SELECT count AS 'loop';
 
1093
fetch cur1 into f1_value, f2_value, f4_value, f5_value, f6_value;
 
1094
insert into temp values (count, f1_value, f2_value, f4_value, f5_value, f6_value);
 
1095
set count = count + 1;
 
1096
END while;
 
1097
END//
 
1098
CALL sp1();
 
1099
loop
 
1100
1
 
1101
loop
 
1102
2
 
1103
loop
 
1104
3
 
1105
loop
 
1106
4
 
1107
ERROR 02000: No data - zero rows fetched, selected, or processed
 
1108
SELECT * FROM temp;
 
1109
cnt     f1      f2      f3      f4      f5
 
1110
0       onip    abc     8760    xyz     10
 
1111
1       a`      a`      -5000   a`      -5000
 
1112
2       aaa     aaa     -4999   aaa     -4999
 
1113
3       abaa    abaa    -4998   abaa    -4998
 
1114
DROP TABLE temp;
 
1115
DROP PROCEDURE sp1;
 
1116
 
 
1117
Testcase 3.1.2.68:
 
1118
------------------
 
1119
 
 
1120
Ensure that FETCH <cursor name> fails with an appropriate error message if the
 
1121
number of columns to be fetched does not match the number of variables specified
 
1122
by the FETCH statement.
 
1123
--------------------------------------------------------------------------------
 
1124
DROP PROCEDURE IF EXISTS sp1;
 
1125
DROP PROCEDURE IF EXISTS sp2;
 
1126
--> not enough columns in FETCH statement
 
1127
CREATE PROCEDURE sp1( )
 
1128
BEGIN
 
1129
declare newf1 char(20);
 
1130
declare cur1 cursor for SELECT f1, f2 from t2 limit 10;
 
1131
declare continue handler for sqlstate '02000' SELECT 'HANDLER executed.' AS '';
 
1132
BEGIN
 
1133
open cur1;
 
1134
fetch cur1 into newf1;
 
1135
SELECT newf1;
 
1136
close cur1;
 
1137
END;
 
1138
END//
 
1139
--> too many columns in FETCH statement
 
1140
CREATE PROCEDURE sp2( )
 
1141
BEGIN
 
1142
declare newf1 char(20);
 
1143
declare newf2 char(20);
 
1144
declare cur1 cursor for SELECT f1 from t2 limit 10;
 
1145
declare continue handler for sqlstate '02000' SELECT 'HANDLER executed.' AS '';
 
1146
BEGIN
 
1147
open cur1;
 
1148
fetch cur1 into newf1, newf2;
 
1149
SELECT newf1, newf2;
 
1150
close cur1;
 
1151
END;
 
1152
END//
 
1153
--> not enough columns in FETCH statement
 
1154
CALL sp1();
 
1155
ERROR HY000: Incorrect number of FETCH variables
 
1156
--> too many columns in FETCH statement
 
1157
CALL sp2();
 
1158
ERROR HY000: Incorrect number of FETCH variables
 
1159
DROP PROCEDURE sp1;
 
1160
DROP PROCEDURE sp2;
 
1161
 
 
1162
Testcase 3.1.2.75:
 
1163
------------------
 
1164
 
 
1165
Ensure that, for nested compound statements, a cursor that was declared and
 
1166
opened during an outer level of the statement is not closed when an inner level
 
1167
of a compound statement ends.
 
1168
--------------------------------------------------------------------------------
 
1169
DROP TABLE IF EXISTS temp1;
 
1170
DROP PROCEDURE IF EXISTS sp1;
 
1171
create table temp1( f0 char(20), f1 char(20), f2 char(20), f3 int, f4 char(20) );
 
1172
SELECT f1, f2, f4, f5 from t2 order by f4;
 
1173
f1      f2      f4      f5
 
1174
a`      a`      -5000   a`
 
1175
aaa     aaa     -4999   aaa
 
1176
abaa    abaa    -4998   abaa
 
1177
acaaa   acaaa   -4997   acaaa
 
1178
adaaaa  adaaaa  -4996   adaaaa
 
1179
aeaaaaa aeaaaaa -4995   aeaaaaa
 
1180
afaaaaaa        afaaaaaa        -4994   afaaaaaa
 
1181
agaaaaaaa       agaaaaaaa       -4993   agaaaaaaa
 
1182
a^aaaaaaaa      a^aaaaaaaa      -4992   a^aaaaaaaa
 
1183
a_aaaaaaaaa     a_aaaaaaaaa     -4991   a_aaaaaaaaa
 
1184
CREATE PROCEDURE sp1( )
 
1185
BEGIN
 
1186
declare count integer;
 
1187
declare from0 char(20);
 
1188
declare newf1 char(20);
 
1189
declare newf2 char(20);
 
1190
declare newf5 char(20);
 
1191
declare newf4 integer;
 
1192
declare cur1 cursor for SELECT f1, f2, f4, f5 from t2 where f4 >= -5000 order by f4 limit 5;
 
1193
declare cur2 cursor for SELECT f1, f2, f4, f5 from t2 where f4 >= -5000 order by f4 limit 5;
 
1194
open cur1;
 
1195
open cur2;
 
1196
BEGIN
 
1197
declare continue handler for sqlstate '02000' set count=1;
 
1198
fetch cur1 into newf1, newf2, newf4, newf5;
 
1199
SELECT '-1-', count, newf1, newf2, newf4, newf5;
 
1200
insert into temp1 values ('cur1_out', newf1, newf2, newf4, newf5);
 
1201
set count= 4;
 
1202
BEGIN
 
1203
while count> 0 do
 
1204
fetch cur1 into newf1, newf2, newf4, newf5;
 
1205
SELECT '-2-', count, newf1, newf2, newf4, newf5;
 
1206
set count = count- 1;
 
1207
END while;
 
1208
SELECT '-3-', count, newf1, newf2, newf4, newf4;
 
1209
END;
 
1210
BEGIN
 
1211
fetch cur1 into newf1, newf2, newf4, newf5;
 
1212
SELECT '-4-', newf1, newf2, newf4, newf5;
 
1213
insert into temp1 values ('cur1_in', newf1, newf2, newf4, newf5);
 
1214
END;
 
1215
fetch cur2 into newf1, newf2, newf4, newf5;
 
1216
SELECT '-5-', newf1, newf2, newf4, newf5;
 
1217
insert into temp1 values ('cur2', newf1, newf2, newf4, newf5);
 
1218
close cur1;
 
1219
END;
 
1220
fetch cur2 into newf1, newf2, newf4, newf5;
 
1221
SELECT '-6-', newf1, newf2, newf4, newf5;
 
1222
close cur2;
 
1223
END//
 
1224
CALL sp1();
 
1225
-1-     count   newf1   newf2   newf4   newf5
 
1226
-1-     NULL    a`      a`      -5000   a`
 
1227
-2-     count   newf1   newf2   newf4   newf5
 
1228
-2-     4       aaa     aaa     -4999   aaa
 
1229
-2-     count   newf1   newf2   newf4   newf5
 
1230
-2-     3       abaa    abaa    -4998   abaa
 
1231
-2-     count   newf1   newf2   newf4   newf5
 
1232
-2-     2       acaaa   acaaa   -4997   acaaa
 
1233
-2-     count   newf1   newf2   newf4   newf5
 
1234
-2-     1       adaaaa  adaaaa  -4996   adaaaa
 
1235
-3-     count   newf1   newf2   newf4   newf4
 
1236
-3-     0       adaaaa  adaaaa  -4996   -4996
 
1237
-4-     newf1   newf2   newf4   newf5
 
1238
-4-     adaaaa  adaaaa  -4996   adaaaa
 
1239
-5-     newf1   newf2   newf4   newf5
 
1240
-5-     a`      a`      -5000   a`
 
1241
-6-     newf1   newf2   newf4   newf5
 
1242
-6-     aaa     aaa     -4999   aaa
 
1243
SELECT * from temp1;
 
1244
f0      f1      f2      f3      f4
 
1245
cur1_out        a`      a`      -5000   a`
 
1246
cur1_in adaaaa  adaaaa  -4996   adaaaa
 
1247
cur2    a`      a`      -5000   a`
 
1248
DROP PROCEDURE sp1;
 
1249
drop table temp1;
 
1250
 
 
1251
Testcase 3.1.2.76:
 
1252
------------------
 
1253
 
 
1254
Ensure that all cursors operate asensitively, so that there is no concurrency
 
1255
conflict between cursors operating on the same, or similar, sets of results
 
1256
during execution of one or more stored procedures.
 
1257
--------------------------------------------------------------------------------
 
1258
DROP PROCEDURE IF EXISTS sp1;
 
1259
drop table IF EXISTS temp1;
 
1260
drop table IF EXISTS temp2;
 
1261
create table temp1( f0 char(10), cnt int, f1 char(20), f2 char(20), f3 date, f4 integer );
 
1262
create table temp2( f0 char(10), cnt int, f1 char(20), f2 char(20), f3 date, f4 integer );
 
1263
CREATE PROCEDURE sp_inner( )
 
1264
BEGIN
 
1265
declare proceed int default 1;
 
1266
declare i_count integer default 20;
 
1267
declare i_newf1 char(20);
 
1268
declare i_newf2 char(20);
 
1269
declare i_newf3 date;
 
1270
declare i_newf4 integer;
 
1271
declare i_newf11 char(20);
 
1272
declare i_newf12 char(20);
 
1273
declare i_newf13 date;
 
1274
declare i_newf14 integer;
 
1275
declare cur1 cursor for SELECT f1, f2, f3, f4 from t2
 
1276
where f4>=-5000 order by f4 limit 4;
 
1277
declare cur2 cursor for SELECT f1, f2, f3, f4 from t2
 
1278
where f4>=-5000 order by f4 limit 3;
 
1279
declare continue handler for sqlstate '02000' set proceed=0;
 
1280
open cur1;
 
1281
open cur2;
 
1282
set i_count = 10;
 
1283
while proceed do
 
1284
fetch cur1 into i_newf1, i_newf2, i_newf3, i_newf4;
 
1285
IF proceed THEN
 
1286
insert into temp1 values ('sp_inner', i_count, i_newf1, i_newf2, i_newf3, i_newf4);
 
1287
fetch cur2 into i_newf11, i_newf12, i_newf13, i_newf14;
 
1288
IF proceed THEN
 
1289
insert into temp2 values ('sp_inner', i_count, i_newf11, i_newf12, i_newf13, i_newf14);
 
1290
END IF;
 
1291
END IF;
 
1292
set i_count = i_count - 1;
 
1293
END while;
 
1294
close cur1;
 
1295
close cur2;
 
1296
END//
 
1297
CREATE PROCEDURE sp_outer( )
 
1298
BEGIN
 
1299
DECLARE proceed INT DEFAULT 1;
 
1300
DECLARE o_count INTEGER DEFAULT 20;
 
1301
DECLARE o_newf1 CHAR(20);
 
1302
DECLARE o_newf2 CHAR(20);
 
1303
DECLARE o_newf3 DATE;
 
1304
DECLARE o_newf4 INTEGER;
 
1305
DECLARE o_newf11 CHAR(20);
 
1306
DECLARE o_newf12 CHAR(20);
 
1307
DECLARE o_newf13 DATE;
 
1308
DECLARE o_newf14 INTEGER;
 
1309
DECLARE cur1 CURSOR FOR SELECT f1, f2, f3, f4 FROM t2
 
1310
WHERE f4>=-5000 ORDER BY f4 LIMIT 5;
 
1311
DECLARE cur2 CURSOR FOR SELECT f1, f2, f3, f4 FROM t2
 
1312
WHERE f4>=-5000 ORDER BY f4 LIMIT 5;
 
1313
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET proceed=0;
 
1314
OPEN cur1;
 
1315
OPEN cur2;
 
1316
SET o_count = 1;
 
1317
WHILE proceed DO
 
1318
FETCH cur1 INTO o_newf1, o_newf2, o_newf3, o_newf4;
 
1319
IF proceed THEN
 
1320
INSERT INTO temp1 VALUES ('_sp_out_', o_count, o_newf1, o_newf2, o_newf3, o_newf4);
 
1321
CALL sp_inner();
 
1322
FETCH cur2 INTO o_newf11, o_newf12, o_newf13, o_newf14;
 
1323
IF proceed THEN
 
1324
INSERT INTO temp2 VALUES ('_sp_out_', o_count, o_newf11, o_newf12, o_newf13, o_newf14);
 
1325
END IF;
 
1326
END IF;
 
1327
SET o_count = o_count + 1;
 
1328
END WHILE;
 
1329
CLOSE cur1;
 
1330
CLOSE cur2;
 
1331
END//
 
1332
CALL sp_outer();
 
1333
SELECT * FROM temp1;
 
1334
f0      cnt     f1      f2      f3      f4
 
1335
_sp_out_        1       a`      a`      1000-01-01      -5000
 
1336
sp_inner        10      a`      a`      1000-01-01      -5000
 
1337
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1338
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1339
sp_inner        7       acaaa   acaaa   1000-01-04      -4997
 
1340
_sp_out_        2       aaa     aaa     1000-01-02      -4999
 
1341
sp_inner        10      a`      a`      1000-01-01      -5000
 
1342
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1343
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1344
sp_inner        7       acaaa   acaaa   1000-01-04      -4997
 
1345
_sp_out_        3       abaa    abaa    1000-01-03      -4998
 
1346
sp_inner        10      a`      a`      1000-01-01      -5000
 
1347
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1348
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1349
sp_inner        7       acaaa   acaaa   1000-01-04      -4997
 
1350
_sp_out_        4       acaaa   acaaa   1000-01-04      -4997
 
1351
sp_inner        10      a`      a`      1000-01-01      -5000
 
1352
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1353
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1354
sp_inner        7       acaaa   acaaa   1000-01-04      -4997
 
1355
_sp_out_        5       adaaaa  adaaaa  1000-01-05      -4996
 
1356
sp_inner        10      a`      a`      1000-01-01      -5000
 
1357
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1358
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1359
sp_inner        7       acaaa   acaaa   1000-01-04      -4997
 
1360
SELECT * FROM temp2;
 
1361
f0      cnt     f1      f2      f3      f4
 
1362
sp_inner        10      a`      a`      1000-01-01      -5000
 
1363
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1364
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1365
_sp_out_        1       a`      a`      1000-01-01      -5000
 
1366
sp_inner        10      a`      a`      1000-01-01      -5000
 
1367
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1368
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1369
_sp_out_        2       aaa     aaa     1000-01-02      -4999
 
1370
sp_inner        10      a`      a`      1000-01-01      -5000
 
1371
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1372
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1373
_sp_out_        3       abaa    abaa    1000-01-03      -4998
 
1374
sp_inner        10      a`      a`      1000-01-01      -5000
 
1375
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1376
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1377
_sp_out_        4       acaaa   acaaa   1000-01-04      -4997
 
1378
sp_inner        10      a`      a`      1000-01-01      -5000
 
1379
sp_inner        9       aaa     aaa     1000-01-02      -4999
 
1380
sp_inner        8       abaa    abaa    1000-01-03      -4998
 
1381
_sp_out_        5       adaaaa  adaaaa  1000-01-05      -4996
 
1382
DROP PROCEDURE sp_outer;
 
1383
DROP PROCEDURE sp_inner;
 
1384
DROP TABLE temp1;
 
1385
DROP TABLE temp2;
 
1386
 
 
1387
--source suite/funcs_1/storedproc/cleanup_sp_tb.inc
 
1388
--------------------------------------------------------------------------------
 
1389
DROP DATABASE IF EXISTS db_storedproc;
 
1390
DROP DATABASE IF EXISTS db_storedproc_1;
 
1391
 
 
1392
.                               +++ END OF SCRIPT +++
 
1393
--------------------------------------------------------------------------------