📄 sp-error.test
字号:
## Stored PROCEDURE error tests#--disable_warningsdrop table if exists t1, t2;--enable_warnings# Make sure we don't have any procedures left.delete from mysql.proc;delimiter |;# This should give three syntax errors (sometimes crashed; bug #643)# (Unfortunately, this is not a 100% test, on some platforms this# passed despite the bug.)--error 1064create procedure syntaxerror(t int)|--error 1064create procedure syntaxerror(t int)|--error 1064create procedure syntaxerror(t int)|# Check that we get the right error, i.e. UDF declaration parses correctly,# but foo.so doesn't exist.# This generates an error message containing a misleading errno which# might vary between systems (it usually doesn't have anything to do with# the actual failing dlopen()).#--error 1126#create function foo returns real soname "foo.so"|--disable_warningsdrop table if exists t3|--enable_warningscreate table t3 ( x int )|insert into t3 values (2), (3)|create procedure bad_into(out param int) select x from t3 into param|--error 1172call bad_into(@x)|drop procedure bad_into|drop table t3|create procedure proc1() set @x = 42|create function func1() returns int return 42|# Can't create recursively--error 1303create procedure foo() create procedure bar() set @x=3|--error 1303create procedure foo() create function bar() returns double return 2.3|# Already exists--error 1304create procedure proc1() set @x = 42|--error 1304create function func1() returns int return 42|drop procedure proc1|drop function func1|# Does not exist--error 1305alter procedure foo|--error 1305alter function foo|--error 1305drop procedure foo|--error 1305drop function foo|--error 1305call foo()|drop procedure if exists foo|--error 1305show create procedure foo|--error 1305show create function foo|# LEAVE/ITERATE with no match--error 1308create procedure foo()foo: loop leave bar;end loop|--error 1308create procedure foo()foo: loop iterate bar;end loop|--error 1308create procedure foo()foo: begin iterate foo;end|# Redefining label--error 1309create procedure foo()foo: loop foo: loop set @x=2; end loop foo;end loop foo|# End label mismatch--error 1310create procedure foo()foo: loop set @x=2;end loop bar|# RETURN in FUNCTION only--error 1313create procedure foo() return 42|# Wrong number of argumentscreate procedure p(x int) set @x = x|create function f(x int) returns int return x+42|--error 1318call p()|--error 1318call p(1, 2)|--error 1318select f()|--error 1318select f(1, 2)|drop procedure p|drop function f|--error 1319 create procedure p(val int, out res int)begin declare x int default 0; declare continue handler for foo set x = 1; insert into test.t1 values (val); if (x) then set res = 0; else set res = 1; end if;end|--error 1319 create procedure p(val int, out res int)begin declare x int default 0; declare foo condition for 1146; declare continue handler for bar set x = 1; insert into test.t1 values (val); if (x) then set res = 0; else set res = 1; end if;end|--error 1320create function f(val int) returns intbegin declare x int; set x = val+3;end|create function f(val int) returns intbegin declare x int; set x = val+3; if x < 4 then return x; end if;end|--error 1321select f(10)|drop function f|--error 1322create procedure p()begin declare c cursor for insert into test.t1 values ("foo", 42); open c; close c;end|--error 1323create procedure p()begin declare x int; declare c cursor for select * into x from test.t limit 1; open c; close c;end|--error 1324create procedure p()begin declare c cursor for select * from test.t; open cc; close c;end|--disable_warningsdrop table if exists t1|--enable_warningscreate table t1 (val int)|create procedure p()begin declare c cursor for select * from test.t1; open c; open c; close c;end|--error 1325call p()|drop procedure p|create procedure p()begin declare c cursor for select * from test.t1; open c; close c; close c;end|--error 1326call p()|drop procedure p|--error 1305alter procedure bar3 sql security invoker|drop table t1|--disable_warningsdrop table if exists t1|--enable_warningscreate table t1 (val int, x float)|insert into t1 values (42, 3.1), (19, 1.2)|--error 1327create procedure p()begin declare x int; declare c cursor for select * from t1; open c; fetch c into x, y; close c;end|create procedure p()begin declare x int; declare c cursor for select * from t1; open c; fetch c into x; close c;end|--error 1328call p()|drop procedure p|create procedure p()begin declare x int; declare y float; declare z int; declare c cursor for select * from t1; open c; fetch c into x, y, z; close c;end|--error 1328call p()|drop procedure p|--error 1330create procedure p(in x int, x char(10))beginend|--error 1330create function p(x int, x char(10))beginend|--error 1331create procedure p()begin declare x float; declare x int;end|--error 1332create procedure p()begin declare c condition for 1064; declare c condition for 1065;end|--error 1333create procedure p()begin declare c cursor for select * from t1; declare c cursor for select field from t1;end|# USE is not allowed--error ER_SP_BADSTATEMENT create procedure u() use sptmp|# Enforced standard order of declarations--error 1337create procedure p()begin declare c cursor for select * from t1; declare x int;end|--error 1337create procedure p()begin declare x int; declare continue handler for sqlstate '42S99' set x = 1; declare foo condition for sqlstate '42S99';end|--error 1338create procedure p()begin declare x int; declare continue handler for sqlstate '42S99' set x = 1; declare c cursor for select * from t1;end|# Check in and inout arguments.--disable_warningsdrop procedure if exists p|--enable_warningscreate procedure p(in x int, inout y int, out z int)begin set y = x+y; set z = x+y;end|set @tmp_x = 42|set @tmp_y = 3|set @tmp_z = 0|# For reference: this is okcall p(@tmp_x, @tmp_y, @tmp_z)|select @tmp_x, @tmp_y, @tmp_z|--error ER_SP_NOT_VAR_ARGcall p(42, 43, @tmp_z)|--error ER_SP_NOT_VAR_ARGcall p(42, @tmp_y, 43)|drop procedure p|## Let us test that we can access mysql.proc table for routines# definitions lookup without locking it explicitly.#create procedure p() begin end|lock table t1 read|# This should succeedcall p()|unlock tables|drop procedure p|# Let us check restrictions which this ability puts on mysql.proc locking.--error ER_WRONG_LOCK_OF_SYSTEM_TABLElock tables t1 read, mysql.proc write|--error ER_WRONG_LOCK_OF_SYSTEM_TABLElock tables mysql.proc write, mysql.user write|# Locking for read should be OKlock tables t1 read, mysql.proc read|unlock tables|# You also should be able lock only mysql.proc for writelock tables mysql.proc write|unlock tables|## Check that in functions we don't allow to update tables which# are used by statements which invoke these functions.#--disable_warningsdrop function if exists f1|--enable_warningscreate function f1(i int) returns intbegin insert into t1 (val) values (i); return 0;end|--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRGselect val, f1(val) from t1|# Table alias should not matter--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRGselect val, f1(val) from t1 as tab|select * from t1|--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRGupdate t1 set val= f1(val)|select * from t1|# But this should be OKselect f1(17)|select * from t1|# Cleanupdelete from t1 where val= 17|drop function f1|## BUG#1965#create procedure bug1965()begin declare c cursor for select val from t1 order by valname; open c; close c;end|--error 1054call bug1965()|drop procedure bug1965|## BUG#1966#--error 1327select 1 into a|## BUG#1653#--disable_warningsdrop table if exists t3|--enable_warningscreate table t3 (column_1_0 int)|create procedure bug1653() update t3 set column_1 = 0|--error 1054call bug1653()|drop table t3|create table t3 (column_1 int)|call bug1653()|drop procedure bug1653|drop table t3|## BUG#2259## Note: When this bug existed, it did not necessarily cause a crash# in all builds, but valgrind did give warnings.create procedure bug2259()begin declare v1 int; declare c1 cursor for select s1 from t1; fetch c1 into v1;end|--error 1326call bug2259()|drop procedure bug2259|## BUG#2272#create procedure bug2272()begin declare v int; update t1 set v = 42;end|insert into t1 values (666, 51.3)|--error 1054call bug2272()|delete from t1|drop procedure bug2272|## BUG#2329#create procedure bug2329_1()begin declare v int; insert into t1 (v) values (5);end|create procedure bug2329_2()begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -