mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / sp-error.test
blob7a04d89fdc2620158bf37abdaf29e58c9bcd6156
2 # Stored PROCEDURE error tests
5 --disable_warnings
6 drop table if exists t1, t2;
7 --enable_warnings
9 # Backup the mysql.proc table
10 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
11 eval SELECT * FROM mysql.proc INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/proc.txt';
13 # Make sure we don't have any procedures left.
14 delete from mysql.proc;
16 delimiter |;
18 # This should give three syntax errors (sometimes crashed; bug #643)
19 # (Unfortunately, this is not a 100% test, on some platforms this
20 #  passed despite the bug.)
21 --error 1064
22 create procedure syntaxerror(t int)|
23 --error 1064
24 create procedure syntaxerror(t int)|
25 --error 1064
26 create procedure syntaxerror(t int)|
28 # Check that we get the right error, i.e. UDF declaration parses correctly,
29 # but foo.so doesn't exist.
30 #    This generates an error message containing a misleading errno which
31 #    might vary between systems (it usually doesn't have anything to do with
32 #    the actual failing dlopen()).
33 #--error 1126
34 #create function foo returns real soname "foo.so"|
37 --disable_warnings
38 drop table if exists t3|
39 --enable_warnings
40 create table t3 ( x int )|
41 insert into t3 values (2), (3)|
43 create procedure bad_into(out param int)
44   select x from t3 into param|
46 --error 1172
47 call bad_into(@x)|
49 drop procedure bad_into|
50 drop table t3|
53 create procedure proc1()
54   set @x = 42|
56 create function func1() returns int
57   return 42|
59 # Can't create recursively
60 --error 1303
61 create procedure foo()
62   create procedure bar() set @x=3|
63 --error 1303
64 create procedure foo()
65   create function bar() returns double return 2.3|
67 # Already exists
68 --error 1304
69 create procedure proc1()
70   set @x = 42|
71 --error 1304
72 create function func1() returns int
73   return 42|
75 drop procedure proc1|
76 drop function func1|
78 # Does not exist
79 --error 1305
80 alter procedure foo|
81 --error 1305
82 alter function foo|
83 --error 1305
84 drop procedure foo|
85 --error 1305
86 drop function foo|
87 --error 1305
88 call foo()|
89 drop procedure if exists foo|
90 --error 1305
91 show create procedure foo|
92 --error 1305
93 show create function foo|
95 # LEAVE/ITERATE with no match
96 --error 1308
97 create procedure foo()
98 foo: loop
99   leave bar;
100 end loop|
101 --error 1308
102 create procedure foo()
103 foo: loop
104   iterate bar;
105 end loop|
106 --error 1308
107 create procedure foo()
108 foo: begin
109   iterate foo;
110 end|
112 # Redefining label
113 --error 1309
114 create procedure foo()
115 foo: loop
116   foo: loop
117     set @x=2;
118   end loop foo;
119 end loop foo|
121 # End label mismatch
122 --error 1310
123 create procedure foo()
124 foo: loop
125   set @x=2;
126 end loop bar|
128 # RETURN in FUNCTION only
129 --error 1313
130 create procedure foo()
131   return 42|
133 # Wrong number of arguments
134 create procedure p(x int)
135   set @x = x|
136 create function f(x int) returns int
137   return x+42|
139 --error 1318
140 call p()|
141 --error 1318
142 call p(1, 2)|
143 --error 1318
144 select f()|
145 --error 1318
146 select f(1, 2)|
148 drop procedure p|
149 drop function f|
151 --error 1319 
152 create procedure p(val int, out res int)
153 begin
154   declare x int default 0;
155   declare continue handler for foo set x = 1;
157   insert into test.t1 values (val);
158   if (x) then
159     set res = 0;
160   else
161     set res = 1;
162   end if;
163 end|
165 --error 1319 
166 create procedure p(val int, out res int)
167 begin
168   declare x int default 0;
169   declare foo condition for 1146;
170   declare continue handler for bar set x = 1;
172   insert into test.t1 values (val);
173   if (x) then
174     set res = 0;
175   else
176     set res = 1;
177   end if;
178 end|
180 --error 1320
181 create function f(val int) returns int
182 begin
183   declare x int;
185   set x = val+3;
186 end|
188 create function f(val int) returns int
189 begin
190   declare x int;
192   set x = val+3;
193   if x < 4 then
194     return x;
195   end if;
196 end|
198 --error 1321
199 select f(10)|
201 drop function f|
203 --error ER_PARSE_ERROR
204 create procedure p()
205 begin
206   declare c cursor for insert into test.t1 values ("foo", 42);
208   open c;
209   close c;
210 end|
212 --error 1323
213 create procedure p()
214 begin
215   declare x int;
216   declare c cursor for select * into x from test.t limit 1;
218   open c;
219   close c;
220 end|
222 --error 1324
223 create procedure p()
224 begin
225   declare c cursor for select * from test.t;
227   open cc;
228   close c;
229 end|
231 --disable_warnings
232 drop table if exists t1|
233 --enable_warnings
234 create table t1 (val int)|
236 create procedure p()
237 begin
238   declare c cursor for select * from test.t1;
240   open c;
241   open c;
242   close c;
243 end|
244 --error 1325
245 call p()|
246 drop procedure p|
248 create procedure p()
249 begin
250   declare c cursor for select * from test.t1;
252   open c;
253   close c;
254   close c;
255 end|
256 --error 1326
257 call p()|
258 drop procedure p|
260 --error 1305
261 alter procedure bar3 sql security invoker|
263 drop table t1|
265 --disable_warnings
266 drop table if exists t1|
267 --enable_warnings
268 create table t1 (val int, x float)|
269 insert into t1 values (42, 3.1), (19, 1.2)|
271 --error 1327
272 create procedure p()
273 begin
274   declare x int;
275   declare c cursor for select * from t1;
277   open c;
278   fetch c into x, y;
279   close c;
280 end|
282 create procedure p()
283 begin
284   declare x int;
285   declare c cursor for select * from t1;
287   open c;
288   fetch c into x;
289   close c;
290 end|
291 --error 1328
292 call p()|
293 drop procedure p|
295 create procedure p()
296 begin
297   declare x int;
298   declare y float;
299   declare z int;
300   declare c cursor for select * from t1;
302   open c;
303   fetch c into x, y, z;
304   close c;
305 end|
306 --error 1328
307 call p()|
308 drop procedure p|
310 --error 1330
311 create procedure p(in x int, x char(10))
312 begin
313 end|
314 --error 1330
315 create function p(x int, x char(10))
316 begin
317 end|
319 --error 1331
320 create procedure p()
321 begin
322   declare x float;
323   declare x int;
324 end|
326 --error 1332
327 create procedure p()
328 begin
329   declare c condition for 1064;
330   declare c condition for 1065;
331 end|
333 --error 1333
334 create procedure p()
335 begin
336   declare c cursor for select * from t1;
337   declare c cursor for select field from t1;
338 end|
340 # USE is not allowed
341 --error ER_SP_BADSTATEMENT 
342 create procedure u()
343   use sptmp|
345 # Enforced standard order of declarations
346 --error 1337
347 create procedure p()
348 begin
349   declare c cursor for select * from t1;
350   declare x int;
351 end|
352 --error 1337
353 create procedure p()
354 begin
355   declare x int;
356   declare continue handler for sqlstate '42S99' set x = 1;
357   declare foo condition for sqlstate '42S99';
358 end|
360 --error 1338
361 create procedure p()
362 begin
363   declare x int;
364   declare continue handler for sqlstate '42S99' set x = 1;
365   declare c cursor for select * from t1;
366 end|
368 # Check in and inout arguments.
369 --disable_warnings
370 drop procedure if exists p|
371 --enable_warnings
372 create procedure p(in x int, inout y int, out z int)
373 begin
374   set y = x+y;
375   set z = x+y;
376 end|
378 set @tmp_x = 42|
379 set @tmp_y = 3|
380 set @tmp_z = 0|
381 # For reference: this is ok
382 call p(@tmp_x, @tmp_y, @tmp_z)|
383 select @tmp_x, @tmp_y, @tmp_z|
385 --error ER_SP_NOT_VAR_ARG
386 call p(42, 43, @tmp_z)|
387 --error ER_SP_NOT_VAR_ARG
388 call p(42, @tmp_y, 43)|
390 drop procedure p|
394 # Let us test that we can access mysql.proc table for routines
395 # definitions lookup without locking it explicitly.
397 create procedure p() begin end|
398 lock table t1 read|
399 # This should succeed
400 call p()|
401 unlock tables|
402 drop procedure p|
403 # Let us check restrictions which this ability puts on mysql.proc locking.
404 --error ER_WRONG_LOCK_OF_SYSTEM_TABLE
405 lock tables t1 read, mysql.proc write|
406 --error ER_WRONG_LOCK_OF_SYSTEM_TABLE
407 lock tables mysql.proc write, mysql.user write|
408 # Locking for read should be OK
409 lock tables t1 read, mysql.proc read|
410 unlock tables|
411 # You also should be able lock only mysql.proc for write
412 lock tables mysql.proc write|
413 unlock tables|
417 # Check that in functions we don't allow to update tables which
418 # are used by statements which invoke these functions.
420 --disable_warnings
421 drop function if exists f1|
422 --enable_warnings
423 create function f1(i int) returns int
424 begin
425   insert into t1 (val) values (i);
426   return 0;
427 end|
428 --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
429 select val, f1(val) from t1|
430 # Table alias should not matter
431 --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
432 select val, f1(val) from t1 as tab|
433 select * from t1|
434 --error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
435 update t1 set val= f1(val)|
436 select * from t1|
437 # But this should be OK
438 select f1(17)|
439 select * from t1|
440 # Cleanup
441 delete from t1 where val= 17|
442 drop function f1|
446 # BUG#1965
448 create procedure bug1965()
449 begin
450   declare c cursor for select val from t1 order by valname;
451   open c;
452   close c;
453 end|
455 --error 1054
456 call bug1965()|
457 drop procedure bug1965|
460 # BUG#1966
462 --error 1327
463 select 1 into a|
466 # BUG#1653
468 --disable_warnings
469 drop table if exists t3|
470 --enable_warnings
471 create table t3 (column_1_0 int)|
473 create procedure bug1653()
474   update t3 set column_1 = 0|
476 --error 1054
477 call bug1653()|
478 drop table t3|
479 create table t3 (column_1 int)|
480 call bug1653()|
482 drop procedure bug1653|
483 drop table t3|
486 # BUG#2259
488 # Note: When this bug existed, it did not necessarily cause a crash
489 #       in all builds, but valgrind did give warnings.
490 create procedure bug2259()
491 begin
492   declare v1 int;
493   declare c1 cursor for select s1 from t1;
495   fetch c1 into v1;
496 end|
498 --error 1326
499 call bug2259()|
500 drop procedure bug2259|
503 # BUG#2272
505 create procedure bug2272()
506 begin
507   declare v int;
509   update t1 set v = 42;
510 end|
512 insert into t1 values (666, 51.3)|
513 --error 1054
514 call bug2272()|
515 truncate table t1|
516 drop procedure bug2272|
519 # BUG#2329
521 create procedure bug2329_1()
522 begin
523   declare v int;
525   insert into t1 (v) values (5);
526 end|
528 create procedure bug2329_2()
529 begin
530   declare v int;
532   replace t1 set v = 5;
533 end|
535 --error 1054
536 call bug2329_1()|
537 --error 1054
538 call bug2329_2()|
539 drop procedure bug2329_1|
540 drop procedure bug2329_2|
543 # BUG#3287
545 create function bug3287() returns int
546 begin
547   declare v int default null;
549   case
550     when v is not null then return 1;
551   end case;
552   return 2;
553 end|
554 --error 1339
555 select bug3287()|
556 drop function bug3287|
558 create procedure bug3287(x int)
559 case x
560 when 0 then
561   insert into test.t1 values (x, 0.1);
562 when 1 then
563   insert into test.t1 values (x, 1.1);
564 end case|
565 --error 1339
566 call bug3287(2)|
567 drop procedure bug3287|
570 # BUG#3297
572 --disable_warnings
573 drop table if exists t3|
574 --enable_warnings
575 create table t3 (s1 int, primary key (s1))|
576 insert into t3 values (5),(6)|
578 create procedure bug3279(out y int) 
579 begin
580   declare x int default 0;
581   begin
582     declare exit handler for sqlexception set x = x+1;
583     insert into t3 values (5);
584   end;
585   if x < 2 then
586     set x = x+1;
587     insert into t3 values (6);
588   end if;
589   set y = x;
590 end|
592 set @x = 0|
593 --error ER_DUP_ENTRY
594 call bug3279(@x)|
595 select @x|
596 drop procedure bug3279|
597 drop table t3|
600 # BUG#3339
602 --error 1049
603 create procedure nodb.bug3339() begin end|
606 # BUG#2653
608 create procedure bug2653_1(a int, out b int)
609   set b = aa|
611 create procedure bug2653_2(a int, out b int)
612 begin
613   if aa < 0 then
614     set b = - a;
615   else
616     set b = a;
617   end if;
618 end|
620 --error 1054
621 call bug2653_1(1, @b)|
622 --error 1054
623 call bug2653_2(2, @b)|
625 drop procedure bug2653_1|
626 drop procedure bug2653_2|
629 # BUG#4344
631 --error 1357
632 create procedure bug4344() drop procedure bug4344|
633 --error 1357
634 create procedure bug4344() drop function bug4344|
637 # BUG#3294: Stored procedure crash if table dropped before use
638 # (Actually, when an error occurs within an error handler.)
639 --disable_warnings
640 drop procedure if exists bug3294|
641 --enable_warnings
642 create procedure bug3294()
643 begin
644   declare continue handler for sqlexception drop table t5;
645   drop table t5;
646   drop table t5;
647 end|
649 create table t5 (x int)|
650 --error 1051
651 call bug3294()|
652 drop procedure bug3294|
655 # BUG#876: Stored Procedures: Invalid SQLSTATE is allowed in 
656 #          a DECLARE ? HANDLER FOR stmt.
658 --disable_warnings
659 drop procedure if exists bug8776_1|
660 drop procedure if exists bug8776_2|
661 drop procedure if exists bug8776_3|
662 drop procedure if exists bug8776_4|
663 --enable_warnings
664 --error ER_SP_BAD_SQLSTATE
665 create procedure bug8776_1()
666 begin
667   declare continue handler for sqlstate '42S0200test' begin end;
668   begin end;
669 end|
671 --error ER_SP_BAD_SQLSTATE
672 create procedure bug8776_2()
673 begin
674   declare continue handler for sqlstate '4200' begin end;
675   begin end;
676 end|
678 --error ER_SP_BAD_SQLSTATE
679 create procedure bug8776_3()
680 begin
681   declare continue handler for sqlstate '420000' begin end;
682   begin end;
683 end|
685 --error ER_SP_BAD_SQLSTATE
686 create procedure bug8776_4()
687 begin
688   declare continue handler for sqlstate '42x00' begin end;
689   begin end;
690 end|
694 # BUG#6600: Stored procedure crash after repeated calls with check table
696 --error ER_SP_BADSTATEMENT
697 create procedure bug6600()
698   check table t1|
700 # Check these two as well, while we're at it. (Although it isn't really
701 # related to the bug report, but to the fix.)
702 --error ER_SP_BADSTATEMENT
703 create procedure bug6600()
704   lock table t1 read|
705 --error ER_SP_BADSTATEMENT
706 create procedure bug6600()
707   unlock table t1|
710 # BUG#9566: explicit LOCK TABLE and store procedures result in illegal state
712 # We should not think that mysql.proc table does not exist if we are unable
713 # to open it under LOCK TABLE or in prelocked mode.
715 --disable_warnings
716 drop procedure if exists bug9566|
717 --enable_warnings
718 create procedure bug9566()
719 begin
720   select * from t1;
721 end|
722 lock table t1 read|
723 # This should fail since we forgot to lock mysql.proc for writing
724 # explicitly, and we can't open mysql.proc for _writing_ if there
725 # are locked tables.
726 --error 1100
727 alter procedure bug9566 comment 'Some comment'|
728 unlock tables|
729 # This should succeed
730 drop procedure bug9566|
734 # BUG#7299: Stored procedures: exception handler catches not-found conditions
736 --disable_warnings
737 drop procedure if exists bug7299|
738 --enable_warnings
739 create procedure bug7299()
740 begin
741   declare v int;
742   declare c cursor for select val from t1;
743   declare exit handler for sqlexception select 'Error!'; 
745   open c;
746   fetch c into v;
747 end|
749 truncate table t1|
750 --error ER_SP_FETCH_NO_DATA
751 call bug7299()|
752 drop procedure bug7299|
756 # BUG#9073: Able to declare two handlers for same condition in same scope
758 --error ER_SP_DUP_HANDLER
759 create procedure bug9073()
760 begin
761   declare continue handler for sqlexception select 1;
762   declare continue handler for sqlexception select 2;
763 end|
764 --error ER_SP_DUP_HANDLER
765 create procedure bug9073()
766 begin
767   declare condname1 condition for 1234;
768   declare continue handler for condname1 select 1;
769   declare exit handler for condname1 select 2;
770 end|
771 --error ER_SP_DUP_HANDLER
772 create procedure bug9073()
773 begin
774   declare condname1 condition for sqlstate '42000';
775   declare condname2 condition for sqlstate '42000';
776   declare exit handler for condname1 select 1;
777   declare continue handler for condname2 select 2;
778 end|
779 --error ER_SP_DUP_HANDLER
780 create procedure bug9073()
781 begin
782   declare condname1 condition for sqlstate '42000';
783   declare exit handler for condname1 select 1;
784   declare exit handler for sqlstate '42000' select 2;
785 end|
787 # This should still work.
788 --disable_warnings
789 drop procedure if exists bug9073|
790 --enable_warnings
791 create procedure bug9073()
792 begin
793   declare condname1 condition for sqlstate '42000';
794   declare continue handler for condname1 select 1;
795   begin
796     declare exit handler for sqlstate '42000' select 2;
797     begin
798       declare continue handler for sqlstate '42000' select 3;
799     end;
800   end;
801 end|
802 drop procedure bug9073|
806 # BUG#7047: Stored procedure crash if alter procedure
808 --error ER_SP_NO_DROP_SP
809 create procedure bug7047()
810   alter procedure bug7047|
811 --error ER_SP_NO_DROP_SP
812 create function bug7047() returns int
813 begin
814   alter function bug7047;
815   return 0;
816 end|
820 # BUG#8408: Stored procedure crash if function contains SHOW
821 # BUG#9058: Stored Procedures: Crash if function included SELECT
824 # Some things are caught when parsing
825 --error ER_SP_NO_RETSET
826 create function bug8408() returns int
827 begin
828   select * from t1;
829   return 0;
830 end|
831 --error ER_SP_NO_RETSET
832 create function bug8408() returns int
833 begin
834   show warnings;
835   return 0;
836 end|
837 --error ER_SP_NO_RETSET
838 create function bug8408(a int) returns int
839 begin
840   declare b int;
841   select b;
842   return b;
843 end|
845 --disable_warnings
846 drop function if exists bug8408_f|
847 drop procedure if exists bug8408_p|
848 --enable_warnings
850 # Some things must be caught at invokation time
851 create function bug8408_f() returns int
852 begin
853   call bug8408_p();
854   return 0;
855 end|
856 create procedure bug8408_p()
857   select * from t1|
859 call bug8408_p()|
860 --error ER_SP_NO_RETSET
861 select bug8408_f()|
863 drop procedure bug8408_p|
864 drop function bug8408_f|
866 # But this is ok
867 create function bug8408() returns int
868 begin
869   declare n int default 0;
870   select count(*) into n from t1;
871   return n;
872 end|
874 insert into t1 value (2, 2.7), (3, 3.14), (7, 7.0)|
875 select *,bug8408() from t1|
877 drop function bug8408|
878 truncate table t1|
882 # BUG#10537: Server crashes while loading data file into table through
883 #            procedure.
884 # Disable load until it's PS and SP safe
885 --disable_warnings
886 drop procedure if exists bug10537|
887 --enable_warnings
888 --error ER_SP_BADSTATEMENT
889 create procedure bug10537()
890   load data local infile '/tmp/somefile' into table t1|
894 # BUG#8409: Stored procedure crash if function contains FLUSH
896 --disable_warnings
897 drop function if exists bug8409|
898 --enable_warnings
899 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
900 create function bug8409()
901   returns int
902 begin
903   flush tables;
904   return 5;
905 end|
906 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
907 create function bug8409() returns int begin reset query cache;
908 return 1; end|
909 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
910 create function bug8409() returns int begin reset master;
911 return 1; end|
912 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
913 create function bug8409() returns int begin reset slave;
914 return 1; end|
915 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
916 create function bug8409() returns int begin flush hosts;
917 return 1; end|
918 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
919 create function bug8409() returns int begin flush privileges;
920 return 1; end|
921 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
922 create function bug8409() returns int begin flush tables with read lock;
923 return 1; end|
924 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
925 create function bug8409() returns int begin flush tables;
926 return 1; end|
927 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
928 create function bug8409() returns int begin flush logs;
929 return 1; end|
930 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
931 create function bug8409() returns int begin flush status;
932 return 1; end|
933 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
934 create function bug8409() returns int begin flush slave;
935 return 1; end|
936 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
937 create function bug8409() returns int begin flush master;
938 return 1; end|
939 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
940 create function bug8409() returns int begin flush des_key_file;
941 return 1; end|
942 --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
943 create function bug8409() returns int begin flush user_resources;
944 return 1; end|
948 # BUG#9529: Stored Procedures: No Warning on truncation of procedure name
949 #           during creation.
950 # BUG#17015: Routine name truncation not an error
951 #            When we started using utf8 for mysql.proc, this limit appeared
952 #            to be higher, but in reality the names were truncated.
953 --error ER_TOO_LONG_IDENT
954 create procedure bug9529_901234567890123456789012345678901234567890123456789012345()
955 begin
956 end|
958 --disable_warnings
959 drop procedure if exists bug17015_0123456789012345678901234567890123456789012345678901234|
960 --enable_warnings
961 # Check the upper limit, just to make sure.
962 create procedure bug17015_0123456789012345678901234567890123456789012345678901234()
963 begin
964 end|
966 --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
967 show procedure status like 'bug17015%'|
968 drop procedure bug17015_0123456789012345678901234567890123456789012345678901234|
972 # BUG#10969: Stored procedures: crash if default() function
974 --disable_warnings
975 drop procedure if exists bug10969|
976 --enable_warnings
977 --error ER_WRONG_COLUMN_NAME
978 create procedure bug10969()
979 begin
980   declare s1 int default 0;
981   select default(s1) from t30;
982 end|
984 # This should work
985 create procedure bug10969()
986 begin
987   declare s1 int default 0;
988   select default(t30.s1) from t30;
989 end|
991 drop procedure bug10969|
994 drop table t1|
996 delimiter ;|
998 # BUG#9814: Closing a cursor that is not open 
999 create table t1(f1 int);
1000 create table t2(f1 int);
1002 delimiter |;
1003 CREATE PROCEDURE SP001()
1004 P1: BEGIN
1005   DECLARE ENDTABLE INT DEFAULT 0;
1006   DECLARE TEMP_NUM INT;
1007   DECLARE TEMP_SUM INT;
1008   DECLARE C1 CURSOR FOR SELECT F1 FROM t1;
1009   DECLARE C2 CURSOR FOR SELECT F1 FROM t2;
1010   DECLARE CONTINUE HANDLER FOR NOT FOUND SET ENDTABLE = 1;
1012   SET ENDTABLE=0;
1013   SET TEMP_SUM=0;
1014   SET TEMP_NUM=0;
1015   
1016   OPEN C1;
1018   FETCH C1 INTO TEMP_NUM;
1019   WHILE ENDTABLE = 0 DO
1020           SET TEMP_SUM=TEMP_NUM+TEMP_SUM;
1021           FETCH C1 INTO TEMP_NUM;
1022   END WHILE;
1023   SELECT TEMP_SUM;
1024   CLOSE C1;
1025   CLOSE C1;
1026   SELECT 'end of proc';
1027 END P1|
1028 delimiter ;|
1029 --error 1326
1030 call SP001();
1031 drop procedure SP001;
1032 drop table t1, t2;
1034 # Bug #11394 "Recursion in SP crash server" and bug #11600 "Stored
1035 # procedures: crash with function calling itself".
1036 # We have to disable recursion since in many cases LEX and many
1037 # Item's can't be used in reentrant way nowdays.
1038 delimiter |;
1039 --disable_warnings
1040 drop function if exists bug11394|
1041 drop function if exists bug11394_1|
1042 drop function if exists bug11394_2|
1043 drop procedure if exists bug11394|
1044 --enable_warnings
1045 create function bug11394(i int) returns int
1046 begin
1047   if i <= 0 then
1048     return 0;
1049   else
1050     return (i in (100, 200, bug11394(i-1), 400));
1051   end if;
1052 end|
1053 # If we allow recursive functions without additional modifications
1054 # this will crash server since Item for "IN" is not reenterable.
1055 --error 1424
1056 select bug11394(2)|
1057 drop function bug11394|
1058 create function bug11394_1(i int) returns int
1059 begin
1060   if i <= 0 then
1061     return 0;
1062   else
1063     return (select bug11394_1(i-1));
1064   end if;
1065 end|
1066 # The following statement will crash because some LEX members responsible
1067 # for selects cannot be used in reentrant fashion.
1068 --error 1424
1069 select bug11394_1(2)|
1070 drop function bug11394_1|
1071 # Note that the following should be allowed since it does not contains
1072 # recursion
1073 create function bug11394_2(i int) returns int return i|
1074 select bug11394_2(bug11394_2(10))|
1075 drop function bug11394_2|
1076 create procedure bug11394(i int, j int)
1077 begin
1078   if i > 0 then
1079     call bug11394(i - 1,(select 1));
1080   end if;
1081 end|
1082 --error ER_SP_RECURSION_LIMIT
1083 call bug11394(2, 1)|
1084 set @@max_sp_recursion_depth=10|
1085 call bug11394(2, 1)|
1086 set @@max_sp_recursion_depth=default|
1087 drop procedure bug11394|
1088 delimiter ;|
1092 # BUG 12490 (Packets out of order if calling HELP CONTENTS from Stored Procedure)
1094 --error ER_SP_BADSTATEMENT
1095 CREATE PROCEDURE BUG_12490() HELP CONTENTS;
1096 --error ER_SP_BADSTATEMENT
1097 CREATE FUNCTION BUG_12490() RETURNS INT HELP CONTENTS;
1098 CREATE TABLE t_bug_12490(a int);
1099 --error ER_SP_BADSTATEMENT
1100 CREATE TRIGGER BUG_12490 BEFORE UPDATE ON t_bug_12490 FOR EACH ROW HELP CONTENTS;
1101 DROP TABLE t_bug_12490;
1104 # Bug#11834 "Re-execution of prepared statement with dropped function
1105 # crashes server". Also tests handling of prepared stmts which use
1106 # stored functions but does not require prelocking.
1108 --disable_warnings
1109 drop function if exists bug11834_1;
1110 drop function if exists bug11834_2;
1111 --enable_warnings
1112 create function bug11834_1() returns int return 10;
1113 create function bug11834_2() returns int return bug11834_1();
1114 prepare stmt from "select bug11834_2()";
1115 execute stmt;
1116 # Re-execution of statement should not crash server.
1117 execute stmt;
1118 drop function bug11834_1;
1119 # Attempt to execute statement should return proper error and 
1120 # should not crash server.
1122 # NOTE! The error we get from the below query indicates that the sp bug11834_2
1123 # does not exist(this is wrong but can be accepted)
1124 # This behaviour has been reported as bug#21294
1125 --error ER_SP_DOES_NOT_EXIST
1126 execute stmt;
1127 deallocate prepare stmt;
1128 drop function bug11834_2;
1131 # Bug#12953 "Stored procedures: crash if OPTIMIZE TABLE in function"
1133 delimiter |;
1134 --disable_warnings
1135 DROP FUNCTION IF EXISTS bug12953|
1136 --enable_warnings
1137 --error ER_SP_NO_RETSET
1138 CREATE FUNCTION bug12953() RETURNS INT
1139 BEGIN
1140   OPTIMIZE TABLE t1;
1141   RETURN 1;
1142 END|
1143 delimiter ;|
1146 # Bug##12995 "Inside function "Table 't4' was not locked with LOCK TABLES"
1148 delimiter |;
1149 --disable_warnings
1150 DROP FUNCTION IF EXISTS bug12995|
1151 --enable_warnings
1152 --error ER_SP_BADSTATEMENT
1153 CREATE FUNCTION bug12995() RETURNS INT
1154 BEGIN
1155   HANDLER t1 OPEN;
1156   RETURN 1;
1157 END|
1158 --error ER_SP_BADSTATEMENT
1159 CREATE FUNCTION bug12995() RETURNS INT
1160 BEGIN
1161   HANDLER t1 READ FIRST;
1162   RETURN 1;
1163 END|
1164 --error ER_SP_BADSTATEMENT
1165 CREATE FUNCTION bug12995() RETURNS INT
1166 BEGIN
1167   HANDLER t1 CLOSE;
1168   RETURN 1;
1169 END|
1170 --error 1305
1171 SELECT bug12995()|
1172 delimiter ;|
1176 # BUG#12712: SET AUTOCOMMIT should fail within SP/functions/triggers
1178 --disable_warnings
1179 drop procedure if exists bug12712;
1180 drop function if exists bug12712;
1181 --enable_warnings
1182 # Can...
1183 create procedure bug12712()
1184   set session autocommit = 0;
1186 select @@autocommit;
1187 set @au = @@autocommit;
1188 call bug12712();
1189 select @@autocommit;
1190 set session autocommit = @au;
1192 delimiter |;
1193 create function bug12712()
1194   returns int
1195 begin
1196   call bug12712();
1197   return 0;
1198 end|
1200 # Can't...
1201 --error ER_SP_CANT_SET_AUTOCOMMIT
1202 set @x = bug12712()|
1203 drop procedure bug12712|
1204 drop function bug12712|
1205 --error ER_SP_CANT_SET_AUTOCOMMIT
1206 create function bug12712()
1207     returns int
1208 begin
1209   set session autocommit = 0;
1210   return 0;
1211 end|
1212 --error ER_SP_CANT_SET_AUTOCOMMIT
1213 create function bug12712()
1214     returns int
1215 begin
1216   set @@autocommit = 0;
1217   return 0;
1218 end|
1219 --error ER_SP_CANT_SET_AUTOCOMMIT
1220 create function bug12712()
1221     returns int
1222 begin
1223   set local autocommit = 0;
1224   return 0;
1225 end|
1226 delimiter ;|
1227 --error ER_SP_CANT_SET_AUTOCOMMIT
1228 create trigger bug12712
1229   before insert on t1 for each row set session autocommit = 0;
1232 # BUG#9367: Stored procedures: client hang after "show warnings"
1234 --disable_parsing
1235 --disable_warnings
1236 drop procedure if exists bug9367;
1237 --enable_warnings
1238 create table t1 (s1 int);
1239 select s1 from t1;
1240 delimiter |;
1241 create procedure bug9367()
1242 begin
1243   declare v int;
1244   declare c cursor for select s1 from t1;
1245   open c;
1246   show warnings;
1247   fetch c into v;
1248   select v;
1249 end|
1250 delimiter ;|
1251 call bug9367();
1252 drop procedure bug9367;
1253 drop table t1;
1254 --enable_parsing
1257 # BUG#13510: Setting password local variable changes current password
1259 delimiter |;
1260 --disable_warnings
1261 drop procedure if exists bug13510_1|
1262 drop procedure if exists bug13510_2|
1263 drop procedure if exists bug13510_3|
1264 drop procedure if exists bug13510_4|
1265 --enable_warnings
1267 --error ER_SP_BAD_VAR_SHADOW
1268 create procedure bug13510_1()
1269 begin
1270   declare password varchar(10);
1272   set password = 'foo1';
1273   select password;
1274 end|
1276 # Check that an error message is sent
1277 --error ER_PARSE_ERROR
1278 set names='foo2'|
1280 --error ER_SP_BAD_VAR_SHADOW
1281 create procedure bug13510_2()
1282 begin
1283   declare names varchar(10);
1285   set names = 'foo2';
1286   select names;
1287 end|
1289 create procedure bug13510_3()
1290 begin
1291   declare password varchar(10);
1293   set `password` = 'foo3';
1294   select password;
1295 end|
1297 create procedure bug13510_4()
1298 begin
1299   declare names varchar(10);
1301   set `names` = 'foo4';
1302   select names;
1303 end|
1305 call bug13510_3()|
1306 call bug13510_4()|
1308 drop procedure bug13510_3|
1309 drop procedure bug13510_4|
1313 # Test that statements which implicitly commit transaction are prohibited
1314 # in stored function and triggers. Attempt to create function or trigger
1315 # containing such statement should produce error (includes test for
1316 # bug #13627).
1318 --disable_warnings
1319 drop function if exists bug_13627_f|
1320 --enable_warnings
1322 CREATE TABLE t1 (a int)|
1323 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1324 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN DROP TRIGGER test1; END |
1325 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1326 CREATE FUNCTION bug_13627_f() returns int BEGIN DROP TRIGGER test1; return 1; END |
1328 -- error ER_SP_BADSTATEMENT
1329 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN load table t1 from master; END |
1330 -- error ER_SP_BADSTATEMENT
1331 CREATE FUNCTION bug_13627_f() returns int BEGIN load table t1 from master; return 1; END |
1333 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1334 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create table t2 (a int); END |
1335 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1336 CREATE FUNCTION bug_13627_f() returns int BEGIN create table t2 (a int); return 1; END |
1338 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1339 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create index t1_i on t1 (a); END |
1340 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1341 CREATE FUNCTION bug_13627_f() returns int BEGIN create index t1_i on t1 (a); return 1; END |
1343 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1344 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter table t1 add column  b int; END |
1345 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1346 CREATE FUNCTION bug_13627_f() returns int BEGIN alter table t1 add column  b int; return 1; END |
1348 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1349 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename table t1 to t2; END |
1350 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1351 CREATE FUNCTION bug_13627_f() returns int BEGIN rename table t1 to t2; return 1; END |
1353 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1354 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN truncate table t1; END |
1355 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1356 CREATE FUNCTION bug_13627_f() returns int BEGIN truncate table t1; return 1; END |
1358 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1359 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop table t1; END |
1360 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1361 CREATE FUNCTION bug_13627_f() returns int BEGIN drop table t1; return 1; END |
1363 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1364 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop index t1_i on t1; END |
1365 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1366 CREATE FUNCTION bug_13627_f() returns int BEGIN drop index t1_i on t1; return 1; END |
1368 -- error ER_SP_BADSTATEMENT
1369 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN unlock tables; END |
1370 -- error ER_SP_BADSTATEMENT
1371 CREATE FUNCTION bug_13627_f() returns int BEGIN unlock tables; return 1; END |
1373 -- error ER_SP_BADSTATEMENT
1374 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN LOCK TABLE t1 READ; END |
1375 -- error ER_SP_BADSTATEMENT
1376 CREATE FUNCTION bug_13627_f() returns int BEGIN LOCK TABLE t1 READ; return 1; END |
1378 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1379 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create database mysqltest; END |
1380 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1381 CREATE FUNCTION bug_13627_f() returns int BEGIN create database mysqltest; return 1; END |
1383 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1384 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop database mysqltest; END |
1385 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1386 CREATE FUNCTION bug_13627_f() returns int BEGIN drop database mysqltest; return 1; END |
1388 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1389 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create user 'mysqltest_1'; END |
1390 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1391 CREATE FUNCTION bug_13627_f() returns int BEGIN create user 'mysqltest_1'; return 1; END |
1393 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1394 CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN grant select on t1 to 'mysqltest_1'; END |
1395 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1396 CREATE FUNCTION bug21975() returns int BEGIN grant select on t1 to 'mysqltest_1'; return 1; END |
1398 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1399 CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke select on t1 from 'mysqltest_1'; END |
1400 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1401 CREATE FUNCTION bug21975() returns int BEGIN revoke select on t1 from 'mysqltest_1'; return 1; END |
1403 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1404 CREATE TRIGGER bug21975 BEFORE INSERT ON t1 FOR EACH ROW BEGIN revoke all privileges on *.* from 'mysqltest_1'; END |
1405 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1406 CREATE FUNCTION bug21975() returns int BEGIN revoke all privileges on *.* from 'mysqltest_1'; return 1; END |
1408 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1409 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop user 'mysqltest_1'; END |
1410 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1411 CREATE FUNCTION bug_13627_f() returns int BEGIN drop user 'mysqltest_1'; return 1; END |
1413 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1414 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; END |
1415 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1416 CREATE FUNCTION bug_13627_f() returns int BEGIN rename user 'mysqltest_2' to 'mysqltest_1'; return 1; END |
1418 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1419 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create view v1 as select 1; END |
1420 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1421 CREATE FUNCTION bug_13627_f() returns int BEGIN create view v1 as select 1; return 1; END |
1423 -- error ER_SP_BADSTATEMENT
1424 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN alter view v1 as select 1; END |
1425 -- error ER_SP_BADSTATEMENT
1426 CREATE FUNCTION bug_13627_f() returns int BEGIN alter view v1 as select 1; return 1; END |
1428 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1429 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop view v1; END |
1430 -- error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1431 CREATE FUNCTION bug_13627_f() returns int BEGIN drop view v1; return 1; END |
1433 -- error ER_SP_NO_RECURSIVE_CREATE
1434 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create trigger tr2 before insert on t1 for each row do select 1; END |
1435 -- error ER_SP_NO_RECURSIVE_CREATE
1436 CREATE FUNCTION bug_13627_f() returns int BEGIN create trigger tr2 before insert on t1 for each row do select 1; return 1; END |
1438 -- error ER_SP_NO_DROP_SP
1439 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN drop function bug_13627_f; END |
1440 -- error ER_SP_NO_DROP_SP
1441 CREATE FUNCTION bug_13627_f() returns int BEGIN drop function bug_13627_f; return 1; END |
1443 -- error ER_SP_NO_RECURSIVE_CREATE
1444 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN create function f2 () returns int return 1; END |
1445 -- error ER_SP_NO_RECURSIVE_CREATE
1446 CREATE FUNCTION bug_13627_f() returns int BEGIN create function f2 () returns int return 1; return 1; END |
1448 CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW
1449   BEGIN
1450     CREATE TEMPORARY TABLE t2 (a int);
1451     DROP TEMPORARY TABLE t2;
1452   END |
1453 CREATE FUNCTION bug_13627_f() returns int
1454   BEGIN
1455     CREATE TEMPORARY TABLE t2 (a int);
1456     DROP TEMPORARY TABLE t2;
1457     return 1;
1458   END |
1460 drop table t1|
1461 drop function bug_13627_f|
1463 delimiter ;|
1465 # BUG#12329: "Bogus error msg when executing PS with stored procedure after
1466 # SP was re-created". See also test for related bug#13399 in trigger.test
1467 drop function if exists bug12329;
1468 --enable_warnings
1469 create table t1 as select 1 a;
1470 create table t2 as select 1 a;
1471 create function bug12329() returns int return (select a from t1);
1472 prepare stmt1 from 'select bug12329()';
1473 execute stmt1;
1474 drop function bug12329;
1475 create function bug12329() returns int return (select a+100 from t2);
1476 select bug12329();
1477 execute stmt1;
1478 deallocate prepare stmt1;
1479 drop function bug12329; 
1480 drop table t1, t2;
1483 # Bug#13514 "server crash when create a stored procedure before choose a
1484 # database" and
1485 # Bug#13587 "Server crash when SP is created without database
1486 # selected"
1488 create database mysqltest1;
1489 use mysqltest1;
1490 drop database mysqltest1;
1491 --error ER_NO_DB_ERROR 
1492 create function f1() returns int return 1;
1493 delimiter |;
1494 --error ER_NO_DB_ERROR 
1495 create procedure p1(out param1 int)
1496 begin
1497   select count(*) into param1 from t3;
1498 end|
1499 delimiter ;|
1500 use test;
1504 # BUG#13037: undefined variable in IF cause erroneous error-message
1507 --disable_warnings
1508 DROP PROCEDURE IF EXISTS bug13037_p1;
1509 DROP PROCEDURE IF EXISTS bug13037_p2;
1510 DROP PROCEDURE IF EXISTS bug13037_p3;
1511 --enable_warnings
1513 delimiter |;
1515 CREATE PROCEDURE bug13037_p1()
1516 BEGIN
1517   IF bug13037_foo THEN
1518     SELECT 1;
1519   END IF;
1520 END|
1522 CREATE PROCEDURE bug13037_p2()
1523 BEGIN
1524   SET @bug13037_foo = bug13037_bar;
1525 END|
1527 CREATE PROCEDURE bug13037_p3()
1528 BEGIN
1529   SELECT bug13037_foo;
1530 END|
1532 delimiter ;|
1534 --echo
1536 --error 1054
1537 CALL bug13037_p1();
1538 --error 1054
1539 CALL bug13037_p2();
1540 --error 1054
1541 CALL bug13037_p3();
1543 --error 1054
1544 CALL bug13037_p1();
1545 --error 1054
1546 CALL bug13037_p2();
1547 --error 1054
1548 CALL bug13037_p3();
1550 DROP PROCEDURE bug13037_p1;
1551 DROP PROCEDURE bug13037_p2;
1552 DROP PROCEDURE bug13037_p3;
1555 # Bug#14569 "editing a stored procedure kills mysqld-nt"
1557 create database mysqltest1;
1558 create database mysqltest2;
1559 use mysqltest1;
1560 drop database mysqltest1;
1561 create procedure mysqltest2.p1() select version();
1562 --error ER_NO_DB_ERROR 
1563 create procedure p2() select version();
1564 use mysqltest2;
1565 --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
1566 show procedure status;
1567 drop database mysqltest2;
1568 use test;
1571 # Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server"
1573 delimiter |;
1574 --disable_warnings
1575 DROP FUNCTION IF EXISTS bug13012|
1576 --enable_warnings
1577 --error ER_SP_NO_RETSET
1578 CREATE FUNCTION bug13012() RETURNS INT
1579 BEGIN
1580   REPAIR TABLE t1;
1581   RETURN 1;
1582 END|
1583 --error ER_SP_NO_RETSET
1584 CREATE FUNCTION bug13012() RETURNS INT
1585 BEGIN
1586   BACKUP TABLE t1 TO '/tmp';
1587   RETURN 1;
1588 END|
1589 --error ER_SP_NO_RETSET
1590 CREATE FUNCTION bug13012() RETURNS INT
1591 BEGIN
1592   RESTORE TABLE t1 FROM '/tmp';
1593   RETURN 1;
1594 END|
1595 create table t1 (a int)|
1596 CREATE PROCEDURE bug13012_1() REPAIR TABLE t1|
1597 CREATE FUNCTION bug13012_2() RETURNS INT
1598 BEGIN
1599   CALL bug13012_1();
1600   RETURN 1;
1601 END|
1602 --error ER_SP_NO_RETSET
1603 SELECT bug13012_2()|
1604 drop table t1|
1605 drop procedure bug13012_1|
1606 drop function bug13012_2|
1607 delimiter ;|
1610 # BUG#11555 "Stored procedures: current SP tables locking make 
1611 # impossible view security". We should not expose names of tables
1612 # which are implicitly used by view (via stored routines/triggers).
1614 # Note that SQL standard assumes that you simply won't be able drop table
1615 # and leave some objects (routines/views/triggers) which were depending on
1616 # it. Such objects should be dropped in advance (by default) or will be
1617 # dropped simultaneously with table (DROP TABLE with CASCADE clause).
1618 # So these tests probably should go away once we will implement standard
1619 # behavior.
1620 --disable_warnings
1621 drop function if exists bug11555_1;
1622 drop function if exists bug11555_2;
1623 drop view if exists v1, v2, v3, v4;
1624 --enable_warnings
1625 create function bug11555_1() returns int return (select max(i) from t1);
1626 create function bug11555_2() returns int return bug11555_1();
1627 # It is OK to report name of implicitly used table which is missing
1628 # when we create view.
1629 # For stored functions however, because of exceptions handlers, there is
1630 # no easy way to find out if a missing table makes the view invalid.
1631 create view v1 as select bug11555_1();
1632 drop view v1;
1633 create view v2 as select bug11555_2();
1634 drop view v2;
1635 # But we should hide name of missing implicitly used table when we use view
1636 create table t1 (i int);
1637 create view v1 as select bug11555_1();
1638 create view v2 as select bug11555_2();
1639 create view v3 as select * from v1;
1640 drop table t1;
1641 --error ER_VIEW_INVALID
1642 select * from v1;
1643 --error ER_VIEW_INVALID
1644 select * from v2;
1645 --error ER_VIEW_INVALID
1646 select * from v3;
1647 # Note that creation of view which depends on broken view is yet 
1648 # another form of view usage.
1649 create view v4 as select * from v1;
1650 drop view v1, v2, v3, v4;
1651 # We also should hide details about broken triggers which are
1652 # invoked for view.
1653 drop function bug11555_1;
1654 drop function bug11555_2;
1655 create table t1 (i int);
1656 create table t2 (i int);
1657 create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i);
1658 create view v1 as select * from t1;
1659 drop table t2;
1660 # Limitation, the desired error is ER_VIEW_INVALID
1661 --error ER_NO_SUCH_TABLE
1662 insert into v1 values (1);
1663 drop trigger t1_ai;
1664 create function bug11555_1() returns int return (select max(i) from t2);
1665 create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1();
1666 # Limitation, the desired error is ER_VIEW_INVALID
1667 --error ER_NO_SUCH_TABLE 
1668 insert into v1 values (2);
1669 drop function bug11555_1;
1670 drop table t1;
1671 drop view v1;
1674 # BUG#15658: Server crashes after creating function as empty string
1676 --disable_warnings
1677 drop procedure if exists ` bug15658`;
1678 --enable_warnings
1680 --error ER_SP_WRONG_NAME
1681 create procedure ``() select 1;
1682 --error ER_SP_WRONG_NAME
1683 create procedure ` `() select 1;
1684 --error ER_SP_WRONG_NAME
1685 create procedure `bug15658 `() select 1;
1686 --error ER_WRONG_DB_NAME
1687 create procedure ``.bug15658() select 1;
1688 --error ER_WRONG_DB_NAME
1689 create procedure `x `.bug15658() select 1;
1691 # This should work
1692 create procedure ` bug15658`() select 1;
1693 call ` bug15658`();
1694 --replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00'
1695 show procedure status;
1696 drop procedure ` bug15658`;
1700 # BUG#14270: Stored procedures: crash if load index
1702 --disable_warnings
1703 drop function if exists bug14270;
1704 drop table if exists t1;
1705 --enable_warnings
1707 create table t1 (s1 int primary key);
1709 delimiter |;
1710 --error ER_SP_NO_RETSET
1711 create function bug14270() returns int
1712 begin
1713   load index into cache t1;
1714   return 1;
1715 end|
1717 --error ER_SP_NO_RETSET
1718 create function bug14270() returns int
1719 begin
1720   cache index t1 key (`primary`) in keycache1;
1721   return 1;
1722 end|
1723 delimiter ;|
1725 drop table t1;
1729 # BUG#15091: Sp Returns Unknown error in order clause....and 
1730 #            there is no order by clause
1732 --disable_warnings
1733 drop procedure if exists bug15091;
1734 --enable_warnings
1736 delimiter |;
1737 create procedure bug15091()
1738 begin
1739   declare selectstr varchar(6000) default ' ';
1740   declare conditionstr varchar(5000)  default '';
1742   set selectstr = concat(selectstr,
1743                          ' and ',
1744                          c.operatorid,
1745                          'in (',conditionstr, ')');
1746 end|
1747 delimiter ;|
1749 # The error message used to be:
1750 #   ERROR 1109 (42S02): Unknown table 'c' in order clause
1751 # but is now rephrased to something less misleading:
1752 #   ERROR 1109 (42S02): Unknown table 'c' in field list
1753 --error ER_UNKNOWN_TABLE
1754 call bug15091();
1756 drop procedure bug15091;
1760 # BUG#16896: Stored function: unused AGGREGATE-clause in CREATE FUNCTION
1762 --disable_warnings
1763 drop function if exists bug16896;
1764 --enable_warnings
1766 --error ER_PARSE_ERROR
1767 create aggregate function bug16896() returns int return 1;
1771 # BUG#14702: misleading error message when syntax error in CREATE
1772 # PROCEDURE
1774 # Misleading error message was given when IF NOT EXISTS was used in
1775 # CREATE PROCEDURE.
1777 --disable_warnings
1778 DROP PROCEDURE IF EXISTS bug14702;
1779 --enable_warnings
1781 --error ER_PARSE_ERROR
1782 CREATE IF NOT EXISTS PROCEDURE bug14702()
1783 BEGIN
1784 END;
1786 --error ER_PARSE_ERROR
1787 CREATE PROCEDURE IF NOT EXISTS bug14702()
1788 BEGIN
1789 END;
1793 # BUG#20953: create proc with a create view that uses local
1794 # vars/params should fail to create
1796 # See test case for what syntax is forbidden in a view.
1798 --disable_warnings
1799 DROP TABLE IF EXISTS t1;
1800 --enable_warnings
1802 CREATE TABLE t1 (i INT);
1804 # We do not have to drop this procedure and view because they won't be
1805 # created.
1806 --error ER_VIEW_SELECT_CLAUSE
1807 CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a;
1808 --error ER_VIEW_SELECT_CLAUSE
1809 CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file";
1810 --error ER_VIEW_SELECT_CLAUSE
1811 CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file";
1812 --error ER_VIEW_SELECT_CLAUSE
1813 CREATE PROCEDURE bug20953()
1814   CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
1815 --error ER_VIEW_SELECT_DERIVED
1816 CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1;
1817 --error ER_VIEW_SELECT_VARIABLE
1818 CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i;
1819 delimiter |;
1820 --error ER_VIEW_SELECT_VARIABLE
1821 CREATE PROCEDURE bug20953()
1822 BEGIN
1823   DECLARE i INT;
1824   CREATE VIEW v AS SELECT i;
1825 END |
1826 delimiter ;|
1827 --error ER_VIEW_SELECT_VARIABLE
1828 PREPARE stmt FROM "CREATE VIEW v AS SELECT ?";
1830 DROP TABLE t1;
1834 # BUG#24491 "using alias from source table in insert ... on duplicate key"
1836 --disable_warnings
1837 drop tables if exists t1;
1838 drop procedure if exists bug24491;
1839 --enable_warnings
1840 create table t1 (id int primary key auto_increment, value varchar(10));
1841 insert into t1 (id, value) values (1, 'FIRST'), (2, 'SECOND'), (3, 'THIRD');
1842 # Let us create routine with INSERT ... SELECT ... ON DUPLICATE KEY UPDATE 
1843 # statement which in its ON DUPLICATE KEY clause erroneously tries to assign
1844 # value to a column which is mentioned only in SELECT part.
1845 create procedure bug24491()
1846   insert into t1 (id, value) select * from (select 4 as i, 'FOURTH' as v) as y on duplicate key update v = 'DUP';
1847 # Both first and second calls to it should fail
1848 --error ER_BAD_FIELD_ERROR 
1849 call bug24491();
1850 --error ER_BAD_FIELD_ERROR
1851 call bug24491();
1852 drop procedure bug24491;
1853 # And now the same test for more complex case which is more close
1854 # to the one that was reported originally.
1855 create procedure bug24491()
1856   insert into t1 (id, value) select * from (select 4 as id, 'FOURTH' as value) as y on duplicate key update y.value = 'DUP';
1857 --error ER_BAD_FIELD_ERROR 
1858 call bug24491();
1859 --error ER_BAD_FIELD_ERROR
1860 call bug24491();
1861 drop procedure bug24491;
1862 drop tables t1;
1865 # BUG#18914: Calling certain SPs from triggers fail
1867 # Failing to call a procedure that does implicit commit from a trigger
1868 # is a correct behaviour, however the error message was misleading.
1870 # DROP TABLE IF EXISTS is also fixed to give correct error instead of
1871 # "Table doesn't exist". 
1873 --disable_warnings
1874 DROP FUNCTION IF EXISTS bug18914_f1;
1875 DROP FUNCTION IF EXISTS bug18914_f2;
1876 DROP PROCEDURE IF EXISTS bug18914_p1;
1877 DROP PROCEDURE IF EXISTS bug18914_p2;
1878 DROP TABLE IF EXISTS t1, t2;
1879 --enable_warnings
1881 CREATE TABLE t1 (i INT);
1883 CREATE PROCEDURE bug18914_p1() CREATE TABLE t2 (i INT);
1884 CREATE PROCEDURE bug18914_p2() DROP TABLE IF EXISTS no_such_table;
1886 delimiter |;
1887 CREATE FUNCTION bug18914_f1() RETURNS INT
1888 BEGIN
1889   CALL bug18914_p1();
1890   RETURN 1;
1891 END |
1893 CREATE FUNCTION bug18914_f2() RETURNS INT
1894 BEGIN
1895   CALL bug18914_p2();
1896   RETURN 1;
1897 END |
1898 delimiter ;|
1900 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
1901   CALL bug18914_p1();
1903 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1904 INSERT INTO t1 VALUES (1);
1906 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1907 SELECT bug18914_f1();
1909 --error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
1910 SELECT bug18914_f2();
1912 --error ER_NO_SUCH_TABLE
1913 SELECT * FROM t2;
1915 DROP FUNCTION bug18914_f1;
1916 DROP FUNCTION bug18914_f2;
1917 DROP PROCEDURE bug18914_p1;
1918 DROP PROCEDURE bug18914_p2;
1919 DROP TABLE t1;
1922 # Bug#20713 (Functions will not not continue for SQLSTATE VALUE '42S02')
1925 --disable_warnings
1926 drop table if exists bogus_table_20713;
1927 drop function if exists func_20713_a;
1928 drop function if exists func_20713_b;
1929 --enable_warnings
1931 create table bogus_table_20713( id int(10) not null primary key);
1932 insert into bogus_table_20713 values (1), (2), (3);
1934 delimiter //;
1936 create function func_20713_a() returns int(11)
1937 begin
1938   declare id int;
1940   declare continue handler for sqlexception set id=null;
1942   set @in_func := 1;
1943   set id = (select id from bogus_table_20713 where id = 3);
1944   set @in_func := 2;
1946   return id;
1947 end//
1949 create function func_20713_b() returns int(11)
1950 begin
1951   declare id int;
1953   declare continue handler for sqlstate value '42S02' set id=null;
1955   set @in_func := 1;
1956   set id = (select id from bogus_table_20713 where id = 3);
1957   set @in_func := 2;
1959   return id;
1960 end//
1962 delimiter ;//
1964 set @in_func := 0;
1965 select func_20713_a();
1966 select @in_func;
1968 set @in_func := 0;
1969 select func_20713_b();
1970 select @in_func;
1972 drop table bogus_table_20713;
1974 set @in_func := 0;
1975 select func_20713_a();
1976 select @in_func;
1978 set @in_func := 0;
1979 select func_20713_b();
1980 select @in_func;
1982 drop function if exists func_20713_a;
1983 drop function if exists func_20713_b;
1986 # Bug#25345 (Cursors from Functions)
1989 --disable_warnings
1990 drop table if exists table_25345_a;
1991 drop table if exists table_25345_b;
1992 drop procedure if exists proc_25345;
1993 drop function if exists func_25345;
1994 drop function if exists func_25345_b;
1995 --enable_warnings
1997 create table table_25345_a (a int);
1998 create table table_25345_b (b int);
2000 delimiter ||;
2002 create procedure proc_25345()
2003 begin
2004   declare c1 cursor for select a from table_25345_a;
2005   declare c2 cursor for select b from table_25345_b;
2007   select 1 as result;
2008 end ||
2010 create function func_25345() returns int(11)
2011 begin
2012   call proc_25345();
2013   return 1;
2014 end ||
2016 create function func_25345_b() returns int(11)
2017 begin
2018   declare c1 cursor for select a from table_25345_a;
2019   declare c2 cursor for select b from table_25345_b;
2021   return 1;
2022 end ||
2024 delimiter ;||
2026 call proc_25345();
2027 --error ER_SP_NO_RETSET
2028 select func_25345();
2029 select func_25345_b();
2031 drop table table_25345_a;
2033 call proc_25345();
2034 --error ER_SP_NO_RETSET
2035 select func_25345();
2036 select func_25345_b();
2038 drop table table_25345_b;
2039 drop procedure proc_25345;
2040 drop function func_25345;
2041 drop function func_25345_b;
2044 # End of 5.0 tests
2046 --echo End of 5.0 tests
2049 # Bug#16164 "Easter egg": check that SHOW AUTHORS is disabled in
2050 # stored functions/triggers
2052 --disable_warnings
2053 drop function if exists bug16164;
2054 --enable_warnings
2055 delimiter |;
2056 --error ER_SP_NO_RETSET
2057 create function bug16164() returns int
2058 begin
2059   show authors;
2060   return 42;
2061 end|
2062 delimiter ;|
2066 # BUG#20701: BINARY keyword should be forbidden in stored routines
2068 --disable_warnings
2069 drop function if exists bug20701;
2070 --enable_warnings
2072 # This was disabled in 5.1.12. See bug #20701
2073 # When collation support in SP is implemented, then this test should
2074 # be removed.
2076 --error ER_NOT_SUPPORTED_YET
2077 create function bug20701() returns varchar(25) binary return "test";
2078 create function bug20701() returns varchar(25) return "test";
2079 drop function bug20701;
2082 # Bug#26503 (Illegal SQL exception handler code causes the server to crash)
2085 delimiter //;
2087 --error ER_SP_LILABEL_MISMATCH
2088 create procedure proc_26503_error_1()
2089 begin
2090 retry:
2091   repeat
2092     begin
2093       declare continue handler for sqlexception
2094       begin
2095         iterate retry;
2096       end
2098       select "do something";
2099     end
2100   until true end repeat retry;
2101 end//
2103 --error ER_SP_LILABEL_MISMATCH
2104 create procedure proc_26503_error_2()
2105 begin
2106 retry:
2107   repeat
2108     begin
2109       declare continue handler for sqlexception
2110         iterate retry;
2112       select "do something";
2113     end
2114   until true end repeat retry;
2115 end//
2117 --error ER_SP_LILABEL_MISMATCH
2118 create procedure proc_26503_error_3()
2119 begin
2120 retry:
2121   repeat
2122     begin
2123       declare continue handler for sqlexception
2124       begin
2125         leave retry;
2126       end
2128       select "do something";
2129     end
2130   until true end repeat retry;
2131 end//
2133 --error ER_SP_LILABEL_MISMATCH
2134 create procedure proc_26503_error_4()
2135 begin
2136 retry:
2137   repeat
2138     begin
2139       declare continue handler for sqlexception
2140         leave retry;
2142       select "do something";
2143     end
2144   until true end repeat retry;
2145 end//
2147 delimiter ;//
2151 # Bug#28360 (RENAME DATABASE destroys routines)
2154 --disable_warnings
2155 drop procedure if exists proc_28360;
2156 drop function if exists func_28360;
2157 --enable_warnings
2159 delimiter //;
2161 --error ER_SP_NO_DROP_SP
2162 CREATE PROCEDURE proc_28360()
2163 BEGIN
2164   ALTER DATABASE `#mysql50#upgrade-me` UPGRADE DATA DIRECTORY NAME;
2165 END//
2167 --error ER_SP_NO_DROP_SP
2168 CREATE FUNCTION func_28360() RETURNS int
2169 BEGIN
2170   ALTER DATABASE `#mysql50#upgrade-me` UPGRADE DATA DIRECTORY NAME;
2171   RETURN 0;
2172 END//
2174 delimiter ;//
2178 # Bug#29223 declare cursor c for SHOW .....
2181 --disable_warnings
2182 DROP PROCEDURE IF EXISTS p1;
2183 --enable_warnings
2184 --delimiter |
2185 --error ER_PARSE_ERROR
2186 CREATE PROCEDURE p1()
2187 BEGIN
2188   DECLARE c char(100);
2189   DECLARE cur1 CURSOR FOR SHOW TABLES;
2191   OPEN cur1;
2192   FETCH cur1 INTO c;
2193   select c;
2194   CLOSE cur1;
2195 END|
2196 --delimiter ;
2199 # Bug#29816 Syntactically wrong query fails with misleading error message
2202 --disable_warnings
2203 DROP DATABASE IF EXISTS mysqltest;
2204 --enable_warnings
2205 CREATE DATABASE mysqltest;
2206 USE mysqltest;
2207 DROP DATABASE mysqltest;
2208 # Both ER_SP_DOES_NOT_EXIST and ER_PARSE_ERROR are valid here,
2209 # the result is implementation dependent:
2210 # See Bug#29816 for details
2211 --error ER_SP_DOES_NOT_EXIST
2212 SELECT inexistent(), 1 + ,;
2213 --error ER_SP_DOES_NOT_EXIST
2214 SELECT inexistent();
2215 --error ER_PARSE_ERROR
2216 SELECT .inexistent();
2217 --error ER_PARSE_ERROR
2218 SELECT ..inexistent();
2219 USE test;
2222 # Bug#30904 SET PASSWORD statement is non-transactional
2225 delimiter |;
2227 --error ER_SP_CANT_SET_AUTOCOMMIT
2228 create function f1() returns int
2229 begin
2230   set @test = 1, password = password('foo');
2231   return 1;
2232 end|
2234 --error ER_SP_CANT_SET_AUTOCOMMIT
2235 create trigger t1
2236   before insert on t2 for each row set password = password('foo');|
2238 delimiter ;|
2241 # Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
2244 --disable_warnings
2245 drop function if exists f1;
2246 drop function if exists f2;
2247 drop table if exists t1, t2;
2248 --enable_warnings
2250 delimiter |;
2251 create function f1() returns int
2252 begin
2253  drop temporary table t1;
2254  return 1;
2255 end|
2256 delimiter ;|
2257 --error ER_CANT_REOPEN_TABLE
2258 create temporary table t1 as select f1();
2260 delimiter |;
2261 create function f2() returns int
2262 begin
2263  create temporary table t2 as select f1();
2264  return 1;
2265 end|
2266 delimiter ;|
2267 --error ER_CANT_REOPEN_TABLE
2268 create temporary table t1 as select f2();
2270 drop function f1;
2271 drop function f2;
2273 delimiter |;
2274 create function f1() returns int
2275 begin
2276  drop temporary table t2,t1;
2277  return 1;
2278 end|
2279 create function f2() returns int
2280 begin
2281  create temporary table t2 as select f1();
2282  return 1;
2283 end|
2284 delimiter ;|
2285 --error ER_CANT_REOPEN_TABLE
2286 create temporary table t1 as select f2();
2288 drop function f1;
2289 drop function f2;
2291 create temporary table t2(a int);
2292 select * from t2;
2293 delimiter |;
2294 create function f2() returns int
2295 begin
2296  drop temporary table t2;
2297  return 1;
2298 end|
2299 delimiter ;|
2300 select f2();
2302 drop function f2;
2303 --error ER_BAD_TABLE_ERROR
2304 drop table t2;
2306 --echo End of 5.1 tests
2309 # Bug#33983 (Stored Procedures: wrong end <label> syntax is accepted)
2312 --disable_warnings
2313 drop procedure if exists proc_33983_a;
2314 drop procedure if exists proc_33983_b;
2315 drop procedure if exists proc_33983_c;
2316 drop procedure if exists proc_33983_d;
2317 --enable_warnings
2319 delimiter |;
2321 --error ER_SP_LABEL_MISMATCH
2322 create procedure proc_33983_a()
2323 begin
2324   label1:
2325     begin
2326       label2:
2327       begin
2328         select 1;
2329       end label1;
2330     end;
2331 end|
2333 --error ER_SP_LABEL_MISMATCH
2334 create procedure proc_33983_b()
2335 begin
2336   label1:
2337     repeat
2338       label2:
2339       repeat
2340         select 1;
2341       until FALSE end repeat label1;
2342     until FALSE end repeat;
2343 end|
2345 --error ER_SP_LABEL_MISMATCH
2346 create procedure proc_33983_c()
2347 begin
2348   label1:
2349     while TRUE do
2350       label2:
2351       while TRUE do
2352         select 1;
2353       end while label1;
2354     end while;
2355 end|
2357 --error ER_SP_LABEL_MISMATCH
2358 create procedure proc_33983_d()
2359 begin
2360   label1:
2361     loop
2362       label2:
2363       loop
2364         select 1;
2365       end loop label1;
2366     end loop;
2367 end|
2369 CREATE TABLE t1 (a INT)|
2370 INSERT INTO t1 VALUES (1),(2)|
2371 CREATE PROCEDURE p1(a INT) BEGIN END|
2372 --error ER_SUBQUERY_NO_1_ROW
2373 CALL p1((SELECT * FROM t1))|
2374 DROP PROCEDURE IF EXISTS p1|
2375 DROP TABLE t1|
2377 delimiter ;|
2380 # Bug#21801: SQL exception handlers and warnings
2383 --disable_warnings
2384 drop procedure if exists p1;
2385 --enable_warnings
2386 delimiter |;
2387 create procedure p1()
2388 begin
2389   create table t1 (a int) type=MyISAM;
2390   drop table t1;
2391 end|
2392 delimiter ;|
2393 call p1();
2394 call p1();
2395 drop procedure p1;
2398 # Bug#8759 (Stored Procedures: SQLSTATE '00000' should be illegal)
2401 --disable_warnings
2402 drop procedure if exists proc_8759;
2403 --enable_warnings
2405 delimiter $$;
2407 --error ER_SP_BAD_SQLSTATE
2408 create procedure proc_8759()
2409 begin
2410   declare should_be_illegal condition for sqlstate '00000';
2411   declare continue handler for should_be_illegal set @x=0;
2412 end$$
2414 --error ER_SP_BAD_SQLSTATE
2415 create procedure proc_8759()
2416 begin
2417   declare continue handler for sqlstate '00000' set @x=0;
2418 end$$
2420 delimiter ;$$
2424 # BUG#NNNN: New bug synopsis
2426 #--disable_warnings
2427 #drop procedure if exists bugNNNN;
2428 #drop function if exists bugNNNN;
2429 #--enable_warnings
2430 #create procedure bugNNNN...
2431 #create function bugNNNN...
2434 # CLEANUP and RESTORE
2436 LOAD DATA INFILE '../../tmp/proc.txt' INTO TABLE mysql.proc;
2437 remove_file $MYSQLTEST_VARDIR/tmp/proc.txt;
2440 # Bug #38159: Function parsing problem generates misleading error message
2443 CREATE TABLE t1 (a INT, b INT);
2444 INSERT INTO t1 VALUES (1,1), (2,2);
2445 --error ER_FUNC_INEXISTENT_NAME_COLLISION
2446 SELECT MAX (a) FROM t1 WHERE b = 999999;
2447 SELECT AVG (a) FROM t1 WHERE b = 999999;
2448 --error ER_SP_DOES_NOT_EXIST
2449 SELECT non_existent (a) FROM t1 WHERE b = 999999;
2450 DROP TABLE t1;
2452 --echo #
2453 --echo # Bug #47788: Crash in TABLE_LIST::hide_view_error on UPDATE + VIEW + 
2454 --echo #   SP + MERGE + ALTER
2455 --echo #
2457 CREATE TABLE t1 (pk INT, b INT, KEY (b));
2458 CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM t1;
2460 CREATE PROCEDURE p1 (a int) UPDATE IGNORE v1 SET b = a; 
2462 --error ER_NON_UPDATABLE_TABLE
2463 CALL p1(5);
2465 ALTER TABLE t1 CHANGE COLUMN b b2 INT;
2467 --error ER_VIEW_INVALID
2468 CALL p1(7);
2470 DROP PROCEDURE p1;
2471 DROP VIEW v1;
2472 DROP TABLE t1;
2474 --echo #
2475 --echo # Bug#12428824 - PARSER STACK OVERFLOW AND CRASH IN SP_ADD_USED_ROUTINE
2476 --echo #                WITH OBSCURE QUERY
2477 --echo #
2479 --error ER_TOO_LONG_IDENT
2480 SELECT very_long_fn_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999();
2482 --error ER_TOO_LONG_IDENT
2483 CALL very_long_pr_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999();
2485 --error ER_WRONG_DB_NAME
2486 SELECT very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999.simple_func();
2488 --error ER_WRONG_DB_NAME
2489 CALL very_long_db_name_1111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222225555555555555555555555555577777777777777777777777777777777777777777777777777777777777777777777777788888888999999999999999999999.simple_proc();
2491 --error ER_TOO_LONG_IDENT
2492 SELECT db_name.very_long_fn_name_111111111111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999999999999999999();
2494 --error ER_TOO_LONG_IDENT
2495 CALL db_name.very_long_pr_name_111111111111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999999999999999999();
2496 --echo End of 5.1 tests