2 --source suite/funcs_1/storedproc/load_sp_tb.inc
3 --------------------------------------------------------------------------------
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;
12 create table t1(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
13 engine = <engine_to_be_tested>;
14 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t1;
15 create table t2(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
16 engine = <engine_to_be_tested>;
17 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t2;
18 create table t3(f1 char(20),f2 char(20),f3 integer) engine = <engine_to_be_tested>;
19 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t3.txt' into table t3;
20 create table t4(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
21 engine = <engine_to_be_tested>;
22 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t4;
24 create table t6(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
25 engine = <engine_to_be_tested>;
26 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t6;
28 create table t7 (f1 char(20), f2 char(25), f3 date, f4 int)
29 engine = <engine_to_be_tested>;
30 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t7.txt' into table t7;
32 Warning 1265 Data truncated for column 'f3' at row 1
33 Warning 1265 Data truncated for column 'f3' at row 2
34 Warning 1265 Data truncated for column 'f3' at row 3
35 Warning 1265 Data truncated for column 'f3' at row 4
36 Warning 1265 Data truncated for column 'f3' at row 5
37 Warning 1265 Data truncated for column 'f3' at row 6
38 Warning 1265 Data truncated for column 'f3' at row 7
39 Warning 1265 Data truncated for column 'f3' at row 8
40 Warning 1265 Data truncated for column 'f3' at row 9
41 Warning 1265 Data truncated for column 'f3' at row 10
42 create table t8 (f1 char(20), f2 char(25), f3 date, f4 int)
43 engine = <engine_to_be_tested>;
44 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t7.txt' into table t8;
46 Warning 1265 Data truncated for column 'f3' at row 1
47 Warning 1265 Data truncated for column 'f3' at row 2
48 Warning 1265 Data truncated for column 'f3' at row 3
49 Warning 1265 Data truncated for column 'f3' at row 4
50 Warning 1265 Data truncated for column 'f3' at row 5
51 Warning 1265 Data truncated for column 'f3' at row 6
52 Warning 1265 Data truncated for column 'f3' at row 7
53 Warning 1265 Data truncated for column 'f3' at row 8
54 Warning 1265 Data truncated for column 'f3' at row 9
55 Warning 1265 Data truncated for column 'f3' at row 10
56 create table t9(f1 int, f2 char(25), f3 int) engine = <engine_to_be_tested>;
57 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t9.txt' into table t9;
58 create table t10(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
59 engine = <engine_to_be_tested>;
60 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t10;
61 create table t11(f1 char(20),f2 char(25),f3 date,f4 int,f5 char(25),f6 int)
62 engine = <engine_to_be_tested>;
63 load data infile '<MYSQLTEST_VARDIR>/std_data/funcs_1/t4.txt' into table t11;
65 Section 3.1.2 - Syntax checks for the stored procedure-specific
66 programming statements BEGIN/END, DECLARE, SET, SELECT/INTO, OPEN, FETCH, CLOSE:
67 --------------------------------------------------------------------------------
72 Ensure that the scope of each BEGIN/END compound statement within a stored
73 procedure definition is properly applied
74 --------------------------------------------------------------------------------
75 DROP PROCEDURE IF EXISTS sp1;
76 CREATE PROCEDURE sp1( )
78 declare x char DEFAULT 'x';
79 declare y char DEFAULT 'y';
83 declare x char DEFAULT 'X';
84 declare y char DEFAULT 'Y';
85 SELECT f1, f2 into x, y from t2 limit 1;
88 declare x char default 'a';
89 declare y char default 'b';
91 declare x char default 'c';
92 declare y char default 'd';
94 declare x char default 'e';
95 declare y char default 'f';
97 declare x char default 'g';
98 declare y char default 'h';
110 SELECT '1.2', @v1, @v2;
126 Warning 1265 Data truncated for column 'x' at row 1
127 Warning 1265 Data truncated for column 'y' at row 1
128 DROP PROCEDURE IF EXISTS sp1;
133 Ensure that the initial value of every variable declared for a stored procedure
134 is either NULL or its DEFAULT value, as appropriate.
135 --------------------------------------------------------------------------------
136 DROP PROCEDURE IF EXISTS sp1;
139 CREATE PROCEDURE sp1( )
141 declare x1 char default 'x';
143 declare x2 tinytext default 'tinytext';
145 declare x3 datetime default '2005-10-03 12:13:14';
147 declare x4 float default 1.2;
149 declare x5 blob default 'b';
151 declare x6 smallint default 127;
153 SELECT x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6;
156 x1 x2 x3 x4 x5 x6 y1 y2 y3 y4 y5 y6
157 x tinytext 2005-10-03 12:13:14 1.2 b 127 NULL NULL NULL NULL NULL NULL
163 Ensure that, when a stored procedure is called/executed, every variable always
164 uses the correct value: either the value with which it is initialized or the
165 value to which it is subsequently SET or otherwise assigned, as appropriate.
166 --------------------------------------------------------------------------------
167 DROP PROCEDURE IF EXISTS sp1;
168 CREATE PROCEDURE sp1( IN invar INT, OUT outvar INT )
171 declare y integer default 1;
175 SELECT f1, f2 into @x, @y from t2 where f1='a`' and f2='a`' limit 1;
176 SELECT @x, @y, @z, invar;
180 SET outvar = @x * invar + @z * @f;
183 set @y = null, @z = 'abcd';
189 SET @outvar = @invar;
191 SELECT @x, @y, @z, @invar, @outvar;
192 @x @y @z @invar @outvar
193 NULL NULL NULL 100 100
194 CALL sp1( @invar, @outvar );
201 SELECT @x, @y, @z, @invar, @outvar;
202 @x @y @z @invar @outvar
209 Ensure that the SELECT ... INTO statement properly assigns values to the
210 variables in its variable list.
211 --------------------------------------------------------------------------------
212 DROP PROCEDURE IF EXISTS sp1;
213 CREATE PROCEDURE sp1( )
215 declare x integer; declare y integer;
218 SELECT f4, f3 into @x, @y from t2 where f4=-5000 and f3='1000-01-01' limit 1;
229 Ensure that a SELECT ... INTO statement that retrieves multiple rows is
230 rejected, with an appropriate error message.
231 --------------------------------------------------------------------------------
232 DROP PROCEDURE IF EXISTS sp1;
233 CREATE PROCEDURE sp1( )
235 declare x integer; declare y integer;
238 SELECT f4, f3 into @x, @y from t2;
241 ERROR 42000: Result consisted of more than one row
247 Ensure that a SELECT ... INTO statement that retrieves too many columns for the
248 number of variables in its variable list is rejected, with an appropriate error
250 --------------------------------------------------------------------------------
251 DROP PROCEDURE IF EXISTS sp1;
252 CREATE PROCEDURE sp1( )
254 declare x integer; declare y integer;
257 SELECT f4, f3, f2, f1 into @x, @y from t2;
260 ERROR 21000: The used SELECT statements have a different number of columns
266 Ensure that a SELECT ... INTO statement that retrieves too few columns for the
267 number of variables in its variable list is rejected, with an appropriate error
269 --------------------------------------------------------------------------------
270 DROP PROCEDURE IF EXISTS sp1;
271 CREATE PROCEDURE sp1( )
273 declare x integer; declare y integer; declare z integer;
277 SELECT f4 into @x, @y, @z from t2;
280 ERROR 21000: The used SELECT statements have a different number of columns
286 Ensure that the scope of every condition declared is properly applied.
287 --------------------------------------------------------------------------------
288 DROP PROCEDURE IF EXISTS h1;
289 DROP TABLE IF EXISTS res_t1;
290 create table res_t1(w char unique, x char);
291 insert into res_t1 values('a', 'b');
292 CREATE PROCEDURE h1 ()
294 declare x1, x2, x3, x4, x5, x6 int default 0;
295 SELECT '-1-', x1, x2, x3, x4, x5, x6;
297 declare condname condition for sqlstate '23000';
298 declare continue handler for condname set x5 = 1;
300 insert into res_t1 values ('a', 'b');
302 SELECT '-2-', x1, x2, x3, x4, x5, x6;
306 declare condname condition for sqlstate '20000';
307 declare continue handler for condname set x1 = 1;
310 when 1 then set x2=10;
311 when 2 then set x2=11;
314 SELECT '-3-', x1, x2, x3, x4, x5, x6;
317 declare condname condition for sqlstate '23000';
318 declare exit handler for condname set x3 = 1;
320 SELECT '-4a', x1, x2, x3, x4, x5, x6;
321 insert into res_t1 values ('a', 'b');
323 SELECT '-4b', x1, x2, x3, x4, x5, x6;
325 SELECT '-5-', x1, x2, x3, x4, x5, x6;
327 SELECT '-6-', x1, x2, x3, x4, x5, x6;
329 SELECT '-7-', x1, x2, x3, x4, x5, x6;
331 SELECT 'END', x1, x2, x3, x4, x5, x6;
334 -1- x1 x2 x3 x4 x5 x6
336 -2- x1 x2 x3 x4 x5 x6
338 -3- x1 x2 x3 x4 x5 x6
340 -4a x1 x2 x3 x4 x5 x6
342 -5- x1 x2 x3 x4 x5 x6
344 -6- x1 x2 x3 x4 x5 x6
346 -7- x1 x2 x3 x4 x5 x6
348 END x1 x2 x3 x4 x5 x6
350 DROP TABLE IF EXISTS tnull;
351 DROP PROCEDURE IF EXISTS sp1;
352 CREATE TABLE tnull(f1 int);
353 CREATE PROCEDURE sp1()
355 declare cond1 condition for sqlstate '42S02';
356 declare continue handler for cond1 set @var2 = 1;
358 declare cond1 condition for sqlstate '23000';
359 declare continue handler for cond1 set @var2 = 1;
361 insert into tnull values(1);
372 Ensure that the DECLARE ... HANDLER FOR statement can not declare any handler
373 for a condition declared outside of the scope of the handler.
374 --------------------------------------------------------------------------------
375 DROP PROCEDURE IF EXISTS h1;
376 DROP PROCEDURE IF EXISTS h2;
377 drop table IF EXISTS res_t1;
378 create table res_t1(w char unique, x char);
379 insert into res_t1 values ('a', 'b');
380 CREATE PROCEDURE h1 ()
382 declare x1, x2, x3, x4, x5, x6 int default 0;
384 declare cond_1 condition for sqlstate '23000';
385 declare continue handler for cond_1 set x5 = 1;
387 declare cond_2 condition for sqlstate '20000';
388 declare continue handler for cond_1 set x1 = 1;
390 declare continue handler for cond_2 set x3 = 1;
396 declare continue handler for cond_1 set x1 = 1;
398 declare continue handler for cond_2 set x3 = 1;
404 SELECT x1, x2, x3, x4, x5, x6;
406 ERROR 42000: Undefined CONDITION: cond_2
407 CREATE PROCEDURE h2 ()
409 declare x1, x2, x3, x4, x5, x6 int default 0;
411 declare condname condition for sqlstate '23000';
412 declare continue handler for condname set x5 = 1;
414 declare condname condition for sqlstate '20000';
415 declare continue handler for condname set x1 = 1;
417 declare condname condition for sqlstate '42000';
418 declare continue handler for condname set x3 = 1;
420 insert into res_t1 values ('a', 'b');
427 when 1 then set x2=10;
428 when 2 then set x2=11;
434 when 1 then set x2=10;
435 when 2 then set x2=11;
439 insert into res_t1 values ('a', 'b');
443 SELECT x1, x2, x3, x4, x5, x6;
448 SELECT * FROM res_t1;
457 Ensure that the DECLARE ... HANDLER FOR statement cannot declare a handler for
458 any invalid, or undeclared, condition.
459 --------------------------------------------------------------------------------
460 DROP PROCEDURE IF EXISTS h1;
461 CREATE PROCEDURE h1 ()
463 declare x1, x2, x3, x4, x5, x6 int default 0;
465 declare condname1 condition for sqlstate '23000';
467 declare condname2 condition for sqlstate '20000';
468 declare continue handler for condname1 set x3 = 1;
469 declare continue handler for condname2 set x1 = 1;
473 declare condname3 condition for sqlstate '42000';
474 declare continue handler for condname1 set x3 = 1;
475 declare continue handler for condname2 set x5 = 1;
476 declare continue handler for condname3 set x1 = 1;
479 ERROR 42000: Undefined CONDITION: condname1
480 CREATE PROCEDURE h1 ()
482 DECLARE x1 INT DEFAULT 0;
484 DECLARE condname1 CONDITION CHECK SQLSTATE '23000';
486 DECLARE CONTINUE HANDLER FOR condname1 SET x1 = 1;
488 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';
490 DECLARE CONTINUE HANDLER FOR condname1 SET x1 = 1;
492 CREATE PROCEDURE h1 ()
494 DECLARE x1 INT DEFAULT 0;
496 DECLARE condname1 CONDITION FOR SQLSTATE 'qwert';
498 DECLARE CONTINUE HANDLER FOR condname1 SET x1 = 1;
500 ERROR 42000: Bad SQLSTATE: 'qwert'
502 Testcase 3.1.2.45 + 3.1.2.50:
503 -----------------------------
505 45. Ensure that the scope of every handler declared is properly applied.
506 50. Ensure that a CONTINUE handler allows the execution of the stored procedure
507 . to continue once the handler statement has completed its own execution (that
508 . is, once the handler action statement has been executed).
509 --------------------------------------------------------------------------------
510 DROP PROCEDURE IF EXISTS p1;
511 DROP PROCEDURE IF EXISTS p1undo;
512 DROP PROCEDURE IF EXISTS h1;
513 DROP PROCEDURE IF EXISTS sp1;
514 drop table IF EXISTS res_t1;
515 ==> 'UNDO' is still not supported.
516 create procedure p1undo ()
518 declare undo handler for sqlexception select '1';
522 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';
526 create procedure p1 ()
528 declare exit handler for sqlexception select 'exit handler 1';
530 declare exit handler for sqlexception select 'exit handler 2';
532 declare continue handler for sqlexception select 'continue handler 3';
533 drop table if exists tqq;
535 SELECT 'end of BEGIN/END 3';
537 drop table if exists tqq;
539 SELECT 'end of BEGIN/END 2';
542 SELECT 'end of BEGIN/END 1';
554 Note 1051 Unknown table 'tqq'
555 Note 1051 Unknown table 'tqq'
556 create table res_t1(w char unique, x char);
557 insert into res_t1 values ('a', 'b');
558 CREATE PROCEDURE h1 ()
560 declare x1, x2, x3, x4, x5, x6 int default 0;
562 declare continue handler for sqlstate '23000' set x5 = 1;
563 insert into res_t1 values ('a', 'b');
568 declare continue handler for sqlstate '23000' set x1 = 1;
569 insert into res_t1 values ('a', 'b');
573 declare exit handler for sqlstate '23000' set x3 = 1;
575 insert into res_t1 values ('a', 'b');
581 SELECT x1, x2, x3, x4, x5, x6;
586 This will fail, SQLSTATE 00000 is not allowed
587 CREATE PROCEDURE sp1()
589 declare exit handler for sqlstate '00000' set @var1 = 5;
592 declare continue handler for sqlstate '00000' set @var3 = 7;
598 ERROR 42000: Bad SQLSTATE: '00000'
599 Verify SP wasn't created
601 ERROR 42000: PROCEDURE db_storedproc.sp1 does not exist
604 DROP PROCEDURE IF EXISTS sp1;
609 DROP PROCEDURE IF EXISTS sp1;
610 DROP PROCEDURE IF EXISTS sp2;
611 CREATE PROCEDURE sp1 (x int, y int)
615 CREATE PROCEDURE sp2 ()
617 declare continue handler for sqlstate '42000' set @x2 = 1;
635 Ensure that an EXIT handler causes the execution of the stored procedure to
636 terminate, within its scope, once the handler action statement has been
638 --------------------------------------------------------------------------------
639 DROP PROCEDURE IF EXISTS sp1;
640 DROP PROCEDURE IF EXISTS sp2;
641 CREATE PROCEDURE sp1 (x int, y int)
645 CREATE PROCEDURE sp2 ()
647 declare exit handler for sqlstate '42000' set @x2 = 1;
650 SELECT '-1-', @x2, @x;
652 SELECT '-2-', @x2, @x;
656 ERROR 42000: Incorrect number of arguments for PROCEDURE db_storedproc.sp1; expected 2, got 1
660 SELECT '-3-', @x2, @x;
669 Ensure that an EXIT handler does not cause the execution of the stored procedure
670 to terminate outside of its scope.
671 --------------------------------------------------------------------------------
672 DROP PROCEDURE IF EXISTS sp1;
673 DROP PROCEDURE IF EXISTS sp2;
674 CREATE PROCEDURE sp1 (x int, y int)
678 CREATE PROCEDURE sp2()
680 declare continue handler for sqlstate '42000' set @x2 = 2;
683 SELECT '-1-', @x2, @x;
685 declare exit handler for sqlstate '42000' set @x2 = 11;
686 SELECT '-2-', @x2, @x;
688 SELECT '-3a', @x2, @x;
690 SELECT '-3b', @x2, @x;
693 SELECT '-4-', @x2, @x;
708 Ensure that a handler with a condition defined with an SQLSTATE that begins with
709 “01“ is always exactly equivalent in action to a handler with an SQLWARNING
711 --------------------------------------------------------------------------------
712 DROP PROCEDURE IF EXISTS sp0;
713 DROP PROCEDURE IF EXISTS sp1;
714 DROP PROCEDURE IF EXISTS sp2;
715 DROP PROCEDURE IF EXISTS sp3;
716 DROP PROCEDURE IF EXISTS sp4;
717 DROP TABLE IF EXISTS temp;
718 CREATE TABLE temp( f1 CHAR, f2 CHAR);
719 CREATE PROCEDURE sp0()
723 insert into temp values('xxx', 'yy');
726 CREATE PROCEDURE sp1()
728 declare continue handler for sqlstate '01000' set @done = 1;
731 insert into temp values('xxx', 'yy');
734 CREATE PROCEDURE sp2()
736 declare continue handler for sqlwarning set @done = 1;
739 insert into temp values('xxx', 'yy');
742 CREATE PROCEDURE sp3()
744 declare exit handler for sqlstate '01000' set @done = 1;
747 insert into temp values('xxx', 'yy');
750 CREATE PROCEDURE sp4()
752 declare exit handler for sqlwarning set @done = 1;
755 insert into temp values('xxx', 'yy');
758 INSERT INTO temp VALUES('0', NULL);
761 Warning 1265 Data truncated for column 'f1' at row 1
762 Warning 1265 Data truncated for column 'f2' at row 1
766 INSERT INTO temp VALUES('1', NULL);
771 INSERT INTO temp VALUES('2', NULL);
776 INSERT INTO temp VALUES('3', NULL);
781 INSERT INTO temp VALUES('4', NULL);
807 Ensure that a handler with a condition defined with an SQLSTATE that begins with
808 “02“ is always exactly equivalent in action to a handler with a NOT FOUND
810 --------------------------------------------------------------------------------
811 DROP PROCEDURE IF EXISTS sp0;
812 DROP PROCEDURE IF EXISTS sp1;
813 DROP PROCEDURE IF EXISTS sp2;
814 DROP PROCEDURE IF EXISTS sp3;
815 DROP PROCEDURE IF EXISTS sp4;
816 CREATE PROCEDURE sp0()
818 DECLARE f1_value CHAR(20);
819 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
823 FETCH cur1 INTO f1_value;
825 FETCH cur1 INTO f1_value;
829 CREATE PROCEDURE sp1()
831 DECLARE f1_value CHAR(20);
832 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
833 declare continue handler for sqlstate '02000' set @done = 1;
837 FETCH cur1 INTO f1_value;
839 FETCH cur1 INTO f1_value;
843 CREATE PROCEDURE sp2()
845 DECLARE f1_value CHAR(20);
846 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
847 declare continue handler for not found set @done = 1;
851 FETCH cur1 INTO f1_value;
853 FETCH cur1 INTO f1_value;
857 CREATE PROCEDURE sp3()
859 DECLARE f1_value CHAR(20);
860 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
861 declare exit handler for sqlstate '02000' set @done = 1;
865 FETCH cur1 INTO f1_value;
867 FETCH cur1 INTO f1_value;
871 CREATE PROCEDURE sp4()
873 DECLARE f1_value CHAR(20);
874 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
875 declare exit handler for not found set @done = 1;
879 FETCH cur1 INTO f1_value;
881 FETCH cur1 INTO f1_value;
886 ERROR 02000: No data - zero rows fetched, selected, or processed
915 Ensure that a handler with a condition defined with an SQLSTATE that begins with
916 anything other that “01“ or “02“ is always exactly equivalent in action to a
917 handler with an SQLEXCEPTION condition.
918 --------------------------------------------------------------------------------
919 DROP PROCEDURE IF EXISTS sp0;
920 DROP PROCEDURE IF EXISTS sp1;
921 DROP PROCEDURE IF EXISTS sp2;
922 DROP PROCEDURE IF EXISTS sp3;
923 DROP PROCEDURE IF EXISTS sp4;
924 CREATE PROCEDURE sp0()
926 DECLARE f1_value CHAR(20);
927 DECLARE cv INT DEFAULT 0;
928 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
931 WHEN 2 THEN SET @x = 2;
932 WHEN 3 THEN SET @x = 3;
935 SELECT f1, f2 FROM t2
937 SELECT f1, f2,3 FROM t2;
939 FETCH cur1 INTO f1_value;
942 CREATE PROCEDURE sp1()
944 DECLARE f1_value CHAR(20);
945 DECLARE cv INT DEFAULT 0;
946 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
947 DECLARE continue HANDLER FOR SQLSTATE '20000' SELECT '20000' AS 'SQLSTATE';
948 DECLARE continue HANDLER FOR SQLSTATE '21000' SELECT '21000' AS 'SQLSTATE';
949 DECLARE continue HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
952 WHEN 2 THEN SET @x = 2;
953 WHEN 3 THEN SET @x = 3;
956 SELECT f1, f2 FROM t2
958 SELECT f1, f2,3 FROM t2;
960 FETCH cur1 INTO f1_value;
963 CREATE PROCEDURE sp2()
965 DECLARE f1_value CHAR(20);
966 DECLARE cv INT DEFAULT 0;
967 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
968 DECLARE continue HANDLER FOR SQLEXCEPTION SELECT 'SQLEXCEPTION' AS 'SQLSTATE';
969 DECLARE continue HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
972 WHEN 2 THEN SET @x = 2;
973 WHEN 3 THEN SET @x = 3;
976 SELECT f1, f2 FROM t2
978 SELECT f1, f2,3 FROM t2;
980 FETCH cur1 INTO f1_value;
983 CREATE PROCEDURE sp3()
985 DECLARE f1_value CHAR(20);
986 DECLARE cv INT DEFAULT 0;
987 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
988 DECLARE EXIT HANDLER FOR SQLSTATE '20000' SELECT '20000' AS 'SQLSTATE';
989 DECLARE EXIT HANDLER FOR SQLSTATE '21000' SELECT '21000' AS 'SQLSTATE';
990 DECLARE EXIT HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
993 WHEN 2 THEN SET @x = 2;
994 WHEN 3 THEN SET @x = 3;
997 SELECT f1, f2 FROM t2
999 SELECT f1, f2,3 FROM t2;
1001 FETCH cur1 INTO f1_value;
1004 CREATE PROCEDURE sp4()
1006 DECLARE f1_value CHAR(20);
1007 DECLARE cv INT DEFAULT 0;
1008 DECLARE cur1 CURSOR FOR SELECT f1 FROM t2 LIMIT 1;
1009 DECLARE EXIT HANDLER FOR SQLEXCEPTION SELECT 'SQLEXCEPTION' AS 'SQLSTATE';
1010 DECLARE EXIT HANDLER FOR SQLSTATE '24000' SELECT '24000' AS 'SQLSTATE';
1013 WHEN 2 THEN SET @x = 2;
1014 WHEN 3 THEN SET @x = 3;
1017 SELECT f1, f2 FROM t2
1019 SELECT f1, f2,3 FROM t2;
1021 FETCH cur1 INTO f1_value;
1026 ERROR 20000: Case not found for CASE statement
1071 Ensure that FETCH <cursor name> returns the first row of the cursor_s result set
1072 the first time FETCH is executed, that it returns each subsequent row of the
1073 cursor_s result set each of the subsequent times FETCH is executed, and that it
1074 returns a NOT FOUND warning if it is executed after the last row of the cursor_s
1075 result set has already been fetched.
1076 --------------------------------------------------------------------------------
1077 DROP PROCEDURE IF EXISTS sp1;
1078 DROP TABLE IF EXISTS temp;
1086 INSERT INTO temp VALUES(0, 'onip', 'abc', 8760, 'xyz', 10);
1087 CREATE PROCEDURE sp1( )
1089 declare proceed int default 1;
1090 declare count integer default 1;
1091 declare f1_value char(20);
1092 declare f2_value char(20);
1093 declare f5_value char(20);
1094 declare f4_value integer;
1095 declare f6_value integer;
1096 declare cur1 cursor for SELECT f1, f2, f4, f5, f6 from t2
1097 where f4 >=-5000 order by f4 limit 3;
1100 SELECT count AS 'loop';
1101 fetch cur1 into f1_value, f2_value, f4_value, f5_value, f6_value;
1102 insert into temp values (count, f1_value, f2_value, f4_value, f5_value, f6_value);
1103 set count = count + 1;
1115 ERROR 02000: No data - zero rows fetched, selected, or processed
1118 0 onip abc 8760 xyz 10
1119 1 a` a` -5000 a` -5000
1120 2 aaa aaa -4999 aaa -4999
1121 3 abaa abaa -4998 abaa -4998
1128 Ensure that FETCH <cursor name> fails with an appropriate error message if the
1129 number of columns to be fetched does not match the number of variables specified
1130 by the FETCH statement.
1131 --------------------------------------------------------------------------------
1132 DROP PROCEDURE IF EXISTS sp1;
1133 DROP PROCEDURE IF EXISTS sp2;
1134 --> not enough columns in FETCH statement
1135 CREATE PROCEDURE sp1( )
1137 declare newf1 char(20);
1138 declare cur1 cursor for SELECT f1, f2 from t2 limit 10;
1139 declare continue handler for sqlstate '02000' SELECT 'HANDLER executed.' AS '';
1142 fetch cur1 into newf1;
1147 --> too many columns in FETCH statement
1148 CREATE PROCEDURE sp2( )
1150 declare newf1 char(20);
1151 declare newf2 char(20);
1152 declare cur1 cursor for SELECT f1 from t2 limit 10;
1153 declare continue handler for sqlstate '02000' SELECT 'HANDLER executed.' AS '';
1156 fetch cur1 into newf1, newf2;
1157 SELECT newf1, newf2;
1161 --> not enough columns in FETCH statement
1163 ERROR HY000: Incorrect number of FETCH variables
1164 --> too many columns in FETCH statement
1166 ERROR HY000: Incorrect number of FETCH variables
1173 Ensure that, for nested compound statements, a cursor that was declared and
1174 opened during an outer level of the statement is not closed when an inner level
1175 of a compound statement ends.
1176 --------------------------------------------------------------------------------
1177 DROP TABLE IF EXISTS temp1;
1178 DROP PROCEDURE IF EXISTS sp1;
1179 create table temp1( f0 char(20), f1 char(20), f2 char(20), f3 int, f4 char(20) );
1180 SELECT f1, f2, f4, f5 from t2 order by f4;
1184 abaa abaa -4998 abaa
1185 acaaa acaaa -4997 acaaa
1186 adaaaa adaaaa -4996 adaaaa
1187 aeaaaaa aeaaaaa -4995 aeaaaaa
1188 afaaaaaa afaaaaaa -4994 afaaaaaa
1189 agaaaaaaa agaaaaaaa -4993 agaaaaaaa
1190 a^aaaaaaaa a^aaaaaaaa -4992 a^aaaaaaaa
1191 a_aaaaaaaaa a_aaaaaaaaa -4991 a_aaaaaaaaa
1192 CREATE PROCEDURE sp1( )
1194 declare count integer;
1195 declare from0 char(20);
1196 declare newf1 char(20);
1197 declare newf2 char(20);
1198 declare newf5 char(20);
1199 declare newf4 integer;
1200 declare cur1 cursor for SELECT f1, f2, f4, f5 from t2 where f4 >= -5000 order by f4 limit 5;
1201 declare cur2 cursor for SELECT f1, f2, f4, f5 from t2 where f4 >= -5000 order by f4 limit 5;
1205 declare continue handler for sqlstate '02000' set count = 1;
1206 fetch cur1 into newf1, newf2, newf4, newf5;
1207 SELECT '-1-', count, newf1, newf2, newf4, newf5;
1208 insert into temp1 values ('cur1_out', newf1, newf2, newf4, newf5);
1212 fetch cur1 into newf1, newf2, newf4, newf5;
1213 SELECT '-2-', count, newf1, newf2, newf4, newf5;
1214 set count = count - 1;
1216 SELECT '-3-', count, newf1, newf2, newf4, newf4;
1219 fetch cur1 into newf1, newf2, newf4, newf5;
1220 SELECT '-4-', newf1, newf2, newf4, newf5;
1221 insert into temp1 values ('cur1_in', newf1, newf2, newf4, newf5);
1223 fetch cur2 into newf1, newf2, newf4, newf5;
1224 SELECT '-5-', newf1, newf2, newf4, newf5;
1225 insert into temp1 values ('cur2', newf1, newf2, newf4, newf5);
1228 fetch cur2 into newf1, newf2, newf4, newf5;
1229 SELECT '-6-', newf1, newf2, newf4, newf5;
1233 -1- count newf1 newf2 newf4 newf5
1234 -1- NULL a` a` -5000 a`
1235 -2- count newf1 newf2 newf4 newf5
1236 -2- 4 aaa aaa -4999 aaa
1237 -2- count newf1 newf2 newf4 newf5
1238 -2- 3 abaa abaa -4998 abaa
1239 -2- count newf1 newf2 newf4 newf5
1240 -2- 2 acaaa acaaa -4997 acaaa
1241 -2- count newf1 newf2 newf4 newf5
1242 -2- 1 adaaaa adaaaa -4996 adaaaa
1243 -3- count newf1 newf2 newf4 newf4
1244 -3- 0 adaaaa adaaaa -4996 -4996
1245 -4- newf1 newf2 newf4 newf5
1246 -4- adaaaa adaaaa -4996 adaaaa
1247 -5- newf1 newf2 newf4 newf5
1249 -6- newf1 newf2 newf4 newf5
1250 -6- aaa aaa -4999 aaa
1251 SELECT * from temp1;
1253 cur1_out a` a` -5000 a`
1254 cur1_in adaaaa adaaaa -4996 adaaaa
1262 Ensure that all cursors operate asensitively, so that there is no concurrency
1263 conflict between cursors operating on the same, or similar, sets of results
1264 during execution of one or more stored procedures.
1265 --------------------------------------------------------------------------------
1266 DROP PROCEDURE IF EXISTS sp1;
1267 drop table IF EXISTS temp1;
1268 drop table IF EXISTS temp2;
1269 create table temp1( f0 char(10), cnt int, f1 char(20), f2 char(20), f3 date, f4 integer );
1270 create table temp2( f0 char(10), cnt int, f1 char(20), f2 char(20), f3 date, f4 integer );
1271 CREATE PROCEDURE sp_inner( )
1273 declare proceed int default 1;
1274 declare i_count integer default 20;
1275 declare i_newf1 char(20);
1276 declare i_newf2 char(20);
1277 declare i_newf3 date;
1278 declare i_newf4 integer;
1279 declare i_newf11 char(20);
1280 declare i_newf12 char(20);
1281 declare i_newf13 date;
1282 declare i_newf14 integer;
1283 declare cur1 cursor for SELECT f1, f2, f3, f4 from t2
1284 where f4>=-5000 order by f4 limit 4;
1285 declare cur2 cursor for SELECT f1, f2, f3, f4 from t2
1286 where f4>=-5000 order by f4 limit 3;
1287 declare continue handler for sqlstate '02000' set proceed=0;
1292 fetch cur1 into i_newf1, i_newf2, i_newf3, i_newf4;
1294 insert into temp1 values ('sp_inner', i_count, i_newf1, i_newf2, i_newf3, i_newf4);
1295 fetch cur2 into i_newf11, i_newf12, i_newf13, i_newf14;
1297 insert into temp2 values ('sp_inner', i_count, i_newf11, i_newf12, i_newf13, i_newf14);
1300 set i_count = i_count - 1;
1305 CREATE PROCEDURE sp_outer( )
1307 DECLARE proceed INT DEFAULT 1;
1308 DECLARE o_count INTEGER DEFAULT 20;
1309 DECLARE o_newf1 CHAR(20);
1310 DECLARE o_newf2 CHAR(20);
1311 DECLARE o_newf3 DATE;
1312 DECLARE o_newf4 INTEGER;
1313 DECLARE o_newf11 CHAR(20);
1314 DECLARE o_newf12 CHAR(20);
1315 DECLARE o_newf13 DATE;
1316 DECLARE o_newf14 INTEGER;
1317 DECLARE cur1 CURSOR FOR SELECT f1, f2, f3, f4 FROM t2
1318 WHERE f4>=-5000 ORDER BY f4 LIMIT 5;
1319 DECLARE cur2 CURSOR FOR SELECT f1, f2, f3, f4 FROM t2
1320 WHERE f4>=-5000 ORDER BY f4 LIMIT 5;
1321 DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET proceed=0;
1326 FETCH cur1 INTO o_newf1, o_newf2, o_newf3, o_newf4;
1328 INSERT INTO temp1 VALUES ('_sp_out_', o_count, o_newf1, o_newf2, o_newf3, o_newf4);
1330 FETCH cur2 INTO o_newf11, o_newf12, o_newf13, o_newf14;
1332 INSERT INTO temp2 VALUES ('_sp_out_', o_count, o_newf11, o_newf12, o_newf13, o_newf14);
1335 SET o_count = o_count + 1;
1341 SELECT * FROM temp1;
1343 _sp_out_ 1 a` a` 1000-01-01 -5000
1344 sp_inner 10 a` a` 1000-01-01 -5000
1345 sp_inner 9 aaa aaa 1000-01-02 -4999
1346 sp_inner 8 abaa abaa 1000-01-03 -4998
1347 sp_inner 7 acaaa acaaa 1000-01-04 -4997
1348 _sp_out_ 2 aaa aaa 1000-01-02 -4999
1349 sp_inner 10 a` a` 1000-01-01 -5000
1350 sp_inner 9 aaa aaa 1000-01-02 -4999
1351 sp_inner 8 abaa abaa 1000-01-03 -4998
1352 sp_inner 7 acaaa acaaa 1000-01-04 -4997
1353 _sp_out_ 3 abaa abaa 1000-01-03 -4998
1354 sp_inner 10 a` a` 1000-01-01 -5000
1355 sp_inner 9 aaa aaa 1000-01-02 -4999
1356 sp_inner 8 abaa abaa 1000-01-03 -4998
1357 sp_inner 7 acaaa acaaa 1000-01-04 -4997
1358 _sp_out_ 4 acaaa acaaa 1000-01-04 -4997
1359 sp_inner 10 a` a` 1000-01-01 -5000
1360 sp_inner 9 aaa aaa 1000-01-02 -4999
1361 sp_inner 8 abaa abaa 1000-01-03 -4998
1362 sp_inner 7 acaaa acaaa 1000-01-04 -4997
1363 _sp_out_ 5 adaaaa adaaaa 1000-01-05 -4996
1364 sp_inner 10 a` a` 1000-01-01 -5000
1365 sp_inner 9 aaa aaa 1000-01-02 -4999
1366 sp_inner 8 abaa abaa 1000-01-03 -4998
1367 sp_inner 7 acaaa acaaa 1000-01-04 -4997
1368 SELECT * FROM temp2;
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_ 1 a` a` 1000-01-01 -5000
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_ 2 aaa aaa 1000-01-02 -4999
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_ 3 abaa abaa 1000-01-03 -4998
1382 sp_inner 10 a` a` 1000-01-01 -5000
1383 sp_inner 9 aaa aaa 1000-01-02 -4999
1384 sp_inner 8 abaa abaa 1000-01-03 -4998
1385 _sp_out_ 4 acaaa acaaa 1000-01-04 -4997
1386 sp_inner 10 a` a` 1000-01-01 -5000
1387 sp_inner 9 aaa aaa 1000-01-02 -4999
1388 sp_inner 8 abaa abaa 1000-01-03 -4998
1389 _sp_out_ 5 adaaaa adaaaa 1000-01-05 -4996
1390 DROP PROCEDURE sp_outer;
1391 DROP PROCEDURE sp_inner;
1395 --source suite/funcs_1/storedproc/cleanup_sp_tb.inc
1396 --------------------------------------------------------------------------------
1397 DROP DATABASE IF EXISTS db_storedproc;
1398 DROP DATABASE IF EXISTS db_storedproc_1;
1400 . +++ END OF SCRIPT +++
1401 --------------------------------------------------------------------------------