From 363503853966c740bc4e77062205d782fda3f010 Mon Sep 17 00:00:00 2001 From: LINxiansheng Date: Tue, 13 Dec 2022 04:18:53 +0000 Subject: [PATCH] public some pl cases and fix a rpm building bug --- cmake/RPM.cmake | 1 - tools/deploy/mysql_test/include/sp-vars.inc | 131 + .../include/wait_until_disconnected.inc | 21 + .../pl/r/mysql/pl_basic_mysql.result | 2385 +++++ .../pl/r/mysql/pl_dbt2_mysql.result | 1459 +++ .../r/mysql/pl_exception_basic_mysql.result | 1559 +++ .../pl/r/mysql/pl_exception_mysql.result | 358 + .../pl/r/mysql/sp-bugs_mysql.result | 253 + .../test_suite/pl/r/mysql/sp-fib_mysql.result | 44 + .../pl/r/mysql/sp-vars_mysql.result | 1711 +++ .../test_suite/pl/r/mysql/sp_mysql.result | 7600 ++++++++++++++ .../test_suite/pl/t/pl_basic_mysql.test | 2113 ++++ .../test_suite/pl/t/pl_dbt2_mysql.test | 1436 +++ .../pl/t/pl_exception_basic_mysql.test | 1491 +++ .../test_suite/pl/t/pl_exception_mysql.test | 378 + .../test_suite/pl/t/sp-bugs_mysql.test | 252 + .../test_suite/pl/t/sp-fib_mysql.test | 63 + .../test_suite/pl/t/sp-vars_mysql.test | 1518 +++ .../mysql_test/test_suite/pl/t/sp_mysql.test | 9231 +++++++++++++++++ 19 files changed, 32003 insertions(+), 1 deletion(-) create mode 100644 tools/deploy/mysql_test/include/sp-vars.inc create mode 100644 tools/deploy/mysql_test/include/wait_until_disconnected.inc create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_basic_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_dbt2_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_exception_basic_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_exception_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-bugs_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-fib_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-vars_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/r/mysql/sp_mysql.result create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/pl_basic_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/pl_dbt2_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/pl_exception_basic_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/pl_exception_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/sp-bugs_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/sp-fib_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/sp-vars_mysql.test create mode 100644 tools/deploy/mysql_test/test_suite/pl/t/sp_mysql.test diff --git a/cmake/RPM.cmake b/cmake/RPM.cmake index 55abea83e..f4525ccbd 100644 --- a/cmake/RPM.cmake +++ b/cmake/RPM.cmake @@ -224,7 +224,6 @@ install(FILES deps/oblib/src/lib/lock/ob_spin_rwlock.h deps/oblib/src/lib/lock/ob_thread_cond.h deps/oblib/src/lib/lock/ob_rwlock.h - deps/oblib/src/lib/lock/threadmutex.h deps/oblib/src/lib/metrics/ob_counter.h deps/oblib/src/lib/net/ob_addr.h deps/oblib/src/lib/net/ob_net_util.h diff --git a/tools/deploy/mysql_test/include/sp-vars.inc b/tools/deploy/mysql_test/include/sp-vars.inc new file mode 100644 index 000000000..46794c2ef --- /dev/null +++ b/tools/deploy/mysql_test/include/sp-vars.inc @@ -0,0 +1,131 @@ +delimiter |; + +# -------------------------------------------------------------------------- + +CREATE PROCEDURE sp_vars_check_dflt() +BEGIN + DECLARE v1 TINYINT DEFAULT 1e200; + DECLARE v1u TINYINT UNSIGNED DEFAULT 1e200; + DECLARE v2 TINYINT DEFAULT -1e200; + DECLARE v2u TINYINT UNSIGNED DEFAULT -1e200; + DECLARE v3 TINYINT DEFAULT 300; + DECLARE v3u TINYINT UNSIGNED DEFAULT 300; + DECLARE v4 TINYINT DEFAULT -300; + DECLARE v4u TINYINT UNSIGNED DEFAULT -300; + + DECLARE v5 TINYINT DEFAULT 10 * 10 * 10; + DECLARE v5u TINYINT UNSIGNED DEFAULT 10 * 10 * 10; + DECLARE v6 TINYINT DEFAULT -10 * 10 * 10; + DECLARE v6u TINYINT UNSIGNED DEFAULT -10 * 10 * 10; + + DECLARE v7 TINYINT DEFAULT '10'; + DECLARE v8 TINYINT DEFAULT '10 '; + DECLARE v9 TINYINT DEFAULT ' 10 '; + DECLARE v10 TINYINT DEFAULT 'String 10 '; + DECLARE v11 TINYINT DEFAULT 'String10'; + DECLARE v12 TINYINT DEFAULT '10 String'; + DECLARE v13 TINYINT DEFAULT '10String'; + DECLARE v14 TINYINT DEFAULT concat('10', ' '); + DECLARE v15 TINYINT DEFAULT concat(' ', '10'); + DECLARE v16 TINYINT DEFAULT concat('Hello, ', 'world'); + + DECLARE v17 DECIMAL(64, 2) DEFAULT 12; + DECLARE v18 DECIMAL(64, 2) DEFAULT 12.123; + DECLARE v19 DECIMAL(64, 2) DEFAULT 11 + 1; + DECLARE v20 DECIMAL(64, 2) DEFAULT 12 + 0.123; + + SELECT v1, v1u, v2, v2u, v3, v3u, v4, v4u; + SELECT v5, v5u, v6, v6u; + SELECT v7, v8, v9, v10, v11, v12, v13, v14, v15, v16; + SELECT v17, v18, v19, v20; +END| + +# -------------------------------------------------------------------------- + +CREATE PROCEDURE sp_vars_check_assignment() +BEGIN + DECLARE i1, i2, i3, i4 TINYINT; + DECLARE u1, u2, u3, u4 TINYINT UNSIGNED; + DECLARE d1, d2, d3 DECIMAL(64, 2); + + SET i1 = 1e200; + SET i2 = -1e200; + SET i3 = 300; + SET i4 = -300; + + SELECT i1, i2, i3, i4; + + SET i1 = 10 * 10 * 10; + SET i2 = -10 * 10 * 10; + SET i3 = sign(10 * 10) * 10 * 20; + SET i4 = sign(-10 * 10) * -10 * 20; + + SELECT i1, i2, i3, i4; + + SET u1 = 1e200; + SET u2 = -1e200; + SET u3 = 300; + SET u4 = -300; + + SELECT u1, u2, u3, u4; + + SET u1 = 10 * 10 * 10; + SET u2 = -10 * 10 * 10; + SET u3 = sign(10 * 10) * 10 * 20; + SET u4 = sign(-10 * 10) * -10 * 20; + + SELECT u1, u2, u3, u4; + + SET d1 = 1234; + SET d2 = 1234.12; + SET d3 = 1234.1234; + + SELECT d1, d2, d3; + + SET d1 = 12 * 100 + 34; + SET d2 = 12 * 100 + 34 + 0.12; + SET d3 = 12 * 100 + 34 + 0.1234; + + SELECT d1, d2, d3; +END| + +# -------------------------------------------------------------------------- + +CREATE FUNCTION sp_vars_check_ret1() RETURNS TINYINT +BEGIN + RETURN 1e200; +END| + +# -------------------------------------------------------------------------- + +CREATE FUNCTION sp_vars_check_ret2() RETURNS TINYINT +BEGIN + RETURN 10 * 10 * 10; +END| + +# -------------------------------------------------------------------------- + +CREATE FUNCTION sp_vars_check_ret3() RETURNS TINYINT +BEGIN + RETURN 'Hello, world'; +END| + +# -------------------------------------------------------------------------- + +CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2) +BEGIN + RETURN 12 * 10 + 34 + 0.1234; +END| + +# -------------------------------------------------------------------------- + +CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER +BEGIN + DECLARE div_zero INTEGER; + SELECT 1/0 INTO div_zero; + RETURN div_zero; +END| + +# -------------------------------------------------------------------------- + +delimiter ;| diff --git a/tools/deploy/mysql_test/include/wait_until_disconnected.inc b/tools/deploy/mysql_test/include/wait_until_disconnected.inc new file mode 100644 index 000000000..8a989becc --- /dev/null +++ b/tools/deploy/mysql_test/include/wait_until_disconnected.inc @@ -0,0 +1,21 @@ +# +# Include this script to wait until the connection to the +# server has been dropped +--disable_result_log +--disable_query_log +let $counter= 500; +let $mysql_errno= 0; +while (!$mysql_errno) +{ + --error 0,1040,1053,2002,2003,2006,2013 + show status; + + dec $counter; + if (!$counter) + { + --die Server failed to dissapear + } + --sleep 0.1 +} +--enable_query_log +--enable_result_log diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_basic_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_basic_mysql.result new file mode 100644 index 000000000..e7b9eb23e --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_basic_mysql.result @@ -0,0 +1,2385 @@ +result_format: 4 +drop table if exists a,b,t,t1; +drop procedure if exists p; +drop procedure if exists f; +drop procedure if exists pp; +drop procedure if exists gather_table_stats; + +create table a(a1 int,a2 int,a3 int); +create procedure f(inout x int) +begin +set x = x+1; +end// +create procedure p(x int) +begin +declare i int; +set i=i+1; +if(1=1) +then +begin +declare j int; +select 1 from a where a1=i into x; +end; +end if; +while i>1 do +set i=i-1; +end while; +call f(x); +end// +call p(1); +drop table a; +drop procedure f; +drop procedure p; + +create table a(a1 int,a2 int,a3 int); +drop procedure pro1; +create procedure pro1() +begin +declare i bigint default 0; +set i=i+1; +if(i=1) +then +select 1 from dual; +end if; +end// +call pro1()// ++---+ +| 1 | ++---+ +| 1 | ++---+ +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ ++------+------+------+ +drop table a; + +create table a(a1 int,a2 int,a3 int); +drop procedure pro1; +create procedure pro1() +begin +declare i bigint default 0; +set i=i+1; +if(i=1) +then +insert into a values(1,1,1); +end if; +end// +call pro1()// +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ +| 1 | 1 | 1 | ++------+------+------+ +drop table a; + +create table a(a1 int,a2 int,a3 int); +create procedure p(x bigint) +begin +select x from dual; +end// +call p(1); ++---+ +| x | ++---+ +| 1 | ++---+ +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ ++------+------+------+ +drop table a; +drop procedure p; + +create table a(a1 int,a2 int,a3 int); +create procedure p(x bigint) +begin +insert into a values(x,1,1); +end// +call p(1); +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ +| 1 | 1 | 1 | ++------+------+------+ +drop table a; +drop procedure p; + +create table a(a1 int,a2 int,a3 int); +create procedure p() +begin +declare i bigint default 0; +set i=i+1; +if(i=1) +then +insert into a values(1,1,1); +end if; +end// +call p(); +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ +| 1 | 1 | 1 | ++------+------+------+ +drop table a; +drop procedure p; + +create table a(a1 int,a2 int,a3 int); +create procedure p(x bigint) +begin +declare i bigint default 0; +set i=i+1; +if(i>x) +then +insert into a values(0,0,0); +else +insert into a values(1,1,1); +end if; +end// +call p(1); +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ +| 1 | 1 | 1 | ++------+------+------+ +drop table a; +drop procedure p; + +create table a(a1 int,a2 int,a3 int); +create procedure p(x bigint) +begin +declare i bigint default 1; +if(xi) +then +insert into a values(x,x,x); +else +insert into a values(i,i,i); +end if; +end// +call p(1); +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ +| 1 | 1 | 1 | ++------+------+------+ +drop table a; +drop procedure p; + +create table a(a1 char(5),a2 char(5),a3 char(5)); +create procedure p(x char(5), y int) +begin +declare i bigint default 1; +if(y>i) +then +insert into a values(x,x,x); +else +insert into a values('i','i','i'); +end if; +end// +call p('x', 1); +select * from a; ++------+------+------+ +| a1 | a2 | a3 | ++------+------+------+ +| i | i | i | ++------+------+------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p() +begin +select *,* from a; +end// +call p; +ERROR 42000: Duplicated star +select * from a; ++------+ +| a1 | ++------+ ++------+ +drop table a; +drop procedure p; + +create table a(a1 bigint); +create procedure p(x bigint) +begin +DECLARE cur Cursor FOR select * from a; +open cur; +fetch cur into x; +close cur; +end// +call p(1); +ERROR 02000: No data - zero rows fetched, selected, or processed +select * from a; ++------+ +| a1 | ++------+ ++------+ +drop table a; +drop procedure p; + +CREATE PROCEDURE p(a bigint) +BEGIN +label1: LOOP +SET a = a + 1; +IF a < 10 THEN +LEAVE label1; +END IF; +END LOOP label1; +END// +call p(1); +drop procedure p; + +create table a(a1 bigint); +CREATE PROCEDURE p(a bigint) +BEGIN +label1: LOOP +SET a = a + 1; +IF a < 10 THEN +insert into a values(a); +else +LEAVE label1; +END IF; +END LOOP label1; +END// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 2 | +| 3 | +| 4 | +| 5 | +| 6 | +| 7 | +| 8 | +| 9 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 bigint); +CREATE PROCEDURE p(a bigint) +BEGIN +label1: LOOP +SET a = a + 1; +IF a < 10 THEN +iterate label1; +elseif a< 20 then +insert into a values(a); +else +LEAVE label1; +END IF; +END LOOP label1; +END// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 10 | +| 11 | +| 12 | +| 13 | +| 14 | +| 15 | +| 16 | +| 17 | +| 18 | +| 19 | ++------+ +drop table a; +drop procedure p; + +CREATE PROCEDURE p(a bigint, sum bigint) +BEGIN +label1: LOOP +begin +declare b bigint; +set b=a+1; +IF a+b > sum THEN +LEAVE label1; +else +set a=b; +END IF; +end; +END LOOP label1; +END// +#### TODO: 执行时间过长导致farm失败, 暂时改小循环次数 +## call p(1,1000000); +call p(1,10000); +drop procedure p; + +CREATE PROCEDURE p(a bigint) +BEGIN +label1: Repeat +begin +declare b bigint; +SET b = a + 1; +end; +UNTIL a<10 +END repeat label1; +END// +call p(1); +drop procedure p; + +CREATE PROCEDURE p(a bigint) +BEGIN +label1: Repeat +begin +declare b int; +SET b = a + 1; +end; +UNTIL a<10 +END repeat label1; +END// +call p(1); +drop procedure p; + +CREATE PROCEDURE p(a bigint) +BEGIN +label1: Repeat +begin +declare b bigint; +SET b = a + 1; +end; +UNTIL b<10 +END repeat label1; +END// +ERROR 42000: Undeclared variable: b + +set @a=1; +drop procedure pro1; +create procedure pro1() +begin +if(@a=1) +then +select @a; +end if; +end// +call pro1()// ++------+ +| @a | ++------+ +| 1 | ++------+ + +create table a(a1 int); +set @a=1; +drop procedure pro1; +create procedure pro1() +begin +if(@a=1) +then +insert into a values(1); +else +insert into a values(@a); +end if; +end// +call pro1()// +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +drop table a; + +drop procedure pro1; +create procedure pro1() +begin +set @a=1; +end// +call pro1()// + +drop procedure pro1; +create procedure pro1() +begin +set @b='b'; +end// +call pro1()// + +drop procedure pro1; +create procedure pro1() +begin +set @@session.a=1; +end// +ERROR 42000: Undeclared variable: a +call pro1()// +ERROR 42000: procedure test.pro1 does not exist + +set @@session.ob_trx_timeout=100000000; +select @@session.ob_trx_timeout; ++--------------------------+ +| @@session.ob_trx_timeout | ++--------------------------+ +| 100000000 | ++--------------------------+ +drop procedure pro1; +ERROR 42000: PROCEDURE test.pro1 does not exist +create procedure pro1() +begin +set @@session.ob_trx_timeout=100000001; +end// +call pro1()// +select @@session.ob_trx_timeout; ++--------------------------+ +| @@session.ob_trx_timeout | ++--------------------------+ +| 100000000 | ++--------------------------+ +set @@session.ob_trx_timeout=100000000; + +drop procedure pro1; +create procedure pro1() +begin +set @@global.a=1; +end// +ERROR 42000: Undeclared variable: a +call pro1()// +ERROR 42000: procedure test.pro1 does not exist + +set @@global.ob_trx_timeout=100000000; +select @@global.ob_trx_timeout; ++-------------------------+ +| @@global.ob_trx_timeout | ++-------------------------+ +| 100000000 | ++-------------------------+ +drop procedure pro1; +ERROR 42000: PROCEDURE test.pro1 does not exist +create procedure pro1() +begin +set @@global.ob_trx_timeout=100000001; +end// +call pro1()// +select @@global.ob_trx_timeout; ++-------------------------+ +| @@global.ob_trx_timeout | ++-------------------------+ +| 100000001 | ++-------------------------+ +set @@global.ob_trx_timeout=100000000; + +create table a(a1 int); +drop procedure pro1; +create procedure pro1() +begin +set @a=1+1; +if(@a=2) then +insert into a values(@a); +else +insert into a values(1); +end if; +end// +call pro1()// +select * from a; ++------+ +| a1 | ++------+ +| 2 | ++------+ +drop table a; + +create table a(a1 varchar(100)); +create procedure p(x varchar(100)) +begin +select * from a where a1=x; +end// +call p('fff'); ++------+ +| a1 | ++------+ ++------+ +drop procedure p; +drop table a; + +create table a(a1 varchar(100)); +create procedure p(x varchar(100)) +begin +declare a1 varchar(100) default 'fff'; +select * from a where a1=x; +end// +call p(); +ERROR 42000: Incorrect number of arguments +call p('a'); ++------+ +| a1 | ++------+ ++------+ +drop procedure p; +drop table a; + +create table a(a1 varchar(100)); +create procedure p(x varchar(100)) +begin +insert into a values(x); +end// +call p('fff'); +select * from a; ++------+ +| a1 | ++------+ +| fff | ++------+ +drop procedure p; +drop table a; + +create table a(a1 varchar(100)); +create procedure p(inout x varchar(10)) +begin +set x='bbb'; +end// +create procedure pp() +begin +declare x varchar(10) default 'aaa'; +call p(x); +insert into a values(x); +end// +call pp(); +select * from a; ++------+ +| a1 | ++------+ +| bbb | ++------+ +drop table a; +drop procedure p; +drop procedure pp; + +create table a(a1 varchar(100)); +create table b(b1 int); +create procedure p(inout x varchar(10)) +begin +insert into a values(x); +insert into b values(x); +end// +create procedure pp(inout x int) +begin +insert into a values(x); +insert into b values(x); +end// +set @px = 1; +call p(@px); ++------+ +| x | ++------+ +| 1 | ++------+ +set @py = 1; +call pp(@py); ++------+ +| x | ++------+ +| 1 | ++------+ +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 1 | ++------+ +select * from b; ++------+ +| b1 | ++------+ +| 1 | +| 1 | ++------+ +drop table a; +drop table b; +drop procedure p; + +create table a(a1 varchar(100)); +create procedure p(x varchar(4)) +begin +insert into a values(x); +end// +call p('gggggggg'); +ERROR 22001: Data too long for column +call p('gggg'); +select * from a; ++------+ +| a1 | ++------+ +| gggg | ++------+ +drop table a; +drop procedure p; +drop procedure pp; + +create table a(a1 varchar(100)); +insert into a values('a'); +create table b(b1 varchar(100)); +drop procedure pro1; +create procedure pro1() +BEGIN +DECLARE x varchar(100); +DECLARE c CURSOR FOR SELECT a1 FROM a; +OPEN c; +fetch c into x; +CLOSE c; +insert into b values(x); +END// +call pro1()// +select * from b; ++------+ +| b1 | ++------+ +| a | ++------+ +drop table a; +drop table b; + +create table a(a1 varchar(10)); +create procedure p(x varchar(100)) +begin +case x +when 1 then insert into a values('1'); +else insert into a values('0'); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 1 | ++------+ +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 0 | +| 1 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 varchar(10)); +create procedure p(x varchar(100)) +begin +case x +when 1 then insert into a values('1'); +when 2 then insert into a values('2'); +else insert into a values('0'); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 1 | +| 2 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +else insert into a values(0); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 1 | +| 2 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +else insert into a values(0); +if x > 1 then insert into a values(100); +else insert into a values(-100); +end if; +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 1 | +| 2 | +| 100 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +else insert into a values(0); +end case; +if x > 1 then insert into a values(100); +else insert into a values(-100); +end if; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| -100 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | +| 100 | +| -100 | ++------+ +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 1 | +| 2 | +| 100 | +| 100 | +| -100 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case +when x=1 then insert into a values(1); +when x=2 then insert into a values(2); +else insert into a values(0); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| 0 | +| 1 | +| 2 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case +when x=1 then insert into a values(1); +when x=2 then insert into a values(2); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +call p(3); +ERROR 20000: Case not found for CASE statement +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(2); +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +call p(3); +ERROR 20000: Case not found for CASE statement +select * from a; ++------+ +| a1 | ++------+ +| 1 | +| 2 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +declare exit handler for 1339 +insert into a values(-1); +case x +when 1 then insert into a values(1); +end case; +end// +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| -1 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +end case; +end// +call p(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +call p(3); +ERROR 20000: Case not found for CASE statement +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +drop table a; +drop procedure p; + +create table b(b1 char(6)); +create procedure p() +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +call p(); +select * from b; ++------+ +| b1 | ++------+ +| a1 | ++------+ +drop table b; +drop procedure p; + +set @@sql_mode=PAD_CHAR_TO_FULL_LENGTH; +create table b(b1 char(6)); +create procedure p() +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +call p(); +select * from b; ++--------+ +| b1 | ++--------+ +| a 1 | ++--------+ +drop table b; +drop procedure p; +set @@sql_mode=default; + +set @@sql_mode=PAD_CHAR_TO_FULL_LENGTH; +create table b(b1 char(6)); +create procedure p() +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +set @@sql_mode=default; +call p(); +select * from b; ++--------+ +| b1 | ++--------+ +| a 1 | ++--------+ +drop table b; +drop procedure p; + +create table a(a1 char(6)); +create procedure p(a int) +begin +insert into a values(a); +end// +select route_sql from oceanbase.__all_routine where routine_name = 'p' and database_id = (select database_id from oceanbase.__all_database where database_name = database()); ++--------------------------+ +| route_sql | ++--------------------------+ +| insert into a values(:0) | ++--------------------------+ +drop procedure p; +drop table a; + +create table b(b1 char(6)); +create procedure p(a int) +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +select route_sql from oceanbase.__all_routine where routine_name = 'p' and database_id = (select database_id from oceanbase.__all_database where database_name = database()); ++--------------------------+ +| route_sql | ++--------------------------+ +| insert into b values(:2) | ++--------------------------+ +drop procedure p; +drop table b; + +set @@sql_mode=PAD_CHAR_TO_FULL_LENGTH; +create table b(b1 char(6)); +create table a(a1 char(5)); +insert into a values('a'); +create procedure p() +begin +declare x char(5); +declare y char(6); +select a1 from a into x; +set y = concat(x, 1); +insert into b values(y); +end// +call p(); +select * from b; ++--------+ +| b1 | ++--------+ +| a 1 | ++--------+ +drop table a; +drop table b; +drop procedure p; +set @@sql_mode=default; + +create table b(b1 char(6)); +create table a(a1 char(5)); +insert into a values('a'); +create procedure p() +begin +declare x char(5); +select a1 from a into x; +insert into b values(x); +end// +call p(); +select * from b; ++------+ +| b1 | ++------+ +| a | ++------+ +drop table b; +drop table a; +drop procedure p; + +set @xxx = 'asd'; +create table b(b1 char(6)); +create table a(a1 char(5)); +insert into a values('a'); +insert into b values(@xxx); +create procedure p() +begin +select a1 from a into @xxx; +insert into b values(@xxx); +end// +call p(); +select * from b; ++------+ +| b1 | ++------+ +| a | +| asd | ++------+ +drop table b; +drop table a; +drop procedure p; + +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +create procedure p() +begin +select a1 from a into @xxx; +insert into b values(@xxx,@xxx); +end// +call p(); +select * from b; ++------+------+ +| b1 | b2 | ++------+------+ +| a | a | +| asd | asd | ++------+------+ +drop table b; +drop table a; +drop procedure p; + +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +create procedure p() +begin +declare x char(6); +select a1,a2 from a into @xxx, x; +insert into b values(@xxx, x); +end// +call p(); +select * from b; ++------+------+ +| b1 | b2 | ++------+------+ +| a | a | +| asd | asd | ++------+------+ +drop table b; +drop table a; +drop procedure p; + +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +create procedure p() +begin +declare x char(6); +select a1,a2 from a into x, x; +insert into b values(@xxx, x); +end// +call p(); +select * from b; ++------+------+ +| b1 | b2 | ++------+------+ +| asd | a | +| asd | asd | ++------+------+ +drop table b; +drop table a; +drop procedure p; + +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +create procedure p() +begin +declare x char(6); +declare y char(6); +select a1,a2 from a into @xxx, x; +set y = @xxx; +insert into b values(y, x); +end// +call p(); +select * from b; ++------+------+ +| b1 | b2 | ++------+------+ +| a | a | +| asd | asd | ++------+------+ +drop table b; +drop table a; +drop procedure p; + +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +insert into b values(@xxx, 'asd'); +create procedure p() +begin +declare x char(6); +set x='a'; +insert into b values(@xxx, x); +end// +call p(); +select * from b; ++------+------+ +| b1 | b2 | ++------+------+ +| asd | a | +| asd | asd | ++------+------+ +drop table b; +drop procedure p; + +create table a(a1 int, a2 varchar(10)); +drop procedure pro1; +create procedure pro1() +begin +declare x varchar(10) default 'x'; +declare y varchar(10) default 'y'; +declare xx int default 1; +declare yy int default 2; +set y = x; +set yy = xx; +set x = 'a'; +set xx = 9; +insert into a values(yy, y); +end// +call pro1()// +select * from a; ++------+------+ +| a1 | a2 | ++------+------+ +| 1 | x | ++------+------+ +drop table a; + +create procedure p() +begin +declare if int default 0; +end// +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'if' at line 3 + +create procedure p() +begin +declare if1 int default 0; +end// +drop procedure p; + +create procedure p() +begin +declare count int default 0; +end// +drop procedure p; + +create procedure p() +begin +declare count1 int default 0; +end// +drop procedure p; + +set autocommit=0; +create table a(a1 int); +drop procedure pro1; +create procedure pro1() +BEGIN +insert into a values(1); +commit; +END// +call pro1()// +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +drop procedure pro1; +create procedure pro1() +BEGIN +insert into a values(2); +rollback; +END// +call pro1()// +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +set autocommit=1; +drop table a; + +create table fib(id int, value bigint); +create procedure p(x int, out y bigint) +begin +if x = 0 then set y = 0; +elseif x = 1 then set y = 1; +else +begin +declare a, b bigint default 0; +call p(x-1, a); +call p(x-2, b); +set y = a+b; +end; +end if; +end// +create procedure pp(x int) +begin +declare i int default 0; +declare result bigint default 0; +while i < x do +call p(i, result); +insert into fib values(i, result); +set i = i + 1; +end while; +end// +set @@max_sp_recursion_depth = 10; +call pp(10); +set @@max_sp_recursion_depth = 0; +select * from fib; ++------+-------+ +| id | value | ++------+-------+ +| 0 | 0 | +| 1 | 1 | +| 2 | 1 | +| 3 | 2 | +| 4 | 3 | +| 5 | 5 | +| 6 | 8 | +| 7 | 13 | +| 8 | 21 | +| 9 | 34 | ++------+-------+ +drop table fib; +drop procedure p; +drop procedure pp; + +create procedure p() +begin +call p(); +end// +call p(); +ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine +drop procedure p; + +create table a(a1 bigint, a2 timestamp); +create procedure p() +begin +declare x bigint default 1; +update a set a2=CURRENT_TIMESTAMP where a1=x; +end // +call p(); +drop table a; +drop procedure p; + +create table a(a1 bigint, a2 timestamp); +create procedure p() +begin +declare x bigint default 1; +declare y timestamp; +set y = CURRENT_TIMESTAMP; +update a set a2=y where a1=x; +end // +call p(); +drop table a; +drop procedure p; + +create table a(a1 timestamp); +create table b(b1 timestamp); +insert into a values('2018-01-02 10:10:32.000000'); +create procedure p() +begin +declare x timestamp; +select a1 from a into x; +insert into b values(x); +end // +call p; +select * from a; ++---------------------+ +| a1 | ++---------------------+ +| 2018-01-02 10:10:32 | ++---------------------+ +select * from b; ++---------------------+ +| b1 | ++---------------------+ +| 2018-01-02 10:10:32 | ++---------------------+ +drop table a; +drop table b; +drop procedure p; + +create table a(a1 decimal(12,2),a2 timestamp); +create table b(b1 decimal(12,2),b2 timestamp); +insert into a values(1.1,'2018-01-02 10:10:32.000000'); +create procedure p() +begin +declare x decimal(12,2); +declare y timestamp; +select a1,a2 from a into x,y; +insert into b values(x,y); +end // +call p; +select * from a; ++------+---------------------+ +| a1 | a2 | ++------+---------------------+ +| 1.10 | 2018-01-02 10:10:32 | ++------+---------------------+ +select * from b; ++------+---------------------+ +| b1 | b2 | ++------+---------------------+ +| 1.10 | 2018-01-02 10:10:32 | ++------+---------------------+ +drop table a; +drop table b; +drop procedure p; + +create table a(a1 decimal(12,2),a2 timestamp); +create table b(b1 decimal(12,2),b2 timestamp); +insert into a values(1.1,'2018-01-02 10:10:32.000000'); +create procedure p() +begin +declare x decimal(12,2); +declare y timestamp; +declare c1 cursor for select a1,a2 from a; +open c1; +fetch c1 into x,y; +close c1; +insert into b values(x,y); +end // +call p; +select * from a; ++------+---------------------+ +| a1 | a2 | ++------+---------------------+ +| 1.10 | 2018-01-02 10:10:32 | ++------+---------------------+ +select * from b; ++------+---------------------+ +| b1 | b2 | ++------+---------------------+ +| 1.10 | 2018-01-02 10:10:32 | ++------+---------------------+ +drop table a; +drop table b; +drop procedure p; + +create table if not exists bmsql_customer ( + c_w_id INTEGER NOT NULL, + c_d_id INTEGER NOT NULL, + c_id INTEGER NOT NULL, + c_data VARCHAR(500), + PRIMARY KEY (c_w_id, c_d_id, c_id) +); +insert into bmsql_customer values(1,1,1,'a'); +create procedure p(IN in_w_id int, + IN in_d_id int, + IN in_c_id int, + IN in_c_d_id int, + IN in_c_w_id int, + IN in_h_amount DECIMAL(6,2) + ) +begin + UPDATE bmsql_customer + SET c_data = SUBSTR(CONCAT('C_ID=', CAST(in_c_id AS CHAR), + ' C_D_ID=', CAST(in_c_d_id AS CHAR), + ' C_W_ID=', CAST(in_c_w_id AS CHAR), + ' D_ID=', CAST(in_d_id AS CHAR), + ' W_ID=', CAST(in_w_id AS CHAR), + ' H_AMOUNT=', ROUND(in_h_amount,2)), 1, 500) + WHERE c_w_id = in_c_w_id AND c_d_id = in_c_d_id AND c_id = in_c_id; +end// +call p(1,1,1,1,1,1.1); +drop table bmsql_customer; +drop procedure p; + +create table a(a1 varchar(20)); +create procedure p(x int) +begin +update a set a1=cast(x as char) where a1=1; +end// +call p(1); +drop table a; +drop procedure p; + +drop procedure pro1; +create procedure pro1() +begin +declare x int default 0; +set x=rand(); +end// +call pro1()// +drop procedure pro1; + +create table a(a1 int); +create procedure p( +arg1 int, +arg2 int, +arg3 int, +arg4 int, +arg5 int, +arg6 int, +arg7 int, +arg8 int, +arg9 int, +arg10 int +) +begin +declare x int default 1; +set x = arg10; +insert into a values(x); +end // +call p(1,2,3,4,5,6,7,8,9,10); +select * from a; ++------+ +| a1 | ++------+ +| 10 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p1( +INOUT arg1 int, +INOUT arg2 int, +INOUT arg3 int, +INOUT arg4 int, +INOUT arg5 int, +INOUT arg6 int, +INOUT arg7 int, +INOUT arg8 int, +INOUT arg9 int, +INOUT arg10 int) +begin +set arg10 = 99; +end // +create procedure p() +begin +declare arg1 int default 1; +declare arg2 int default 2; +declare arg3 int default 3; +declare arg4 int default 4; +declare arg5 int default 5; +declare arg6 int default 6; +declare arg7 int default 7; +declare arg8 int default 8; +declare arg9 int default 9; +declare arg10 int default 10; +call p1(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10); +insert into a values(arg10); +end // +call p(); +select * from a; ++------+ +| a1 | ++------+ +| 99 | ++------+ +drop table a; +drop procedure p1; +drop procedure p; + +create table a(a1 int); +create procedure p1( +INOUT arg1 int, +INOUT arg2 int, +INOUT arg3 int, +INOUT arg4 int, +INOUT arg5 int, +INOUT arg6 int, +INOUT arg7 int, +INOUT arg8 int, +INOUT arg9 int, +INOUT arg10 int, +INOUT arg11 int, +INOUT arg12 int, +INOUT arg13 int, +INOUT arg14 int, +INOUT arg15 int, +INOUT arg16 int, +INOUT arg17 int, +INOUT arg18 int, +INOUT arg19 int, +INOUT arg20 int) +begin +set arg20 = 99; +end // +create procedure p() +begin +declare arg1 int default 1; +declare arg2 int default 2; +declare arg3 int default 3; +declare arg4 int default 4; +declare arg5 int default 5; +declare arg6 int default 6; +declare arg7 int default 7; +declare arg8 int default 8; +declare arg9 int default 9; +declare arg10 int default 10; +declare arg11 int default 11; +declare arg12 int default 12; +declare arg13 int default 13; +declare arg14 int default 14; +declare arg15 int default 15; +declare arg16 int default 16; +declare arg17 int default 17; +declare arg18 int default 18; +declare arg19 int default 19; +declare arg20 int default 20; +call p1(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20); +insert into a values(arg20); +end // +call p(); +select * from a; ++------+ +| a1 | ++------+ +| 99 | ++------+ +drop table a; +drop procedure p1; +drop procedure p; + +create table a(a1 timestamp); +create procedure p() +begin +declare x int default 1; +while x <=10 do +insert into a values(CURRENT_TIMESTAMP); +set x = x+1; +end while; +end // +call p; +select count(*) from a; ++----------+ +| count(*) | ++----------+ +| 10 | ++----------+ +drop table a; +drop procedure p; + +create table a(a1 timestamp); +create procedure p() +begin +declare x int default 1; +declare y timestamp; +while x <=10 do +set y = CURRENT_TIMESTAMP; +insert into a values(y); +set x = x+1; +end while; +end // +call p; +select count(*) from a; ++----------+ +| count(*) | ++----------+ +| 10 | ++----------+ +drop table a; +drop procedure p; + +create table a(a1 decimal(6,2)); +insert into a values(1.11); +create table b(b1 decimal(6,2)); +create procedure p() +begin +declare x decimal(6,2); +declare c cursor for select a1 from a; +open c; +fetch c into x; +close c; +insert into b values(x); +end // +call p; +select * from a; ++------+ +| a1 | ++------+ +| 1.11 | ++------+ +select * from b; ++------+ +| b1 | ++------+ +| 1.11 | ++------+ +drop table a; +drop table b; +drop procedure p; + +create table a(a1 decimal(6,2)); +insert into a values(1.11); +create table b(b1 int); +create procedure p() +begin +declare x int; +declare c cursor for select a1 from a; +open c; +fetch c into x; +close c; +insert into b values(x); +end // +call p; +select * from a; ++------+ +| a1 | ++------+ +| 1.11 | ++------+ +select * from b; ++------+ +| b1 | ++------+ +| 1 | ++------+ +drop table a; +drop table b; +drop procedure p; + +create table a(a1 decimal(6,2)); +create procedure p(x int) +begin +insert into a values(x); +select * from a where a1=x; +end // +select route_sql from oceanbase.__all_routine where routine_name = 'p' and database_id = (select database_id from oceanbase.__all_database where database_name = database()); ++--------------------------+ +| route_sql | ++--------------------------+ +| insert into a values(:0) | ++--------------------------+ +drop table a; +drop procedure p; + +create procedure p() +begin +insert into table_not_exist values(1); +end // +call p(); +ERROR 42S02: Table 'test.table_not_exist' doesn't exist +drop procedure p; + +create procedure p() +label1: +begin +end label1// +call p(); +drop procedure p; + +create procedure p() +begin +end// +call p(); +drop procedure p; + +create procedure p() +begin +declare i int default 3; +label1: begin +if i > 0 then +set i = i-1; +else leave label1; +end if; +end; +end// +call p(); +drop procedure p; + +create procedure p() +return 42;// +ERROR 42000: RETURN is only allowed in a FUNCTION + +set @a=0; +select @a; ++------+ +| @a | ++------+ +| 0 | ++------+ +create procedure p(out x int) +begin +set x=1; +end// +call p(@a); ++------+ +| x | ++------+ +| 1 | ++------+ +select @a; ++------+ +| @a | ++------+ +| 1 | ++------+ +drop procedure p; + +create procedure gather_table_stats(tenant_name varchar(128), db_name varchar(128), table_name varchar(128)) +begin +end// +drop procedure gather_table_stats; + +create procedure gather_table_stats(tenant_name int, db_name int, table_name int) +begin +end// +drop procedure gather_table_stats; + +create procedure gather_table_stats(tenant_name int, db_name int, t_name int) +begin +end// +call gather_table_stats(1,1,1); +drop procedure gather_table_stats; + +drop function f; +create function f(x int) returns int +begin + if x>1 then + return x; + else + signal SQLSTATE '01000'; + end if; +end// +select f(2); ++------+ +| f(2) | ++------+ +| 2 | ++------+ +select f(1); +ERROR 2F005: FUNCTION ended without RETURN +drop function f; + +create function f(x int) returns int +begin + if x>1 then + return x; + else + signal SQLSTATE '02000'; + end if; +end// +select f(2); ++------+ +| f(2) | ++------+ +| 2 | ++------+ +select f(1); +ERROR 02000: Unhandled user-defined not found condition +drop function f; + +create function f(x int) returns int +begin + if x>1 then + return NULL; + else + signal SQLSTATE '02000'; + end if; +end// +select f(2); ++------+ +| f(2) | ++------+ +| NULL | ++------+ +select f(1); +ERROR 02000: Unhandled user-defined not found condition +drop function f; + +### need has return in mysql function +### https://work.aone.alibaba-inc.com/issue/34977232 +DROP FUNCTION IF EXISTS `fun6`// + +CREATE FUNCTION fun6 ( p1 INT) RETURNS VARCHAR(20) +BEGIN + SET p1 = p1 + 3; + SET p1 = p1 * 2; + SET @num = p1 * p1; +END// +ERROR 42000: No Return found in FUNCTION 'fun6' + +SELECT fun6(5)// +ERROR 42000: FUNCTION fun6 does not exist +SELECT @num// ++------+ +| @num | ++------+ +| NULL | ++------+ + +CREATE FUNCTION fun6 ( p1 INT) RETURNS VARCHAR(20) +BEGIN + SET @num = p1 * p1; +END// +ERROR 42000: No Return found in FUNCTION 'fun6' + +SELECT fun6(5)// +ERROR 42000: FUNCTION fun6 does not exist +SELECT @num// ++------+ +| @num | ++------+ +| NULL | ++------+ + +DROP FUNCTION IF EXISTS `fun6`// + +### label dup +### https://work.aone.alibaba-inc.com/issue/34954831 +DROP TABLE IF EXISTS result1// +CREATE TABLE result1( +id INT, +res1 VARCHAR(50), +res2 VARCHAR(50) +)// +DROP PROCEDURE IF EXISTS `pro_1`// + +CREATE PROCEDURE pro_1() +BEGIN + label1:BEGIN + INSERT INTO result1 VALUES(1,'结果表:','标签label1'); + label2:BEGIN + INSERT INTO result1 VALUES(2,'结果表:','标签label2'); + END label2; + END label1; +END// + +CALL pro_1()// + +CREATE PROCEDURE pro_2() +BEGIN + label1:BEGIN + INSERT INTO result1 VALUES(3,'结果表:','标签label1'); + END label1; + label1:BEGIN + INSERT INTO result1 VALUES(4,'结果表:','标签label1'); + END label1; +END// + +CALL pro_2()// + +CREATE PROCEDURE pro_3() +BEGIN + label1:BEGIN + INSERT INTO result1 VALUES(5,'结果表:','标签label1'); + label1:BEGIN + INSERT INTO result1 VALUES(6,'结果表:','标签label1'); + END label1; + END label1; +END// +ERROR 42000: Redefining label '%.*s' + +CALL pro_3()// +ERROR 42000: procedure test.pro_3 does not exist + +SELECT * FROM result1// ++------+--------------+--------------+ +| id | res1 | res2 | ++------+--------------+--------------+ +| 1 | 结果表: | 标签label1 | +| 2 | 结果表: | 标签label2 | +| 3 | 结果表: | 标签label1 | +| 4 | 结果表: | 标签label1 | ++------+--------------+--------------+ +DROP TABLE IF EXISTS result1// +DROP PROCEDURE IF EXISTS `pro_1`// +DROP PROCEDURE IF EXISTS `pro_2`// +DROP PROCEDURE IF EXISTS `pro_3`// + +### ### varchar +### ### https://work.aone.alibaba-inc.com/issue/35400448 +### DROP TABLE IF EXISTS t2// +### --error 1074 +### CREATE TABLE t2 ( +### id INT, +### res1 VARCHAR(128), +### d1 VARCHAR(16384) +### )// +### DROP TABLE IF EXISTS t3// +### --error 1074 +### CREATE TABLE t3 ( +### id INT, +### res1 VARCHAR(128), +### d1 VARCHAR(262145) +### )// +### DROP FUNCTION IF EXISTS fun_l// +### --error 1074 +### CREATE FUNCTION fun_l() RETURNS VARCHAR(262144) +### BEGIN +### DECLARE d1 VARCHAR(262144123456); +### SET d1='123456789012345678901234567890'; +### RETURN '定义长度262144123456的VARCHAR(262144123456)类型的变量'; +### END// +### --error 1305 +### SELECT fun_l()// +### char +### https://work.aone.alibaba-inc.com/issue/35399998 +DROP TABLE IF EXISTS t1// +DROP TABLE IF EXISTS t2// +CREATE TABLE t1 ( + id INT, + res1 VARCHAR(128), + d1 CHAR(255) + )// +### --error 1074 +### TODO: https://work.aone.alibaba-inc.com/issue/35400448 +### CREATE TABLE t2 ( +### id INT, +### res1 VARCHAR(128), +### d1 CHAR(256) +### )// +DROP TABLE IF EXISTS t3// +CREATE TABLE t3 ( + id INT, + res1 VARCHAR(128), + d1 CHAR(257) + )// +ERROR 42000: Column length too big for column 'd1' (max = 256) +DROP PROCEDURE IF EXISTS `pro_1`// +CREATE PROCEDURE pro_1() + BEGIN + DECLARE d1 CHAR(257); + SET d1='CHAR[(M)] M表示以字符为单位的列长度, M范围是 0~255'; + INSERT INTO t1 VALUES(1,'变量形式插入CHAR(257)类型数据',d1); + END// +ERROR 42000: Column length too big for column '(null)' (max = 256) +CALL pro_1()// +ERROR 42000: procedure test.pro_1 does not exist +SELECT * FROM t1// ++------+------+------+ +| id | res1 | d1 | ++------+------+------+ ++------+------+------+ + +### varbinary +### https://work.aone.alibaba-inc.com/issue/35614023 +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 ( + d1 VARBINARY(65536) +)// +DROP TABLE IF EXISTS t2// +CREATE TABLE t2 ( + d1 VARBINARY(1048577) +)// +ERROR 42000: Column length too big for column 'd1' (max = 1048576) + +DROP FUNCTION IF EXISTS `fun_l`// +CREATE FUNCTION fun_l() RETURNS VARBINARY(65535) +BEGIN + DECLARE d1 VARBINARY(65536); + SET d1='123456789012345678901234567890'; + RETURN '定义长度65536的VARCHAR类型的变量'; +END// +ERROR 42000: Column length too big for column '(null)' (max = 65535) + +SELECT fun_l()// +ERROR 42000: FUNCTION fun_l does not exist + +### number +### https://work.aone.alibaba-inc.com/issue/35302277 +DROP FUNCTION IF EXISTS `fun_l`// +CREATE FUNCTION fun_l() RETURNS DEC(65,30) +BEGIN + DECLARE a DEC(66,30); + SET a=123450.1415; + RETURN a; +END// +ERROR 42000: Too big precision 66 specified for column '(null)'. Maximum is 65. +SELECT fun_l()// +ERROR 42000: FUNCTION fun_l does not exist +DROP FUNCTION IF EXISTS `fun_2`// +CREATE FUNCTION fun_2() RETURNS DEC(65,30) +BEGIN + DECLARE a DEC(65,31); + SET a=50.1; + RETURN a; +END// +ERROR 42000: Too big scale 31 specified for column '(null)'. Maximum is 30. +SELECT fun_2()// +ERROR 42000: FUNCTION fun_2 does not exist + +### datetime +### https://work.aone.alibaba-inc.com/issue/35346065 +DROP TABLE IF EXISTS t2// +CREATE TABLE t2 ( + id INT, + res1 VARCHAR(128), + d1 DATETIME(7) +)// +ERROR 42000: Too big precision 7 specified for column 'd1'. Maximum is 6. +DROP FUNCTION IF EXISTS `fun_l`// +CREATE FUNCTION fun_l() RETURNS DATETIME(6) +BEGIN + DECLARE d2 DATETIME(7) DEFAULT '2021-07-02 23:59:59.999999'; + RETURN d2; +END// +ERROR 42000: Too big precision 7 specified for column '(null)'. Maximum is 6. +SELECT fun_l()// +ERROR 42000: FUNCTION fun_l does not exist + +### datetime max value insert fail +### https://work.aone.alibaba-inc.com/issue/35345945 +DROP TABLE IF EXISTS t2// +CREATE TABLE t2 ( + id INT, + res1 VARCHAR(128), + d1 DATETIME, + d2 DATETIME(0), + d3 DATETIME(6) +)// +INSERT INTO t2 VALUES(1,'插入DATETIME类型数据','1000-01-01 00:00:00.123','2000-01-01 00:00:00.123','9999-12-31 23:59:59.999999')// +DROP PROCEDURE IF EXISTS `pro_1`// +CREATE PROCEDURE pro_1() +BEGIN + DECLARE d1 DATETIME DEFAULT '1000-01-01 00:00:00.000000'; + DECLARE d2 DATETIME(0) DEFAULT '2021-07-02 23:59:59.999999'; + DECLARE d3 DATETIME(6) DEFAULT '9999-12-31 23:59:59.999999'; + INSERT INTO t2 VALUES(2,'变量形式插入DATETIME类型数据',d1,d2,d3); + INSERT INTO t2 VALUES(3,'直接插入DATETIME类型数据','3000-01-01 00:00:00.123','4000-01-01 00:00:00.123','9999-12-31 23:59:59.999999'); +END// +CALL pro_1()// +SELECT * FROM t2// ++------+----------------------------------------+---------------------+---------------------+----------------------------+ +| id | res1 | d1 | d2 | d3 | ++------+----------------------------------------+---------------------+---------------------+----------------------------+ +| 1 | 插入DATETIME类型数据 | 1000-01-01 00:00:00 | 2000-01-01 00:00:00 | 9999-12-31 23:59:59.999999 | +| 2 | 变量形式插入DATETIME类型数据 | 1000-01-01 00:00:00 | 2021-07-03 00:00:00 | 9999-12-31 23:59:59.999999 | +| 3 | 直接插入DATETIME类型数据 | 3000-01-01 00:00:00 | 4000-01-01 00:00:00 | 9999-12-31 23:59:59.999999 | ++------+----------------------------------------+---------------------+---------------------+----------------------------+ + +### int +### https://work.aone.alibaba-inc.com/issue/35302003 +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 ( + id INT, + res1 VARCHAR(128), + a INT(255) +)// +DROP PROCEDURE IF EXISTS `pro_1`// +CREATE PROCEDURE pro_1() +BEGIN + DECLARE a INT(256); + SET a=4294967295; + INSERT INTO t1 VALUES(1,'插入INT类型数据',a); +END// +ERROR 42000: Display width out of range for column '(null)' (max = 255) +CALL pro_1()// +ERROR 42000: procedure test.pro_1 does not exist +SELECT * FROM t1// ++------+------+------+ +| id | res1 | a | ++------+------+------+ ++------+------+------+ + +### commit +### rollback +### https://work.aone.alibaba-inc.com/issue/34756672 +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 +( a INT +)// +DROP TABLE IF EXISTS t2// +CREATE TABLE t2 +( a INT +)// + +INSERT INTO t1 VALUES (1),(2),(3)// + +DROP PROCEDURE IF EXISTS `pro`// +CREATE PROCEDURE pro() +BEGIN + INSERT INTO t1 VALUES (4); + COMMIT; +END// + +call pro()// + +select * from t1// ++------+ +| a | ++------+ +| 1 | +| 2 | +| 3 | +| 4 | ++------+ + +DROP PROCEDURE IF EXISTS `pro`// +CREATE PROCEDURE pro() +BEGIN + INSERT INTO t1 VALUES (4); + ROLLBACK; +END// + +call pro()// + +select * from t1// ++------+ +| a | ++------+ +| 1 | +| 2 | +| 3 | +| 4 | +| 4 | ++------+ + +DROP FUNCTION IF EXISTS `fun1`// +####mysql: ERROR 1422 (HY000): Explicit or implicit commit is not allowed in stored function or trigger. +CREATE FUNCTION fun1() RETURNS VARCHAR(128) +BEGIN + INSERT INTO t1 VALUES (4); + COMMIT; + return '显示提交'; +END// +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. + +DROP FUNCTION IF EXISTS `fun2`// +CREATE FUNCTION fun2() RETURNS VARCHAR(128) +BEGIN + INSERT INTO t1 VALUES (4); + return '隐式提交'; +END// + +select fun2()// ++--------------+ +| fun2() | ++--------------+ +| 隐式提交 | ++--------------+ + +select * from t1// ++------+ +| a | ++------+ +| 1 | +| 2 | +| 3 | +| 4 | +| 4 | +| 4 | ++------+ + +DROP FUNCTION IF EXISTS `fun3`// +CREATE FUNCTION fun3() RETURNS VARCHAR(128) +BEGIN + INSERT INTO t1 VALUES (4); + ROLLBACK; + return '回滚'; +END// +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. + +### BIT +### https://work.aone.alibaba-inc.com/issue/35280082 +DROP TABLE IF EXISTS t1;// +DROP PROCEDURE IF EXISTS `pro_2`;// +CREATE PROCEDURE pro_2() +BEGIN + CREATE TABLE t1 (id INT,a BIT(65)); + INSERT INTO t1 VALUES(1,b'0'); +END; +// +ERROR 42000: Display width out of range for column 'CREATE TABLE t1 (id INT,a BIT(65))' (max = 64) + +### load data +### https://work.aone.alibaba-inc.com/issue/34756578 +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 (a INT)// +INSERT INTO t1 VALUES (1),(2),(3)// +DROP PROCEDURE IF EXISTS `pro_22`// + +CREATE PROCEDURE pro_22() +BEGIN + LOAD DATA INFILE 'data.txt' INTO TABLE t1; +END// +ERROR HY000: 'LOAD DATA' is not allowed in stored procedure. + +### lock +### https://work.aone.alibaba-inc.com/issue/34756555 +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 (a INT)// +INSERT INTO t1 VALUES (1),(2),(3)// +DROP PROCEDURE IF EXISTS `pro_1`// +CREATE PROCEDURE pro_1() +BEGIN + LOCK TABLES t1 READ; +END// +ERROR HY000: 'LOCK TABLE' is not allowed in stored procedure. + +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP PROCEDURE IF EXISTS `pro_1`; +DROP FUNCTION IF EXISTS `fun_l`; +DROP PROCEDURE IF EXISTS `pro_22`; diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_dbt2_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_dbt2_mysql.result new file mode 100644 index 000000000..4e692f4e8 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_dbt2_mysql.result @@ -0,0 +1,1459 @@ +result_format: 4 +use test; + +set ob_query_timeout=100000000; + +DROP TABLE IF EXISTS customer; +DROP TABLE IF EXISTS district; +DROP TABLE IF EXISTS history; +DROP TABLE IF EXISTS item; +DROP TABLE IF EXISTS new_order; +DROP TABLE IF EXISTS order_line; +DROP TABLE IF EXISTS orders; +DROP TABLE IF EXISTS stock; +DROP TABLE IF EXISTS warehouse; +DROP PROCEDURE IF EXISTS delivery; +DROP PROCEDURE IF EXISTS new_order_2; +DROP PROCEDURE IF EXISTS new_order; +DROP PROCEDURE IF EXISTS order_status; +DROP PROCEDURE IF EXISTS payment; +DROP PROCEDURE IF EXISTS stock_level; +CREATE TABLE customer ( + c_id int(11) NOT NULL default '0', + c_d_id int(11) NOT NULL default '0', + c_w_id int(11) NOT NULL default '0', + c_first varchar(16) default NULL, + c_middle char(2) default NULL, + c_last varchar(16) default NULL, + c_street_1 varchar(20) default NULL, + c_street_2 varchar(20) default NULL, + c_city varchar(20) default NULL, + c_state char(2) default NULL, + c_zip varchar(9) default NULL, + c_phone varchar(16) default NULL, + c_since timestamp NOT NULL, + c_credit char(2) default NULL, + c_credit_lim decimal(24,12) default NULL, + c_discount double default NULL, + c_balance decimal(24,12) default NULL, + c_ytd_payment decimal(24,12) default NULL, + c_payment_cnt double default NULL, + c_delivery_cnt double default NULL, + c_data varchar(500), + PRIMARY KEY (c_w_id,c_d_id,c_id), + KEY c_w_id (c_w_id,c_d_id,c_last,c_first) +); + +CREATE TABLE district ( + d_id int(11) NOT NULL default '0', + d_w_id int(11) NOT NULL default '0', + d_name varchar(10) default NULL, + d_street_1 varchar(20) default NULL, + d_street_2 varchar(20) default NULL, + d_city varchar(20) default NULL, + d_state char(2) default NULL, + d_zip varchar(9) default NULL, + d_tax double default NULL, + d_ytd decimal(24,12) default NULL, + d_next_o_id int(11) default NULL, + PRIMARY KEY (d_w_id,d_id) +); + +CREATE TABLE history ( + h_id bigint(20) auto_increment, + h_c_id int(11) default NULL, + h_c_d_id int(11) default NULL, + h_c_w_id int(11) default NULL, + h_d_id int(11) default NULL, + h_w_id int(11) NOT NULL default '0', + h_date timestamp NOT NULL, + h_amount double default NULL, + h_data varchar(24) default NULL, + PRIMARY KEY (h_id, h_w_id) +); + +CREATE TABLE item ( + i_id int(11) NOT NULL default '0', + i_im_id int(11) default NULL, + i_name varchar(24) default NULL, + i_price double default NULL, + i_data varchar(50) default NULL, + PRIMARY KEY (i_id) +); + +CREATE TABLE new_order ( + no_o_id int(11) NOT NULL default '0', + no_d_id int(11) NOT NULL default '0', + no_w_id int(11) NOT NULL default '0', + PRIMARY KEY (no_w_id,no_d_id,no_o_id) +); + +CREATE TABLE order_line ( + ol_o_id int(11) NOT NULL default '0', + ol_d_id int(11) NOT NULL default '0', + ol_w_id int(11) NOT NULL default '0', + ol_number int(11) NOT NULL default '0', + ol_i_id int(11) default NULL, + ol_supply_w_id int(11) default NULL, + ol_delivery_d timestamp NOT NULL, + ol_quantity double default NULL, + ol_amount double default NULL, + ol_dist_info varchar(24) default NULL, + PRIMARY KEY (ol_w_id,ol_d_id,ol_o_id,ol_number) +); + +CREATE TABLE orders ( + o_id int(11) NOT NULL default '0', + o_d_id int(11) NOT NULL default '0', + o_w_id int(11) NOT NULL default '0', + o_c_id int(11) default NULL, + o_entry_d timestamp NOT NULL, + o_carrier_id int(11) default NULL, + o_ol_cnt int(11) default NULL, + o_all_local double default NULL, + PRIMARY KEY (o_w_id,o_d_id,o_id), + KEY o_w_id (o_w_id,o_d_id,o_c_id,o_id) +); + +CREATE TABLE stock ( + s_i_id int(11) NOT NULL default '0', + s_w_id int(11) NOT NULL default '0', + s_quantity double NOT NULL default '0', + s_dist_01 varchar(24) default NULL, + s_dist_02 varchar(24) default NULL, + s_dist_03 varchar(24) default NULL, + s_dist_04 varchar(24) default NULL, + s_dist_05 varchar(24) default NULL, + s_dist_06 varchar(24) default NULL, + s_dist_07 varchar(24) default NULL, + s_dist_08 varchar(24) default NULL, + s_dist_09 varchar(24) default NULL, + s_dist_10 varchar(24) default NULL, + s_ytd decimal(16,8) default NULL, + s_order_cnt double default NULL, + s_remote_cnt double default NULL, + s_data varchar(50) default NULL, + PRIMARY KEY (s_w_id,s_i_id), + KEY (s_w_id,s_i_id,s_quantity) +); + +CREATE TABLE warehouse ( + w_id int(11) NOT NULL default '0', + w_name varchar(10) default NULL, + w_street_1 varchar(20) default NULL, + w_street_2 varchar(20) default NULL, + w_city varchar(20) default NULL, + w_state char(2) default NULL, + w_zip varchar(9) default NULL, + w_tax double default NULL, + w_ytd decimal(24,12) default NULL, + PRIMARY KEY (w_id) +); + + +CREATE PROCEDURE delivery(in_w_id INT, in_o_carrier_id INT) +BEGIN + DECLARE out_c_id INT; + DECLARE out_ol_amount INT; + DECLARE tmp_d_id INT; + DECLARE tmp_o_id INT default 0; + + SET tmp_d_id = 1; + + while tmp_d_id <= 10 DO + BEGIN + + SET tmp_o_id= 0; + + SELECT no_o_id + FROM new_order + WHERE no_w_id = in_w_id AND no_d_id = tmp_d_id + ORDER BY no_o_id ASC + LIMIT 1 + FOR UPDATE INTO tmp_o_id; + + IF tmp_o_id > 0 + THEN + DELETE FROM new_order + WHERE no_o_id = tmp_o_id + AND no_w_id = in_w_id + AND no_d_id = tmp_d_id; + + SELECT o_c_id + FROM orders + WHERE o_id = tmp_o_id + AND o_w_id = in_w_id + AND o_d_id = tmp_d_id + FOR UPDATE INTO out_c_id; + + UPDATE orders + SET o_carrier_id = in_o_carrier_id + WHERE o_id = tmp_o_id + AND o_w_id = in_w_id + AND o_d_id = tmp_d_id; + + UPDATE order_line force index (primary) + SET ol_delivery_d = current_timestamp + WHERE ol_o_id = tmp_o_id + AND ol_w_id = in_w_id + AND ol_d_id = tmp_d_id; + + SELECT SUM(ol_amount * ol_quantity) + FROM order_line force index (primary) + WHERE ol_o_id = tmp_o_id + AND ol_w_id = in_w_id + AND ol_d_id = tmp_d_id INTO out_ol_amount; + + UPDATE customer + SET c_delivery_cnt = c_delivery_cnt + 1, + c_balance = c_balance + out_ol_amount + WHERE c_id = out_c_id + AND c_w_id = in_w_id + AND c_d_id = tmp_d_id; + + END IF; + + SET tmp_d_id = tmp_d_id + 1; + + END; + END WHILE; +END// + +CREATE PROCEDURE new_order_2 (in_w_id INT, + in_d_id INT, + in_ol_i_id INT, + in_ol_quantity INT, + in_i_price NUMERIC, + in_i_name VARCHAR(24), + in_i_data VARCHAR(50), + in_ol_o_id INT, + in_ol_amount NUMERIC, + in_ol_supply_w_id INT, + in_ol_number INT, + out out_s_quantity INT) +BEGIN + + DECLARE tmp_s_dist VARCHAR(255); + DECLARE tmp_s_data VARCHAR(255); + + SET out_s_quantity = 0; + + IF in_d_id = 1 THEN + SELECT s_quantity, s_dist_01, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 2 THEN + SELECT s_quantity, s_dist_02, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 3 THEN + SELECT s_quantity, s_dist_03, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 4 THEN + SELECT s_quantity, s_dist_04, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 5 THEN + SELECT s_quantity, s_dist_05, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 6 THEN + SELECT s_quantity, s_dist_06, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 7 THEN + SELECT s_quantity, s_dist_07, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 8 THEN + SELECT s_quantity, s_dist_08, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 9 THEN + SELECT s_quantity, s_dist_09, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 10 THEN + SELECT s_quantity, s_dist_10, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + END IF; + + IF out_s_quantity > in_ol_quantity + 10 THEN + UPDATE stock + SET s_quantity = out_s_quantity - in_ol_quantity + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id; + ELSE + UPDATE stock + SET s_quantity = out_s_quantity - in_ol_quantity + 91 + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id; + END IF; + + INSERT INTO order_line (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, + ol_supply_w_id, ol_delivery_d, ol_quantity, + ol_amount, ol_dist_info) + VALUES (in_ol_o_id, in_d_id, in_w_id, in_ol_number, in_ol_i_id, + in_ol_supply_w_id, NULL, in_ol_quantity, in_ol_amount, + tmp_s_dist); +END// + +CREATE PROCEDURE new_order(tmp_w_id INT, + tmp_d_id INT, + tmp_c_id INT, + tmp_o_all_local INT, + tmp_o_ol_cnt INT, + ol_i_id1 INT, + ol_supply_w_id1 INT, + ol_quantity1 INT, + ol_i_id2 INT, + ol_supply_w_id2 INT, + ol_quantity2 INT, + ol_i_id3 INT, + ol_supply_w_id3 INT, + ol_quantity3 INT, + ol_i_id4 INT, + ol_supply_w_id4 INT, + ol_quantity4 INT, + ol_i_id5 INT, + ol_supply_w_id5 INT, + ol_quantity5 INT, + ol_i_id6 INT, + ol_supply_w_id6 INT, + ol_quantity6 INT, + ol_i_id7 INT, + ol_supply_w_id7 INT, + ol_quantity7 INT, + ol_i_id8 INT, + ol_supply_w_id8 INT, + ol_quantity8 INT, + ol_i_id9 INT, + ol_supply_w_id9 INT, + ol_quantity9 INT, + ol_i_id10 INT, + ol_supply_w_id10 INT, + ol_quantity10 INT, + ol_i_id11 INT, + ol_supply_w_id11 INT, + ol_quantity11 INT, + ol_i_id12 INT, + ol_supply_w_id12 INT, + ol_quantity12 INT, + ol_i_id13 INT, + ol_supply_w_id13 INT, + ol_quantity13 INT, + ol_i_id14 INT, + ol_supply_w_id14 INT, + ol_quantity14 INT, + ol_i_id15 INT, + ol_supply_w_id15 INT, + ol_quantity15 INT, + out rc int) +BEGIN + DECLARE out_c_credit VARCHAR(255); + DECLARE tmp_i_name VARCHAR(255); + DECLARE tmp_i_data VARCHAR(255); + DECLARE out_c_last VARCHAR(255); + + DECLARE tmp_ol_supply_w_id INT; + DECLARE tmp_ol_quantity INT; + DECLARE out_d_next_o_id INT; + DECLARE tmp_i_id INT; + + DECLARE tmp_s_quantity INT; + + DECLARE out_w_tax REAL; + DECLARE out_d_tax REAL; + DECLARE out_c_discount REAL; + DECLARE tmp_i_price REAL; + DECLARE tmp_ol_amount REAL; + DECLARE tmp_total_amount REAL; + + DECLARE o_id INT; + + declare exit handler for sqlstate '02000' set rc = 1; + + SET rc=0; + + SET o_id = 0; + + SELECT w_tax + FROM warehouse + WHERE w_id = tmp_w_id + INTO out_w_tax; + + SELECT d_tax, d_next_o_id + FROM district + WHERE d_w_id = tmp_w_id + AND d_id = tmp_d_id FOR UPDATE + INTO out_d_tax, out_d_next_o_id; + + SET o_id=out_d_next_o_id; + + UPDATE district + SET d_next_o_id = out_d_next_o_id + 1 + WHERE d_w_id = tmp_w_id + AND d_id = tmp_d_id; + + SELECT c_discount , c_last, c_credit + FROM customer + WHERE c_w_id = tmp_w_id + AND c_d_id = tmp_d_id + AND c_id = tmp_c_id + INTO out_c_discount, out_c_last, out_c_credit; + + INSERT INTO new_order (no_o_id, no_d_id, no_w_id) + VALUES (out_d_next_o_id, tmp_d_id, tmp_w_id); + + INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, + o_carrier_id, o_ol_cnt, o_all_local) + VALUES (out_d_next_o_id, tmp_d_id, tmp_w_id, tmp_c_id, + current_timestamp, NULL, tmp_o_ol_cnt, tmp_o_all_local); + + SET tmp_total_amount = 0; + + IF tmp_o_ol_cnt > 0 + THEN + + SET tmp_i_id = ol_i_id1; + SET tmp_ol_supply_w_id = ol_supply_w_id1; + SET tmp_ol_quantity = ol_quantity1; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 1, tmp_s_quantity); + + SET tmp_total_amount = tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 1 + THEN + SET tmp_i_id = ol_i_id2; + SET tmp_ol_supply_w_id = ol_supply_w_id2; + SET tmp_ol_quantity = ol_quantity2; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 2, tmp_s_quantity); + + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + IF tmp_o_ol_cnt > 2 + THEN + SET tmp_i_id = ol_i_id3; + SET tmp_ol_supply_w_id = ol_supply_w_id3; + SET tmp_ol_quantity = ol_quantity3; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 3, tmp_s_quantity); + + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 3 + THEN + SET tmp_i_id = ol_i_id4; + SET tmp_ol_supply_w_id = ol_supply_w_id4; + SET tmp_ol_quantity = ol_quantity4; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 4, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 4 + THEN + SET tmp_i_id = ol_i_id5; + SET tmp_ol_supply_w_id = ol_supply_w_id5; + SET tmp_ol_quantity = ol_quantity5; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 5, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 5 + THEN + SET tmp_i_id = ol_i_id6; + SET tmp_ol_supply_w_id = ol_supply_w_id6; + SET tmp_ol_quantity = ol_quantity6; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 6, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 6 + THEN + SET tmp_i_id = ol_i_id7; + SET tmp_ol_supply_w_id = ol_supply_w_id7; + SET tmp_ol_quantity = ol_quantity7; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 7, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 7 + THEN + SET tmp_i_id = ol_i_id8; + SET tmp_ol_supply_w_id = ol_supply_w_id8; + SET tmp_ol_quantity = ol_quantity8; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 8, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 8 + THEN + SET tmp_i_id = ol_i_id9; + SET tmp_ol_supply_w_id = ol_supply_w_id9; + SET tmp_ol_quantity = ol_quantity9; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 9, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 9 + THEN + SET tmp_i_id = ol_i_id10; + SET tmp_ol_supply_w_id = ol_supply_w_id10; + SET tmp_ol_quantity = ol_quantity10; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 10, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 10 + THEN + SET tmp_i_id = ol_i_id11; + SET tmp_ol_supply_w_id = ol_supply_w_id11; + SET tmp_ol_quantity = ol_quantity11; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 11, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 11 + THEN + SET tmp_i_id = ol_i_id12; + SET tmp_ol_supply_w_id = ol_supply_w_id12; + SET tmp_ol_quantity = ol_quantity12; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 12, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 12 + THEN + SET tmp_i_id = ol_i_id13; + SET tmp_ol_supply_w_id = ol_supply_w_id13; + SET tmp_ol_quantity = ol_quantity13; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 13, tmp_s_quantity); + + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 13 + THEN + SET tmp_i_id = ol_i_id14; + SET tmp_ol_supply_w_id = ol_supply_w_id14; + SET tmp_ol_quantity = ol_quantity14; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 14, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 14 + THEN + SET tmp_i_id = ol_i_id15; + SET tmp_ol_supply_w_id = ol_supply_w_id15; + SET tmp_ol_quantity = ol_quantity15; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 15, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; +END// + +CREATE PROCEDURE order_status (in_c_id INT, + in_c_w_id INT, + in_c_d_id INT, + in_c_last VARCHAR(16)) +BEGIN + DECLARE out_c_first VARCHAR(255); + DECLARE out_c_middle char(2); + DECLARE out_c_balance NUMERIC; + DECLARE out_o_id INT; + DECLARE out_o_carrier_id INT; + DECLARE out_o_entry_d VARCHAR(28); + DECLARE out_o_ol_cnt INT; + DECLARE out_ol_supply_w_id1 INT; + DECLARE out_ol_i_id1 INT; + DECLARE out_ol_quantity1 INT; + DECLARE out_ol_amount1 NUMERIC; + DECLARE out_ol_delivery_d1 VARCHAR(28); + DECLARE out_ol_supply_w_id2 INT; + DECLARE out_ol_i_id2 INT; + DECLARE out_ol_quantity2 INT; + DECLARE out_ol_amount2 NUMERIC; + DECLARE out_ol_delivery_d2 VARCHAR(28); + DECLARE out_ol_supply_w_id3 INT; + DECLARE out_ol_i_id3 INT; + DECLARE out_ol_quantity3 INT; + DECLARE out_ol_amount3 NUMERIC; + DECLARE out_ol_delivery_d3 VARCHAR(28); + DECLARE out_ol_supply_w_id4 INT; + DECLARE out_ol_i_id4 INT; + DECLARE out_ol_quantity4 INT; + DECLARE out_ol_amount4 NUMERIC; + DECLARE out_ol_delivery_d4 VARCHAR(28); + DECLARE out_ol_supply_w_id5 INT; + DECLARE out_ol_i_id5 INT; + DECLARE out_ol_quantity5 INT; + DECLARE out_ol_amount5 NUMERIC; + DECLARE out_ol_delivery_d5 VARCHAR(28); + DECLARE out_ol_supply_w_id6 INT; + DECLARE out_ol_i_id6 INT; + DECLARE out_ol_quantity6 INT; + DECLARE out_ol_amount6 NUMERIC; + DECLARE out_ol_delivery_d6 VARCHAR(28); + DECLARE out_ol_supply_w_id7 INT; + DECLARE out_ol_i_id7 INT; + DECLARE out_ol_quantity7 INT; + DECLARE out_ol_amount7 NUMERIC; + DECLARE out_ol_delivery_d7 VARCHAR(28); + DECLARE out_ol_supply_w_id8 INT; + DECLARE out_ol_i_id8 INT; + DECLARE out_ol_quantity8 INT; + DECLARE out_ol_amount8 NUMERIC; + DECLARE out_ol_delivery_d8 VARCHAR(28); + DECLARE out_ol_supply_w_id9 INT; + DECLARE out_ol_i_id9 INT; + DECLARE out_ol_quantity9 INT; + DECLARE out_ol_amount9 NUMERIC; + DECLARE out_ol_delivery_d9 VARCHAR(28); + DECLARE out_ol_supply_w_id10 INT; + DECLARE out_ol_i_id10 INT; + DECLARE out_ol_quantity10 INT; + DECLARE out_ol_amount10 NUMERIC; + DECLARE out_ol_delivery_d10 VARCHAR(28); + DECLARE out_ol_supply_w_id11 INT; + DECLARE out_ol_i_id11 INT; + DECLARE out_ol_quantity11 INT; + DECLARE out_ol_amount11 NUMERIC; + DECLARE out_ol_delivery_d11 VARCHAR(28); + DECLARE out_ol_supply_w_id12 INT; + DECLARE out_ol_i_id12 INT; + DECLARE out_ol_quantity12 INT; + DECLARE out_ol_amount12 NUMERIC; + DECLARE out_ol_delivery_d12 VARCHAR(28); + DECLARE out_ol_supply_w_id13 INT; + DECLARE out_ol_i_id13 INT; + DECLARE out_ol_quantity13 INT; + DECLARE out_ol_amount13 NUMERIC; + DECLARE out_ol_delivery_d13 VARCHAR(28); + DECLARE out_ol_supply_w_id14 INT; + DECLARE out_ol_i_id14 INT; + DECLARE out_ol_quantity14 INT; + DECLARE out_ol_amount14 NUMERIC; + DECLARE out_ol_delivery_d14 VARCHAR(28); + DECLARE out_ol_supply_w_id15 INT; + DECLARE out_ol_i_id15 INT; + DECLARE out_ol_quantity15 INT; + DECLARE out_ol_amount15 NUMERIC; + DECLARE out_ol_delivery_d15 VARCHAR(28); + DECLARE out_c_id INT; + DECLARE out_c_last VARCHAR(255); + DECLARE rc int default 0; + + declare c cursor for SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d + FROM order_line force index (primary) + WHERE ol_w_id = in_c_w_id + AND ol_d_id = in_c_d_id + AND ol_o_id = out_o_id; + declare continue handler for sqlstate '02000' set rc = 1; + # /* + # * Pick a customer by searching for c_last, should pick the one in the + # * middle, not the first one. + # */ + IF in_c_id = 0 + THEN + SELECT c_id + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_last = in_c_last + ORDER BY c_first ASC LIMIT 1 + INTO out_c_id; + ELSE + set out_c_id = in_c_id; + END IF; + + SELECT c_first, c_middle, c_last, c_balance + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_id = out_c_id + INTO out_c_first, out_c_middle, out_c_last, out_c_balance; + + SELECT o_id, o_carrier_id, o_entry_d, o_ol_cnt + FROM orders + WHERE o_w_id = in_c_w_id + AND o_d_id = in_c_d_id + AND o_c_id = out_c_id + ORDER BY o_id DESC LIMIT 1 + INTO out_o_id, out_o_carrier_id, out_o_entry_d, out_o_ol_cnt; + + open c; + fetch_block: + BEGIN + fetch c into out_ol_i_id1, out_ol_supply_w_id1, out_ol_quantity1, + out_ol_amount1, out_ol_delivery_d1; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id2, out_ol_supply_w_id2, out_ol_quantity2, + out_ol_amount2, out_ol_delivery_d2; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id3, out_ol_supply_w_id3, out_ol_quantity3, + out_ol_amount3, out_ol_delivery_d3; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id4, out_ol_supply_w_id4, out_ol_quantity4, + out_ol_amount4, out_ol_delivery_d4; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id5, out_ol_supply_w_id5, out_ol_quantity5, + out_ol_amount5, out_ol_delivery_d5; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id6, out_ol_supply_w_id6, out_ol_quantity6, + out_ol_amount6, out_ol_delivery_d6; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id7, out_ol_supply_w_id7, out_ol_quantity7, + out_ol_amount7, out_ol_delivery_d7; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id8, out_ol_supply_w_id8, out_ol_quantity8, + out_ol_amount8, out_ol_delivery_d8; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id9, out_ol_supply_w_id9, out_ol_quantity9, + out_ol_amount9, out_ol_delivery_d9; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id10, out_ol_supply_w_id10, out_ol_quantity10, + out_ol_amount10, out_ol_delivery_d10; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id11, out_ol_supply_w_id11, out_ol_quantity11, + out_ol_amount11, out_ol_delivery_d11; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id12, out_ol_supply_w_id12, out_ol_quantity12, + out_ol_amount12, out_ol_delivery_d12; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id13, out_ol_supply_w_id13, out_ol_quantity13, + out_ol_amount13, out_ol_delivery_d13; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id14, out_ol_supply_w_id14, out_ol_quantity14, + out_ol_amount14, out_ol_delivery_d14; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id15, out_ol_supply_w_id15, out_ol_quantity15, + out_ol_amount15, out_ol_delivery_d15; + end fetch_block; + close c; +END// + +CREATE PROCEDURE payment(in_w_id INT, in_d_id INT, in_c_id INT, in_c_w_id INT, in_c_d_id INT, + in_c_last VARCHAR(16), in_h_amount INT) +BEGIN + DECLARE out_w_name VARCHAR(10); + DECLARE out_w_street_1 VARCHAR(20); + DECLARE out_w_street_2 VARCHAR(20); + DECLARE out_w_city VARCHAR(20); + DECLARE out_w_state VARCHAR(2); + DECLARE out_w_zip VARCHAR(9); + DECLARE out_w_ytd INTEGER; + + DECLARE out_d_name VARCHAR(10); + DECLARE out_d_street_1 VARCHAR(20); + DECLARE out_d_street_2 VARCHAR(20); + DECLARE out_d_city VARCHAR(20); + DECLARE out_d_state VARCHAR(2); + DECLARE out_d_zip VARCHAR(9); + DECLARE out_d_ytd INTEGER; + + DECLARE out_c_id INTEGER; + DECLARE out_c_first VARCHAR(16); + DECLARE out_c_middle VARCHAR(2); + DECLARE out_c_last VARCHAR(20); + DECLARE out_c_street_1 VARCHAR(20); + DECLARE out_c_street_2 VARCHAR(20); + DECLARE out_c_city VARCHAR(20); + DECLARE out_c_state VARCHAR(2); + DECLARE out_c_zip VARCHAR(9); + DECLARE out_c_phone VARCHAR(16); + DECLARE out_c_since VARCHAR(28); + DECLARE out_c_credit VARCHAR(2); + DECLARE out_c_credit_lim DECIMAL(24, 12); + DECLARE out_c_discount REAL; + DECLARE out_c_balance NUMERIC; + DECLARE out_c_data VARCHAR(500); + DECLARE out_c_ytd_payment INTEGER; + + # /* Goofy temporaty variables. */ + DECLARE tmp_c_id VARCHAR(30); + DECLARE tmp_c_d_id VARCHAR(30); + DECLARE tmp_c_w_id VARCHAR(30); + DECLARE tmp_d_id VARCHAR(30); + DECLARE tmp_w_id VARCHAR(30); + DECLARE tmp_h_amount VARCHAR(30); + + # /* This one is not goofy. */ + DECLARE tmp_h_data VARCHAR(30); + + SELECT w_name, w_street_1, w_street_2, w_city, w_state, w_zip, w_ytd + FROM warehouse + WHERE w_id = in_w_id + FOR UPDATE + INTO out_w_name, out_w_street_1, out_w_street_2, out_w_city, + out_w_state, out_w_zip, out_w_ytd; + + UPDATE warehouse + SET w_ytd = out_w_ytd + in_h_amount + WHERE w_id = in_w_id; + + SELECT d_name, d_street_1, d_street_2, d_city, d_state, d_zip, d_ytd + FROM district + WHERE d_id = in_d_id + AND d_w_id = in_w_id + FOR UPDATE + INTO out_d_name, out_d_street_1, out_d_street_2, out_d_city, + out_d_state, out_d_zip, out_d_ytd; + + UPDATE district + SET d_ytd = out_d_ytd + in_h_amount + WHERE d_id = in_d_id + AND d_w_id = in_w_id; + + #/* + # * Pick a customer by searching for c_last, should pick the one in the + # * middle, not the first one. + # */ + IF in_c_id = 0 THEN + SELECT c_id + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_last = in_c_last + ORDER BY c_first ASC LIMIT 1 + FOR UPDATE + INTO out_c_id; + ELSE + SET out_c_id = in_c_id; + END IF; + + SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, + c_state, c_zip, c_phone, c_since, c_credit, + c_credit_lim, c_discount, c_balance, c_data, + c_ytd_payment + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_id = out_c_id + FOR UPDATE + INTO out_c_first, out_c_middle, out_c_last, out_c_street_1, + out_c_street_2, out_c_city, out_c_state, out_c_zip, out_c_phone, + out_c_since, out_c_credit, out_c_credit_lim, out_c_discount, + out_c_balance, out_c_data, out_c_ytd_payment; + + # /* Check credit rating. */ + IF out_c_credit = 'BC' + THEN + SELECT out_c_id + INTO tmp_c_id; + SELECT in_c_d_id + INTO tmp_c_d_id; + SELECT in_c_w_id + INTO tmp_c_w_id; + SELECT in_d_id + INTO tmp_d_id; + SELECT in_w_id + INTO tmp_w_id; + + SET out_c_data = concat(tmp_c_id,' ',tmp_c_d_id,' ',tmp_c_w_id,' ',tmp_d_id,' ',tmp_w_id); + + UPDATE customer + SET c_balance = out_c_balance - in_h_amount, + c_ytd_payment = out_c_ytd_payment + 1, + c_data = out_c_data + WHERE c_id = out_c_id + AND c_w_id = in_c_w_id + AND c_d_id = in_c_d_id; + ELSE + UPDATE customer + SET c_balance = out_c_balance - in_h_amount, + c_ytd_payment = out_c_ytd_payment + 1 + WHERE c_id = out_c_id + AND c_w_id = in_c_w_id + AND c_d_id = in_c_d_id; + END IF; + + SET tmp_h_data = concat(out_w_name,' ', out_d_name); + INSERT INTO history (h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, + h_date, h_amount, h_data) + VALUES (out_c_id, in_c_d_id, in_c_w_id, in_d_id, in_w_id, + current_timestamp, in_h_amount, tmp_h_data); + + # RETURN out_c_id; +END // + +CREATE PROCEDURE stock_level(in_w_id INT, + in_d_id INT, + in_threshold INT, + OUT low_stock INT) +BEGIN + DECLARE tmp_d_next_o_id INT; + + SELECT d_next_o_id + FROM district + WHERE d_w_id = in_w_id + AND d_id = in_d_id + INTO tmp_d_next_o_id; + + SELECT count(*) + FROM order_line, stock, district + WHERE d_id = in_d_id + AND d_w_id = in_w_id + AND d_id = ol_d_id + AND d_w_id = ol_w_id + AND ol_i_id = s_i_id + AND ol_w_id = s_w_id + AND s_quantity < in_threshold + AND ol_o_id BETWEEN (tmp_d_next_o_id - 20) + AND (tmp_d_next_o_id - 1) + INTO low_stock; +END// + + +## LOAD DATA +## ./src/datagen -w 1 -m 1 -c 1 -i 1 -o 1 -n 1 -d /home/linlin.xll/work/dbt2-0.37.50.15/data/ --mysql +## sh mysql_load_db.sh --mysql-path /usr/bin/mysql --host 10.244.4.65 --local --path /home/linlin.xll/data/ +## sh mysql_load_sp.sh --client-path /usr/bin/ --host 10.244.4.65 +## sh run_mysql.sh --connections 1 --time 10 --warehouses 1 --host 10.244.4.65 --lib-client-path /usr/bin/mysql --verbose --terminals 1 +insert into customer values(1,1,1,"4W+?M?/aG","OE","BARBARBAR","?VJ;t+P??m5v2?.=?T","%N#RO?|??;[_??~!Y?HP","?[S!JV58?#;+$cP?=d","tw",547411111,3078688431492068,"2018-09-13 15:23:42","GC",50000.00,0.0012,-10.00,10.00,1,0,"?&s?Jf4\\>?oCj'n?HR`i]c?uDH&-w?4??}{39?mL?2mC712Tao??1?oJ)kLvP^_:91BO??qs?F*t#[???m?7sX7|p*Nne?d|\\X}T'?tC?t??-???Ox'?&4zt4?9v?rQ?'#q.?CF??1???x?@G?5K???&?*sk{??x?N{~f?_P%7]z?G?O:0EM<+??*X[W??Y)???V2pfk??Dm=??L/4v@=X?=?[rpD(w??eM?+?\\??}O?|GB?P??kC??%FMs_SAV4??$?fVoB1?8?8WXfCC&c6?_Q-'?]FBg??a?\\?Vt!H?z"); +insert into customer values(1,3,1,"?0?WH??\\|L??", "OE", "BARBARBAR", "n9m?}j|H@TZ??gFp\\kFAi(7?]W?(?_<`o]SE?fk???}?_?]?ax/?v;?1ol0a?A?n{G?^?QOxA?e}??lOmpMA?6HNxM?wk?CD%(w?P$Un#?B???>HQ`_0s?\\I&F?o$6??5]?b_7.Y$EH?%c$U?aZi;???8??2?q0?-?aa?d???5m?up5k/e3HV?dcqFsV?xU?X?VMNC;*V???T?b`Xr}?`@E&c?[Mc?:?wmD??T!18?'aug?*/r?l?/pH?(kZ??IaEbY'?Q/?14Y|pN?|?fF?j??Y?i?tI03kpaiZ?mY?v?oD3J?/?9?N????MkSkq[5??sv~>$r???3?^%?B4?m!_G???*RWd\\k[-70H9?/??7?H:?gC_)D?N??+?)`]\\??f5??D"); +insert into customer values(1,4,1,"?:Y??~5|CN9", "OE", "BARBARBAR", "g)fX?oQ?%?B", "p~7aXX/>g]9f:D8RgFr", "M6a+z??}i)?7}", "yL", 361011111, 7420033904334245, "2018-09-13 15:23:42", "GC", 50000.00, 0.3738, -10.00, 10.00, 1, 0, "N*f7vnUE?9G<_`????b2?\\Fp^:?H??9$?t9]8lx???17S??R{XYz?|@E?3kj?yd?Dr4Y1;Z???L3Up]z~lb?r?~dM?^p?eIqp??v?=e?&??YMN1(?q?XPb?{FVI$?gkVGN)0`e?dJ??t$?s?hV???7^1b}3PB||_??l^>Y?]8?02?x?E#.0?:d?y?&?^?p?}Rd9e?/?(?%0y{??t(?a@ZU?vY?37Q!?xe?iXjqw&?O??S??-AQ?0?7TzR]`??HPc\\???]]?P??=3{?=?"); +insert into customer values(1,5,1,"2?'>Pxn?.d", "OE", "BARBARBAR", "T?(?~?~2Qs_1[r", "+oS!?[??vL_B-j?r?lxv", "dJO????LT1", "wr", 609111111, 1509496824653474, "2018-09-13 15:23:42", "GC", 50000.00, 0.2251, -10.00, 10.00, 1, 0, "}n40ejZEZ???H?p?a%.%??70Igi]??`kHqx?1'?h??[!y??0??+??8?(|b[r;?;X_?8n?2+h?]`[TIiN5rA??:?aqL(?;98o?F3?M=G8o?h?#/L6vb(Sr??A;??S%&??B(xl;?y?w@}pD&??_?A/p(E??<2?@'?_&O??Ax???o[&l5?(?45b:WA?pP??NZ:R?9f??X?i%9moK`u=q?t?4?z?8\\]c?u?g?Oag|?%?VpD~.??tsZR?B*]X\\??=b??;%8w?Uz]?AvTLk;?4rF??FAHw/6?f?h??vLe($?~Ck0d4@X>?t?x?A?]E(D???]xV?;\\?00?y5[?S??A[??@+?zN??+h|_70?fvk?R??", "??a???L*G??Yp`??#", "Ek", 848911111, 3707196301486666, "2018-09-13 15:23:42", "GC", 50000.00, 0.4027, -10.00, 10.00, 1, 0, "ttO?>:?!?eL??.?A??QI?Gh(=$@3??^am?K??Cyt?![j%S??<0F!L?(f~>nj8)(z?IYyj0CE0t?4?k(6xL6?%5]?P(Je'H6?ol^/yvQ~H4?Z\\?yJD?=M^??$?^jG1k=E??!D8?jKw??eQk){Zg^??3p?~6?8?nJ?=4?zOR??E?VkX]D??wo??5_cHHp1???%?nuF?m79Rk??%?e?o){M=9?bVThHATC8??S?Yg*?0?f+y(&>1whK?L?B}I_?r?(hkYR!?Z?#9M-?T(#Z~iza?Z?ex5WI?]?S?7S?f:?u]?Z??[>^????EkF?~z:"); +insert into customer values(1,8,1,"-???)8tfGL9?%pe?", "OE", "BARBARBAR", "x:?k-q?u?wId??gy", "[y?%=!GS?B?E???4?T6", "8?H?'?p?G@Q", "dH", 317811111, 5312129264696994, "2018-09-13 15:23:42", "GC", 50000.00, 0.2249, -10.00, 10.00, 1, 0, "v??C????$o>~sb{q|ax???5/}?>mBpn~=9?n?HbiOmB?<~H}iR?A?A\\<6GWM?#)'2?s?=*PivoP?Cn[??=?y[S?fwG?Z@?`G?(.')[f}??Z@X??S-?)]G???/?LLt?iW?tT?$?a?y??/?5X?(W?M?6>K?gldF*?+|B?~'Ou~F??$$1?*]#My7h?&.dhIlOR?f@?kdfH?N??H/^HiWrAc88g;y$bDQ?`??PV`?{E7y?\\}P?E?Q[E_p?w@{/a!????tl%?Fj?6c?h%?9%d0?U[iYco?>ZeSM???{?3De>|R??:??t?k&X)^?oE+&?]J^O?7)GPlc)??#j??K%Y7&?i23mX?z[3?5X?u~>w.????S??s?9???G?#???bw?O?F?\\?Z)%I??1;z??U'i4????m7w-?eQk?m?y??t;?mI?E8}x=We._?dhL", "GU", 886611111, 8211838608073655, "2018-09-13 15:23:42", "GC", 50000.00, 0.0409, -10.00, 10.00, 1, 0, "2MouAk0(+&JaDUpM?h?XV\\?Q[X?$%fH-???&V?%W?M?#w[NZ???Lps{?)Z!$?A'{#??O_???%n@z&c)?w??=h??DI?P<%B5o`(vg-M?W!?????}h?|?*?^E6ErHI?Z?GaY?k?q?{\\?jP?=?r?lr|???Bd-hKeKg??I\\Z?Q+I7sn??Z]r?-D??)8Y+vzf?7_~]?6B@?`L?-/d\\a+UkNKXMX?V+_?(kO??>?>S$|t?~?<8?Ej?h?6?@?GJO"); + +insert into district values(1,1,"4W+?M?/aG","?VJ;t+P??m5v2?.=?T","%N#RO?|??;[_??~!Y?HP","?[S!JV58?#;+$cP?=d","tw", 547411111, 0.0364, 30000.00, 3001); +insert into district values(2,1,"[VIK?yC..","C?WS?Q?2?&s?J","4\\>?oCj'n?HR`i]c?u","H&-w?4??}{39","FT", 948111111, 0.1732, 30000.00, 3001); +insert into district values(3,1,"Tao??1?oJ)","LvP^_:91BO??qs??"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 7, 1, 7, 1, "2018-09-13 15:23:42", 10.00,"Cj'n?HR`i]c?uDH&-w?4"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 8, 1, 8, 1, "2018-09-13 15:23:42", 10.00,"?}{39?mL?2mC71"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 9, 1, 9, 1, "2018-09-13 15:23:42", 10.00,"Tao??1?oJ)kLvP^"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 10,1, 10,1, "2018-09-13 15:23:42", 10.00,":91BO??qs?0) +then +signal sqlstate '03001'; +else +signal sqlstate '03002'; +end if; +end// +create procedure pp(x bigint) +begin +call p(x); +end// +call pp(0); +ERROR 03002: Unhandled user-defined exception condition +select * from a; ++------+ +| a1 | ++------+ ++------+ +call pp(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +drop table a; +drop procedure p; +drop procedure pp; + +create table a(a1 int); +create procedure p(x bigint) +begin +DECLARE Exit HANDLER FOR sqlstate '03001' +BEGIN +insert into a values(1); +END; +if(x>0) +then +signal sqlstate '03001'; +else +signal sqlstate '03002'; +end if; +end// +create procedure pp(x bigint) +begin +call p(x); +end// +call pp(0); +ERROR 03002: Unhandled user-defined exception condition +select * from a; ++------+ +| a1 | ++------+ ++------+ +call pp(1); +select * from a; ++------+ +| a1 | ++------+ +| 1 | ++------+ +drop table a; +drop procedure p; +drop procedure pp; + +create table a(a1 int); +create procedure p() +begin +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION insert into a values(3); +select *,* from a; +end// +call p; +select * from a; ++------+ +| a1 | ++------+ +| 3 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p() +begin +DECLARE Exit HANDLER FOR SQLEXCEPTION insert into a values(3); +select *,* from a; +end// +call p; +select * from a; ++------+ +| a1 | ++------+ +| 3 | ++------+ +drop table a; +drop procedure p; + +CREATE PROCEDURE p() +BEGIN +label1: LOOP +begin +DECLARE Exit HANDLER FOR SQLEXCEPTION +begin +leave label1; +end; +signal sqlstate '04001'; +end; +END LOOP label1; +END// +ERROR 42000: no matching label: label1 + +create table a(a1 int); +create procedure p(x int) +begin +declare exit handler for SQLSTATE '20000' +insert into a values(-1); +case x +when 1 then insert into a values(1); +end case; +end// +call p(3); +select * from a; ++------+ +| a1 | ++------+ +| -1 | ++------+ +drop table a; +drop procedure p; + +create table a(a1 int); +create procedure p() +begin +DECLARE no_such_table CONDITION FOR 1051; +DECLARE Exit HANDLER FOR 1052 +BEGIN +insert into a values(1052); +END; +signal no_such_table; +end// +ERROR HY000: SIGNAL/RESIGNAL can only use a CONDITION defined with SQLSTATE +create procedure pp(x bigint) +begin +DECLARE Exit HANDLER FOR 1051 +BEGIN +insert into a values(1051); +END; +call p; +end// +call pp(1); +ERROR 42000: procedure/function does not exist +select * from a; ++------+ +| a1 | ++------+ ++------+ +drop table a; +drop procedure pp; + +create table a(a1 int); +create procedure p() +begin +DECLARE no_such_table CONDITION FOR SQLSTATE '10510'; +DECLARE Exit HANDLER FOR SQLSTATE '10520' +BEGIN +insert into a values(1052); +END; +signal no_such_table; +end// +create procedure pp(x bigint) +begin +DECLARE Exit HANDLER FOR SQLSTATE '10510' +BEGIN +insert into a values(1051); +END; +call p; +end// +call pp(1); +select * from a; ++------+ +| a1 | ++------+ +| 1051 | ++------+ +drop table a; +drop procedure p; +drop procedure pp; + +create table a(a1 int); +create procedure p(x int) +begin +declare exit handler for SQLSTATE '20000' +insert into a values(-1); +case x +when 1 then insert into a values(x); +end case; +delete from a; +end// +select route_sql from oceanbase.__all_routine, oceanbase.__all_database where routine_name = 'p' and database_name = 'test'; ++--------------------------+ +| route_sql | ++--------------------------+ +| insert into a values(:0) | ++--------------------------+ +call p(1); +drop procedure p; +drop table a; + +create table a(a1 int); +create table b(b1 int); +create procedure p() +begin +declare x int; +declare exit handler for not found insert into b values(-1); +select a1 from a into x ; +insert into b values(1); +end// +call p; +select * from a; ++------+ +| a1 | ++------+ ++------+ +select * from b; ++------+ +| b1 | ++------+ +| -1 | ++------+ +drop table a; +drop table b; +drop procedure p; + +create table a(a1 int); +insert into a values(0); +create table b(b1 int); +create procedure p() +begin +declare x int; +declare exit handler for not found insert into b values(-1); +select a1 from a into x; +insert into b values(1); +end// +call p; +select * from a; ++------+ +| a1 | ++------+ +| 0 | ++------+ +select * from b; ++------+ +| b1 | ++------+ +| 1 | ++------+ +drop table a; +drop table b; +drop procedure p; diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_exception_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_exception_mysql.result new file mode 100644 index 000000000..cbd6edb73 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/pl_exception_mysql.result @@ -0,0 +1,358 @@ +drop table if exists a,t; +drop procedure if exists p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE CONTINUE HANDLER FOR sqlexception insert into a values(0); +DECLARE EXIT HANDLER FOR SQLSTATE '23000' insert into a values(1); +insert into t values(1); +insert into a values(2); +end// +call p(0); +select * from a; +a1 +1 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE CONTINUE HANDLER FOR sqlexception insert into a values(0); +begin +DECLARE EXIT HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +0 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE CONTINUE HANDLER FOR sqlwarning insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +0 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE EXIT HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE CONTINUE HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR sqlwarning insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +0 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE CONTINUE HANDLER FOR sqlwarning insert into a values(5); +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end; +end// +call p(0); +select * from a; +a1 +5 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE CONTINUE HANDLER FOR sqlexception insert into a values(5); +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end; +end// +call p(0); +select * from a; +a1 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +select * from a; +a1 +2 +3 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end// +call p(0); +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +select * from a; +a1 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR sqlexception insert into a values(0); +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end; +insert into a values(5); +end// +call p(0); +select * from a; +a1 +0 +5 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE continue HANDLER FOR sqlexception insert into a values(-1); +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE continue HANDLER FOR sqlexception +begin +insert into a values(0); +insert into t values(1); +insert into a values(6); +end; +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end; +insert into a values(5); +end// +call p(0); +select * from a; +a1 +0 +-1 +6 +2 +3 +5 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE EXIT HANDLER FOR sqlexception insert into a values(0); +DECLARE EXIT HANDLER FOR SQLSTATE '23000' insert into a values(1); +insert into t values(1); +insert into a values(2); +end// +call p(0); +select * from a; +a1 +1 +drop table a; +drop table t; +drop procedure p; +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +create procedure p(x int) +begin +DECLARE EXIT HANDLER FOR SQLSTATE '23000' insert into a values(1); +DECLARE EXIT HANDLER FOR sqlexception insert into a values(0); +insert into t values(1); +insert into a values(2); +end// +call p(0); +select * from a; +a1 +1 +drop table a; +drop table t; +drop procedure p; +create table t(col int primary key); +insert into t values(1); +create procedure p() +begin +declare x condition for sqlstate '23000'; +declare exit handler for x +begin +rollback; +resignal; +end; +insert into t values(1); +end; +// +call p(); +// +ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +drop procedure p; +drop table t; diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-bugs_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-bugs_mysql.result new file mode 100644 index 000000000..9c5fef67d --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-bugs_mysql.result @@ -0,0 +1,253 @@ +result_format: 4 +# +# Bug #47412: Valgrind warnings / user can read uninitalized memory +# using SP variables +# +DROP SCHEMA IF EXISTS testdb; +CREATE SCHEMA testdb; +USE testdb; + +CREATE FUNCTION f2 () RETURNS INTEGER +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1; + RETURN f_not_exists () ; +END| +CREATE PROCEDURE p3 ( arg1 VARCHAR(32) ) +BEGIN + CALL p_not_exists(); +END| +# should not return valgrind warnings +### TODO : --error 1305 +CALL p3(f2()); +ERROR 2F005: FUNCTION ended without RETURN + +DROP SCHEMA testdb; + +CREATE SCHEMA testdb; +USE testdb; + +CREATE FUNCTION f2() RETURNS INTEGER +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1; + RETURN f_not_exists(); +END| +CREATE PROCEDURE p3(arg2 INTEGER) +BEGIN + CALL p_not_exists(); +END| +# should not return valgrind warnings +### TODO : --error 1305 +CALL p3(f2()); +ERROR 2F005: FUNCTION ended without RETURN + +DROP SCHEMA testdb; + +CREATE SCHEMA testdb; +USE testdb; + +CREATE FUNCTION f2 () RETURNS INTEGER +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1; + RETURN f_not_exists () ; +END| +# should not return valgrind warnings +### TODO : --error 1305 +SELECT f2(); +ERROR 2F005: FUNCTION ended without RETURN + +DROP SCHEMA testdb; + +USE test; + +# +# Bug#50423: Crash on second call of a procedure dropping a trigger +# +## coeanbase not support trigger yet ! +## +## DROP TABLE IF EXISTS t1; +## DROP TRIGGER IF EXISTS tr1; +## DROP PROCEDURE IF EXISTS p1; +## --enable_warnings +## +## CREATE TABLE t1 (f1 INTEGER); +## CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1; +## CREATE PROCEDURE p1 () DROP TRIGGER tr1; +## +## CALL p1 (); +## --error ER_TRG_DOES_NOT_EXIST +## CALL p1 (); +## +## DROP TABLE t1; +## DROP PROCEDURE p1; +## +## --echo # +## --echo # Bug#50423: Crash on second call of a procedure dropping a trigger +## --echo # +## +## --disable_warnings +## DROP TABLE IF EXISTS t1; +## DROP TRIGGER IF EXISTS tr1; +## DROP PROCEDURE IF EXISTS p1; +## --enable_warnings +## +## CREATE TABLE t1 (f1 INTEGER); +## CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1; +## CREATE PROCEDURE p1 () DROP TRIGGER tr1; +## +## CALL p1 (); +## --error ER_TRG_DOES_NOT_EXIST +## CALL p1 (); +## +## DROP TABLE t1; +## DROP PROCEDURE p1; +# +# Bug#54375: Error in stored procedure leaves connection +# in different default schema +# +SET @SQL_MODE_SAVE = @@SQL_MODE; +SET @@SQL_MODE = 'STRICT_ALL_TABLES'; +DROP DATABASE IF EXISTS db1; +CREATE DATABASE db1; +USE db1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c1 int NOT NULL PRIMARY KEY); +INSERT INTO t1 VALUES (1); +CREATE FUNCTION f1 ( + some_value int +) +RETURNS smallint +DETERMINISTIC +BEGIN + INSERT INTO t1 SET c1 = some_value; + RETURN(LAST_INSERT_ID()); +END$$ +DROP DATABASE IF EXISTS db2; +CREATE DATABASE db2; +USE db2; +SELECT DATABASE(); ++------------+ +| DATABASE() | ++------------+ +| db2 | ++------------+ +SELECT db1.f1(1); +Got one of the listed errors +SELECT DATABASE(); ++------------+ +| DATABASE() | ++------------+ +| db2 | ++------------+ +USE test; +DROP FUNCTION db1.f1; +DROP TABLE db1.t1; +DROP DATABASE db1; +DROP DATABASE db2; + +# +# Bug#13105873:valgrind warning:possible crash in foreign +# key handling on subsequent create table if not exists +# +## oceanbase not support foreign key yet! +## --disable_warnings +## DROP DATABASE IF EXISTS testdb; +## --enable_warnings +## CREATE DATABASE testdb; +## USE testdb; +## CREATE TABLE t1 (id1 INT PRIMARY KEY); +## DELIMITER $; +## CREATE PROCEDURE `p1`() +## BEGIN +## CREATE TABLE IF NOT EXISTS t2(id INT PRIMARY KEY, +## CONSTRAINT FK FOREIGN KEY (id) REFERENCES t1( id1 )); +## END$ +## DELIMITER ;$ +## CALL p1(); +## --echo # below stmt should not return valgrind warnings +## CALL p1(); +## DROP DATABASE testdb; +## USE test; +End of 5.1 tests +# +# BUG#13489996 valgrind:conditional jump or move depends on +# uninitialised values-field_blob +# +## oceanbase not support BLOB yet! +## CREATE FUNCTION sf() RETURNS BLOB RETURN ""; +## SELECT sf(); +## DROP FUNCTION sf; +# +# Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE +# +SET @@SQL_MODE = ''; +CREATE FUNCTION testf_bug11763507() RETURNS INT +BEGIN + RETURN 0; +END +$ + +CREATE PROCEDURE testp_bug11763507() +BEGIN + SELECT "PROCEDURE testp_bug11763507"; +END +$ + + +SELECT testf_bug11763507(); ++---------------------+ +| testf_bug11763507() | ++---------------------+ +| 0 | ++---------------------+ +SELECT TESTF_bug11763507(); ++---------------------+ +| TESTF_bug11763507() | ++---------------------+ +| 0 | ++---------------------+ + +CALL testp_bug11763507(); ++-----------------------------+ +| PROCEDURE testp_bug11763507 | ++-----------------------------+ +| PROCEDURE testp_bug11763507 | ++-----------------------------+ +CALL TESTP_bug11763507(); ++-----------------------------+ +| PROCEDURE testp_bug11763507 | ++-----------------------------+ +| PROCEDURE testp_bug11763507 | ++-----------------------------+ + +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'testf_bug11763507'; ++-------------------+ +| specific_name | ++-------------------+ +| testf_bug11763507 | ++-------------------+ +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'TESTF_bug11763507'; ++-------------------+ +| specific_name | ++-------------------+ +| testf_bug11763507 | ++-------------------+ + +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='testf_bug11763507'; ++-------------------+ +| specific_name | ++-------------------+ +| testf_bug11763507 | ++-------------------+ +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='TESTF_bug11763507'; ++-------------------+ +| specific_name | ++-------------------+ +| testf_bug11763507 | ++-------------------+ + +DROP PROCEDURE testp_bug11763507; +DROP FUNCTION testf_bug11763507; + +SET @@SQL_MODE = @SQL_MODE_SAVE; + +#END OF BUG#11763507 test. diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-fib_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-fib_mysql.result new file mode 100644 index 000000000..2bd1c628c --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-fib_mysql.result @@ -0,0 +1,44 @@ +result_format: 4 +drop table if exists t3; +create table t3 ( f bigint unsigned not null ); + +drop procedure if exists fib; + +create procedure fib(n int unsigned) +begin + if n > 1 then + begin + declare x, y bigint unsigned; + declare c cursor for select f from t3 order by f desc limit 2; + open c; + fetch c into y; + fetch c into x; + insert into t3 values (x+y); + call fib(n-1); + ## Close the cursor AFTER the recursion to ensure that the stack + ## frame is somewhat intact. + close c; + end; + end if; +end| + +set @@max_sp_recursion_depth= 20| + +insert into t3 values (0), (1)| + +call fib(4)| + +select * from t3 order by f asc| ++---+ +| f | ++---+ +| 0 | +| 1 | +| 1 | +| 2 | +| 3 | ++---+ + +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-vars_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-vars_mysql.result new file mode 100644 index 000000000..cf0422292 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp-vars_mysql.result @@ -0,0 +1,1711 @@ +result_format: 4 +set ob_query_timeout=100000000; + +########################################################################### +########################################################################### +DROP PROCEDURE IF EXISTS sp_vars_check_dflt; +DROP PROCEDURE IF EXISTS sp_vars_check_assignment; +DROP FUNCTION IF EXISTS sp_vars_check_ret1; +DROP FUNCTION IF EXISTS sp_vars_check_ret2; +DROP FUNCTION IF EXISTS sp_vars_check_ret3; +DROP FUNCTION IF EXISTS sp_vars_check_ret4; +DROP FUNCTION IF EXISTS sp_vars_div_zero; + +########################################################################### +########################################################################### +## SET @@sql_mode = 'ansi'; +## REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI +## for ansi, oceanbase only support PIPES_AS_CONCAT and ONLY_FULL_GROUP_BY +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + + +CREATE PROCEDURE sp_vars_check_dflt() +BEGIN + DECLARE v1 TINYINT DEFAULT 1e200; + DECLARE v1u TINYINT UNSIGNED DEFAULT 1e200; + DECLARE v2 TINYINT DEFAULT -1e200; + DECLARE v2u TINYINT UNSIGNED DEFAULT -1e200; + DECLARE v3 TINYINT DEFAULT 300; + DECLARE v3u TINYINT UNSIGNED DEFAULT 300; + DECLARE v4 TINYINT DEFAULT -300; + DECLARE v4u TINYINT UNSIGNED DEFAULT -300; + + DECLARE v5 TINYINT DEFAULT 10 * 10 * 10; + DECLARE v5u TINYINT UNSIGNED DEFAULT 10 * 10 * 10; + DECLARE v6 TINYINT DEFAULT -10 * 10 * 10; + DECLARE v6u TINYINT UNSIGNED DEFAULT -10 * 10 * 10; + + DECLARE v7 TINYINT DEFAULT '10'; + DECLARE v8 TINYINT DEFAULT '10 '; + DECLARE v9 TINYINT DEFAULT ' 10 '; + DECLARE v10 TINYINT DEFAULT 'String 10 '; + DECLARE v11 TINYINT DEFAULT 'String10'; + DECLARE v12 TINYINT DEFAULT '10 String'; + DECLARE v13 TINYINT DEFAULT '10String'; + DECLARE v14 TINYINT DEFAULT concat('10', ' '); + DECLARE v15 TINYINT DEFAULT concat(' ', '10'); + DECLARE v16 TINYINT DEFAULT concat('Hello, ', 'world'); + + DECLARE v17 DECIMAL(64, 2) DEFAULT 12; + DECLARE v18 DECIMAL(64, 2) DEFAULT 12.123; + DECLARE v19 DECIMAL(64, 2) DEFAULT 11 + 1; + DECLARE v20 DECIMAL(64, 2) DEFAULT 12 + 0.123; + + SELECT v1, v1u, v2, v2u, v3, v3u, v4, v4u; + SELECT v5, v5u, v6, v6u; + SELECT v7, v8, v9, v10, v11, v12, v13, v14, v15, v16; + SELECT v17, v18, v19, v20; +END| + +CREATE PROCEDURE sp_vars_check_assignment() +BEGIN + DECLARE i1, i2, i3, i4 TINYINT; + DECLARE u1, u2, u3, u4 TINYINT UNSIGNED; + DECLARE d1, d2, d3 DECIMAL(64, 2); + + SET i1 = 1e200; + SET i2 = -1e200; + SET i3 = 300; + SET i4 = -300; + + SELECT i1, i2, i3, i4; + + SET i1 = 10 * 10 * 10; + SET i2 = -10 * 10 * 10; + SET i3 = sign(10 * 10) * 10 * 20; + SET i4 = sign(-10 * 10) * -10 * 20; + + SELECT i1, i2, i3, i4; + + SET u1 = 1e200; + SET u2 = -1e200; + SET u3 = 300; + SET u4 = -300; + + SELECT u1, u2, u3, u4; + + SET u1 = 10 * 10 * 10; + SET u2 = -10 * 10 * 10; + SET u3 = sign(10 * 10) * 10 * 20; + SET u4 = sign(-10 * 10) * -10 * 20; + + SELECT u1, u2, u3, u4; + + SET d1 = 1234; + SET d2 = 1234.12; + SET d3 = 1234.1234; + + SELECT d1, d2, d3; + + SET d1 = 12 * 100 + 34; + SET d2 = 12 * 100 + 34 + 0.12; + SET d3 = 12 * 100 + 34 + 0.1234; + + SELECT d1, d2, d3; +END| + +CREATE FUNCTION sp_vars_check_ret1() RETURNS TINYINT +BEGIN + RETURN 1e200; +END| + +CREATE FUNCTION sp_vars_check_ret2() RETURNS TINYINT +BEGIN + RETURN 10 * 10 * 10; +END| + +CREATE FUNCTION sp_vars_check_ret3() RETURNS TINYINT +BEGIN + RETURN 'Hello, world'; +END| + +CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2) +BEGIN + RETURN 12 * 10 + 34 + 0.1234; +END| + +CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER +BEGIN + DECLARE div_zero INTEGER; + SELECT 1/0 INTO div_zero; + RETURN div_zero; +END| + + + +--------------------------------------------------------------- +Calling the routines, created in ANSI mode. +--------------------------------------------------------------- + +CALL sp_vars_check_dflt(); ++------+------+------+------+------+------+------+------+ +| v1 | v1u | v2 | v2u | v3 | v3u | v4 | v4u | ++------+------+------+------+------+------+------+------+ ++------+------+------+------+ +| v5 | v5u | v6 | v6u | ++------+------+------+------+ ++------+------+------+------+------+------+------+------+------+------+ +| v7 | v8 | v9 | v10 | v11 | v12 | v13 | v14 | v15 | v16 | ++------+------+------+------+------+------+------+------+------+------+ ++-------+-------+-------+-------+ +| v17 | v18 | v19 | v20 | ++-------+-------+-------+-------+ +| 127 | 255 | -128 | 255 | 127 | 255 | -128 | 0 | +| 127 | 255 | -128 | 0 | +| 10 | 10 | 10 | 0 | 0 | 10 | 10 | 10 | 10 | 0 | +| 12.00 | 12.12 | 12.00 | 12.12 | ++------+------+------+------+------+------+------+------+ ++------+------+------+------+ ++------+------+------+------+------+------+------+------+------+------+ ++-------+-------+-------+-------+ + +CALL sp_vars_check_assignment(); ++------+------+------+------+ +| i1 | i2 | i3 | i4 | ++------+------+------+------+ ++------+------+------+------+ +| i1 | i2 | i3 | i4 | ++------+------+------+------+ ++------+------+------+------+ +| u1 | u2 | u3 | u4 | ++------+------+------+------+ ++------+------+------+------+ +| u1 | u2 | u3 | u4 | ++------+------+------+------+ ++---------+---------+---------+ +| d1 | d2 | d3 | ++---------+---------+---------+ ++---------+---------+---------+ +| d1 | d2 | d3 | ++---------+---------+---------+ +| 127 | -128 | 127 | -128 | +| 127 | -128 | 127 | 127 | +| 255 | 255 | 255 | 0 | +| 255 | 0 | 200 | 200 | +| 1234.00 | 1234.12 | 1234.12 | +| 1234.00 | 1234.12 | 1234.12 | ++------+------+------+------+ ++------+------+------+------+ ++------+------+------+------+ ++------+------+------+------+ ++---------+---------+---------+ ++---------+---------+---------+ + +SELECT sp_vars_check_ret1(); ++----------------------+ +| sp_vars_check_ret1() | ++----------------------+ +| 127 | ++----------------------+ + +SELECT sp_vars_check_ret2(); ++----------------------+ +| sp_vars_check_ret2() | ++----------------------+ +| 127 | ++----------------------+ + +SELECT sp_vars_check_ret3(); ++----------------------+ +| sp_vars_check_ret3() | ++----------------------+ +| 0 | ++----------------------+ + +SELECT sp_vars_check_ret4(); ++----------------------+ +| sp_vars_check_ret4() | ++----------------------+ +| 154.12 | ++----------------------+ + +SELECT sp_vars_div_zero(); ++--------------------+ +| sp_vars_div_zero() | ++--------------------+ +| NULL | ++--------------------+ + +## SET @@sql_mode = 'traditional'; +## STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION +## for traditional oceanbase only support STRICT_TRANS_TABLES, STRICT_ALL_TABLES +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + +--------------------------------------------------------------- +Calling in TRADITIONAL mode the routines, created in ANSI mode. +--------------------------------------------------------------- + +CALL sp_vars_check_dflt(); ++------+------+------+------+------+------+------+------+ +| v1 | v1u | v2 | v2u | v3 | v3u | v4 | v4u | ++------+------+------+------+------+------+------+------+ ++------+------+------+------+ +| v5 | v5u | v6 | v6u | ++------+------+------+------+ ++------+------+------+------+------+------+------+------+------+------+ +| v7 | v8 | v9 | v10 | v11 | v12 | v13 | v14 | v15 | v16 | ++------+------+------+------+------+------+------+------+------+------+ ++-------+-------+-------+-------+ +| v17 | v18 | v19 | v20 | ++-------+-------+-------+-------+ +| 127 | 255 | -128 | 255 | 127 | 255 | -128 | 0 | +| 127 | 255 | -128 | 0 | +| 10 | 10 | 10 | 0 | 0 | 10 | 10 | 10 | 10 | 0 | +| 12.00 | 12.12 | 12.00 | 12.12 | ++------+------+------+------+------+------+------+------+ ++------+------+------+------+ ++------+------+------+------+------+------+------+------+------+------+ ++-------+-------+-------+-------+ + +CALL sp_vars_check_assignment(); ++------+------+------+------+ +| i1 | i2 | i3 | i4 | ++------+------+------+------+ ++------+------+------+------+ +| i1 | i2 | i3 | i4 | ++------+------+------+------+ ++------+------+------+------+ +| u1 | u2 | u3 | u4 | ++------+------+------+------+ ++------+------+------+------+ +| u1 | u2 | u3 | u4 | ++------+------+------+------+ ++---------+---------+---------+ +| d1 | d2 | d3 | ++---------+---------+---------+ ++---------+---------+---------+ +| d1 | d2 | d3 | ++---------+---------+---------+ +| 127 | -128 | 127 | -128 | +| 127 | -128 | 127 | 127 | +| 255 | 255 | 255 | 0 | +| 255 | 0 | 200 | 200 | +| 1234.00 | 1234.12 | 1234.12 | +| 1234.00 | 1234.12 | 1234.12 | ++------+------+------+------+ ++------+------+------+------+ ++------+------+------+------+ ++------+------+------+------+ ++---------+---------+---------+ ++---------+---------+---------+ + +SELECT sp_vars_check_ret1(); ++----------------------+ +| sp_vars_check_ret1() | ++----------------------+ +| 127 | ++----------------------+ + +SELECT sp_vars_check_ret2(); ++----------------------+ +| sp_vars_check_ret2() | ++----------------------+ +| 127 | ++----------------------+ + +SELECT sp_vars_check_ret3(); ++----------------------+ +| sp_vars_check_ret3() | ++----------------------+ +| 0 | ++----------------------+ + +SELECT sp_vars_check_ret4(); ++----------------------+ +| sp_vars_check_ret4() | ++----------------------+ +| 154.12 | ++----------------------+ + +SELECT sp_vars_div_zero(); ++--------------------+ +| sp_vars_div_zero() | ++--------------------+ +| NULL | ++--------------------+ + +DROP PROCEDURE sp_vars_check_dflt; +DROP PROCEDURE sp_vars_check_assignment; +DROP FUNCTION sp_vars_check_ret1; +DROP FUNCTION sp_vars_check_ret2; +DROP FUNCTION sp_vars_check_ret3; +DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; + + +CREATE PROCEDURE sp_vars_check_dflt() +BEGIN + DECLARE v1 TINYINT DEFAULT 1e200; + DECLARE v1u TINYINT UNSIGNED DEFAULT 1e200; + DECLARE v2 TINYINT DEFAULT -1e200; + DECLARE v2u TINYINT UNSIGNED DEFAULT -1e200; + DECLARE v3 TINYINT DEFAULT 300; + DECLARE v3u TINYINT UNSIGNED DEFAULT 300; + DECLARE v4 TINYINT DEFAULT -300; + DECLARE v4u TINYINT UNSIGNED DEFAULT -300; + + DECLARE v5 TINYINT DEFAULT 10 * 10 * 10; + DECLARE v5u TINYINT UNSIGNED DEFAULT 10 * 10 * 10; + DECLARE v6 TINYINT DEFAULT -10 * 10 * 10; + DECLARE v6u TINYINT UNSIGNED DEFAULT -10 * 10 * 10; + + DECLARE v7 TINYINT DEFAULT '10'; + DECLARE v8 TINYINT DEFAULT '10 '; + DECLARE v9 TINYINT DEFAULT ' 10 '; + DECLARE v10 TINYINT DEFAULT 'String 10 '; + DECLARE v11 TINYINT DEFAULT 'String10'; + DECLARE v12 TINYINT DEFAULT '10 String'; + DECLARE v13 TINYINT DEFAULT '10String'; + DECLARE v14 TINYINT DEFAULT concat('10', ' '); + DECLARE v15 TINYINT DEFAULT concat(' ', '10'); + DECLARE v16 TINYINT DEFAULT concat('Hello, ', 'world'); + + DECLARE v17 DECIMAL(64, 2) DEFAULT 12; + DECLARE v18 DECIMAL(64, 2) DEFAULT 12.123; + DECLARE v19 DECIMAL(64, 2) DEFAULT 11 + 1; + DECLARE v20 DECIMAL(64, 2) DEFAULT 12 + 0.123; + + SELECT v1, v1u, v2, v2u, v3, v3u, v4, v4u; + SELECT v5, v5u, v6, v6u; + SELECT v7, v8, v9, v10, v11, v12, v13, v14, v15, v16; + SELECT v17, v18, v19, v20; +END| + +CREATE PROCEDURE sp_vars_check_assignment() +BEGIN + DECLARE i1, i2, i3, i4 TINYINT; + DECLARE u1, u2, u3, u4 TINYINT UNSIGNED; + DECLARE d1, d2, d3 DECIMAL(64, 2); + + SET i1 = 1e200; + SET i2 = -1e200; + SET i3 = 300; + SET i4 = -300; + + SELECT i1, i2, i3, i4; + + SET i1 = 10 * 10 * 10; + SET i2 = -10 * 10 * 10; + SET i3 = sign(10 * 10) * 10 * 20; + SET i4 = sign(-10 * 10) * -10 * 20; + + SELECT i1, i2, i3, i4; + + SET u1 = 1e200; + SET u2 = -1e200; + SET u3 = 300; + SET u4 = -300; + + SELECT u1, u2, u3, u4; + + SET u1 = 10 * 10 * 10; + SET u2 = -10 * 10 * 10; + SET u3 = sign(10 * 10) * 10 * 20; + SET u4 = sign(-10 * 10) * -10 * 20; + + SELECT u1, u2, u3, u4; + + SET d1 = 1234; + SET d2 = 1234.12; + SET d3 = 1234.1234; + + SELECT d1, d2, d3; + + SET d1 = 12 * 100 + 34; + SET d2 = 12 * 100 + 34 + 0.12; + SET d3 = 12 * 100 + 34 + 0.1234; + + SELECT d1, d2, d3; +END| + +CREATE FUNCTION sp_vars_check_ret1() RETURNS TINYINT +BEGIN + RETURN 1e200; +END| + +CREATE FUNCTION sp_vars_check_ret2() RETURNS TINYINT +BEGIN + RETURN 10 * 10 * 10; +END| + +CREATE FUNCTION sp_vars_check_ret3() RETURNS TINYINT +BEGIN + RETURN 'Hello, world'; +END| + +CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2) +BEGIN + RETURN 12 * 10 + 34 + 0.1234; +END| + +CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER +BEGIN + DECLARE div_zero INTEGER; + SELECT 1/0 INTO div_zero; + RETURN div_zero; +END| + + + +--------------------------------------------------------------- +Calling the routines, created in TRADITIONAL mode. +--------------------------------------------------------------- + +CALL sp_vars_check_dflt(); +ERROR 22003: Out of range value for column + +CALL sp_vars_check_assignment(); +ERROR 22003: Out of range value for column + +SELECT sp_vars_check_ret1(); +ERROR 22003: Out of range value for column + +SELECT sp_vars_check_ret2(); +ERROR 22003: Out of range value for column + +SELECT sp_vars_check_ret3(); +ERROR HY000: Incorrect integer value + +SELECT sp_vars_check_ret4(); ++----------------------+ +| sp_vars_check_ret4() | ++----------------------+ +| 154.12 | ++----------------------+ + +## --error ER_DIVISION_BY_ZERO +SELECT sp_vars_div_zero(); ++--------------------+ +| sp_vars_div_zero() | ++--------------------+ +| NULL | ++--------------------+ + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP PROCEDURE sp_vars_check_dflt; +DROP PROCEDURE sp_vars_check_assignment; +DROP FUNCTION sp_vars_check_ret1; +DROP FUNCTION sp_vars_check_ret2; +DROP FUNCTION sp_vars_check_ret3; +DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BIT data type tests +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1() +BEGIN + DECLARE v1 BIT; + DECLARE v2 BIT(1); + DECLARE v3 BIT(3) DEFAULT b'101'; + DECLARE v4 BIT(64) DEFAULT 0x5555555555555555; + DECLARE v5 BIT(3); + DECLARE v6 BIT(64); + DECLARE v7 BIT(8) DEFAULT 128; + DECLARE v8 BIT(8) DEFAULT '128'; + DECLARE v9 BIT(8) DEFAULT ' 128'; + DECLARE v10 BIT(8) DEFAULT 'x 128'; + + SET v1 = v4; + SET v2 = 0; + SET v5 = v4; # check overflow + SET v6 = v3; # check padding + + SELECT HEX(v1); + SELECT HEX(v2); + SELECT HEX(v3); + SELECT HEX(v4); + SELECT HEX(v5); + SELECT HEX(v6); + SELECT HEX(v7); + SELECT HEX(v8); + SELECT HEX(v9); + SELECT HEX(v10); +END| + +CALL p1(); ++---------+ +| HEX(v1) | ++---------+ ++---------+ +| HEX(v2) | ++---------+ ++---------+ +| HEX(v3) | ++---------+ ++------------------+ +| HEX(v4) | ++------------------+ ++---------+ +| HEX(v5) | ++---------+ ++---------+ +| HEX(v6) | ++---------+ ++---------+ +| HEX(v7) | ++---------+ ++---------+ +| HEX(v8) | ++---------+ ++---------+ +| HEX(v9) | ++---------+ ++----------+ +| HEX(v10) | ++----------+ +| 1 | +| 0 | +| 5 | +| 5555555555555555 | +| 7 | +| 5 | +| 80 | +| FF | +| FF | +| FF | ++---------+ ++---------+ ++---------+ ++------------------+ ++---------+ ++---------+ ++---------+ ++---------+ ++---------+ ++----------+ + +DROP PROCEDURE p1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +CASE expression tests. +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP TABLE IF EXISTS t1; +## use create time to make the order of log_msg stable +CREATE TABLE t1(ctime int auto_increment, log_msg VARCHAR(1024)); + + +CREATE PROCEDURE p1(arg VARCHAR(255)) +BEGIN + INSERT INTO t1(log_msg) VALUES('p1: step1'); + CASE arg * 10 + WHEN 10 * 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: on 10'); + WHEN 10 * 10 + 10 * 10 THEN + BEGIN + CASE arg / 10 + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: on 1'); + WHEN 2 THEN + BEGIN + DECLARE i TINYINT DEFAULT 10; + + WHILE i > 0 DO + INSERT INTO t1(log_msg) VALUES(CONCAT('p1: case1: case2: loop: i: ', i)); + + CASE MOD(i, 2) + WHEN 0 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: loop: i is even'); + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: loop: i is odd'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: loop: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: ERROR'); + END CASE; + + CASE arg + WHEN 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case3: on 10'); + WHEN 20 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case3: on 20'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: case3: ERROR'); + END CASE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: ERROR'); + END CASE; + + CASE arg * 10 + WHEN 10 * 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: on 10'); + WHEN 10 * 10 + 10 * 10 THEN + BEGIN + CASE arg / 10 + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: on 1'); + WHEN 2 THEN + BEGIN + DECLARE i TINYINT DEFAULT 10; + + WHILE i > 0 DO + INSERT INTO t1(log_msg) VALUES(CONCAT('p1: case4: case5: loop: i: ', i)); + + CASE MOD(i, 2) + WHEN 0 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: loop: i is even'); + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: loop: i is odd'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: loop: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: ERROR'); + END CASE; + + CASE arg + WHEN 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case6: on 10'); + WHEN 20 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case6: on 20'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: case6: ERROR'); + END CASE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: ERROR'); + END CASE; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE i TINYINT DEFAULT 3; + + WHILE i > 0 DO + IF MOD(i, 2) = 0 THEN + SET @_test_session_var = 10; + ELSE + SET @_test_session_var = 'test'; + END IF; + + CASE @_test_session_var + WHEN 10 THEN + INSERT INTO t1(log_msg) VALUES('p2: case: numerical type'); + WHEN 'test' THEN + INSERT INTO t1(log_msg) VALUES('p2: case: string type'); + ELSE + INSERT INTO t1(log_msg) VALUES('p2: case: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; +END| + + +CALL p1(10); +CALL p1(20); + +CALL p2(); + +SELECT ctime, log_msg FROM t1 order by ctime, log_msg; ++-------+-----------------------------------+ +| ctime | log_msg | ++-------+-----------------------------------+ +| 1 | p1: step1 | +| 2 | p1: case1: on 10 | +| 3 | p1: case4: on 10 | +| 4 | p1: step1 | +| 5 | p1: case1: case2: loop: i: 10 | +| 6 | p1: case1: case2: loop: i is even | +| 7 | p1: case1: case2: loop: i: 9 | +| 8 | p1: case1: case2: loop: i is odd | +| 9 | p1: case1: case2: loop: i: 8 | +| 10 | p1: case1: case2: loop: i is even | +| 11 | p1: case1: case2: loop: i: 7 | +| 12 | p1: case1: case2: loop: i is odd | +| 13 | p1: case1: case2: loop: i: 6 | +| 14 | p1: case1: case2: loop: i is even | +| 15 | p1: case1: case2: loop: i: 5 | +| 16 | p1: case1: case2: loop: i is odd | +| 17 | p1: case1: case2: loop: i: 4 | +| 18 | p1: case1: case2: loop: i is even | +| 19 | p1: case1: case2: loop: i: 3 | +| 20 | p1: case1: case2: loop: i is odd | +| 21 | p1: case1: case2: loop: i: 2 | +| 22 | p1: case1: case2: loop: i is even | +| 23 | p1: case1: case2: loop: i: 1 | +| 24 | p1: case1: case2: loop: i is odd | +| 25 | p1: case1: case3: on 20 | +| 26 | p1: case4: case5: loop: i: 10 | +| 27 | p1: case4: case5: loop: i is even | +| 28 | p1: case4: case5: loop: i: 9 | +| 29 | p1: case4: case5: loop: i is odd | +| 30 | p1: case4: case5: loop: i: 8 | +| 31 | p1: case4: case5: loop: i is even | +| 32 | p1: case4: case5: loop: i: 7 | +| 33 | p1: case4: case5: loop: i is odd | +| 34 | p1: case4: case5: loop: i: 6 | +| 35 | p1: case4: case5: loop: i is even | +| 36 | p1: case4: case5: loop: i: 5 | +| 37 | p1: case4: case5: loop: i is odd | +| 38 | p1: case4: case5: loop: i: 4 | +| 39 | p1: case4: case5: loop: i is even | +| 40 | p1: case4: case5: loop: i: 3 | +| 41 | p1: case4: case5: loop: i is odd | +| 42 | p1: case4: case5: loop: i: 2 | +| 43 | p1: case4: case5: loop: i is even | +| 44 | p1: case4: case5: loop: i: 1 | +| 45 | p1: case4: case5: loop: i is odd | +| 46 | p1: case4: case6: on 20 | +| 47 | p2: case: string type | +| 48 | p2: case: numerical type | +| 49 | p2: case: string type | ++-------+-----------------------------------+ + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#14161 +--------------------------------------------------------------- + +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +CREATE TABLE t1(col BIGINT UNSIGNED); + +INSERT INTO t1 VALUE(18446744073709551614); + +CREATE PROCEDURE p1(IN arg BIGINT UNSIGNED) +BEGIN + SELECT arg; + SELECT * FROM t1; + SELECT * FROM t1 WHERE col = arg; +END| + +CALL p1(18446744073709551614); ++----------------------+ +| arg | ++----------------------+ ++----------------------+ +| col | ++----------------------+ ++----------------------+ +| col | ++----------------------+ +| 18446744073709551614 | +| 18446744073709551614 | +| 18446744073709551614 | ++----------------------+ ++----------------------+ ++----------------------+ + +DROP TABLE t1; +DROP PROCEDURE p1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#13705 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1(x VARCHAR(10), y CHAR(3)) READS SQL DATA +BEGIN + SELECT x, y; +END| + +CALL p1('alpha', 'abc'); ++-------+------+ +| x | y | ++-------+------+ +| alpha | abc | ++-------+------+ +CALL p1('alpha', 'abcdef'); ++-------+------+ +| x | y | ++-------+------+ +| alpha | abc | ++-------+------+ + +DROP PROCEDURE p1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#13675 +--------------------------------------------------------------- + +## --disable_warnings +## DROP PROCEDURE IF EXISTS p1; +## DROP TABLE IF EXISTS t1; +## --enable_warnings +## TODO: DDL not support select x with variables +## delimiter |; +## CREATE PROCEDURE p1(x DATETIME) +## BEGIN +## CREATE TABLE t1 AS SELECT x; +## SHOW CREATE TABLE t1; +## DROP TABLE t1; +## END| +## delimiter ;| +## +## CALL p1(NOW()); +## CALL p1('test'); +## DROP PROCEDURE p1; +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#12976 +--------------------------------------------------------------- + +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +CREATE TABLE t1(b BIT(1)); + +INSERT INTO t1(b) VALUES(b'0'), (b'1'); + +CREATE PROCEDURE p1() +BEGIN + SELECT HEX(b), + b = 0, + b = FALSE, + b IS FALSE, + b = 1, + b = TRUE, + b IS TRUE + FROM t1; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE vb BIT(1); + SELECT b FROM t1 WHERE b = 0 INTO vb; + + SELECT HEX(vb), + vb = 0, + vb = FALSE, + vb IS FALSE, + vb = 1, + vb = TRUE, + vb IS TRUE; + + SELECT b FROM t1 WHERE b = 1 INTO vb; + + SELECT HEX(vb), + vb = 0, + vb = FALSE, + vb IS FALSE, + vb = 1, + vb = TRUE, + vb IS TRUE; +END| + +call p1(); ++--------+-------+-----------+------------+-------+----------+-----------+ +| HEX(b) | b = 0 | b = FALSE | b IS FALSE | b = 1 | b = TRUE | b IS TRUE | ++--------+-------+-----------+------------+-------+----------+-----------+ +| 0 | 1 | 1 | 1 | 0 | 0 | 0 | +| 1 | 0 | 0 | 0 | 1 | 1 | 1 | ++--------+-------+-----------+------------+-------+----------+-----------+ +call p2(); ++---------+--------+------------+-------------+--------+-----------+------------+ +| HEX(vb) | vb = 0 | vb = FALSE | vb IS FALSE | vb = 1 | vb = TRUE | vb IS TRUE | ++---------+--------+------------+-------------+--------+-----------+------------+ ++---------+--------+------------+-------------+--------+-----------+------------+ +| HEX(vb) | vb = 0 | vb = FALSE | vb IS FALSE | vb = 1 | vb = TRUE | vb IS TRUE | ++---------+--------+------------+-------------+--------+-----------+------------+ +| 0 | 1 | 1 | 1 | 0 | 0 | 0 | +| 1 | 0 | 0 | 0 | 1 | 1 | 1 | ++---------+--------+------------+-------------+--------+-----------+------------+ ++---------+--------+------------+-------------+--------+-----------+------------+ + +DROP TABLE t1; +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +DROP TABLE IF EXISTS table_12976_a; +DROP TABLE IF EXISTS table_12976_b; +DROP PROCEDURE IF EXISTS proc_12976_a; +DROP PROCEDURE IF EXISTS proc_12976_b; +CREATE TABLE table_12976_a (val bit(1)); + +CREATE TABLE table_12976_b( + appname varchar(15), + emailperm bit not null default 1, + phoneperm bit not null default 0); + +insert into table_12976_b values ('A', b'1', b'1'), ('B', b'0', b'0'); + +CREATE PROCEDURE proc_12976_a() +BEGIN + declare localvar bit(1); + SELECT val FROM table_12976_a INTO localvar; + SELECT coalesce(localvar, 1)+1, coalesce(val, 1)+1 FROM table_12976_a; +END|| + +CREATE PROCEDURE proc_12976_b( + name varchar(15), + out ep bit, + out msg varchar(10)) +BEGIN + SELECT emailperm FROM table_12976_b where (appname = name) INTO ep; + IF ep is true THEN + SET msg = 'True'; + ELSE + SET msg = 'False'; + END IF; +END|| + + +INSERT table_12976_a VALUES (0); +call proc_12976_a(); ++-------------------------+--------------------+ +| coalesce(localvar, 1)+1 | coalesce(val, 1)+1 | ++-------------------------+--------------------+ +| 1 | 1 | ++-------------------------+--------------------+ +UPDATE table_12976_a set val=1; +call proc_12976_a(); ++-------------------------+--------------------+ +| coalesce(localvar, 1)+1 | coalesce(val, 1)+1 | ++-------------------------+--------------------+ +| 1 | 1 | ++-------------------------+--------------------+ +call proc_12976_b('A', @ep, @msg); ++------+------+ +| ep | msg | ++------+------+ +|  | True | ++------+------+ +select HEX(@ep), @msg; ++----------+------+ +| HEX(@ep) | @msg | ++----------+------+ +| 1 | True | ++----------+------+ + +call proc_12976_b('B', @ep, @msg); ++------+-------+ +| ep | msg | ++------+-------+ +| | False | ++------+-------+ +select HEX(@ep), @msg; ++----------+-------+ +| HEX(@ep) | @msg | ++----------+-------+ +| 0 | False | ++----------+-------+ + +DROP TABLE table_12976_a; +DROP TABLE table_12976_b; +DROP PROCEDURE proc_12976_a; +DROP PROCEDURE proc_12976_b; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#9572 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; + +DROP PROCEDURE IF EXISTS p4; +DROP PROCEDURE IF EXISTS p5; +DROP PROCEDURE IF EXISTS p6; +## SET @@sql_mode = 'traditional'; +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + + +CREATE PROCEDURE p1() +BEGIN + DECLARE v TINYINT DEFAULT 1e200; + SELECT v; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE v DECIMAL(5) DEFAULT 1e200; + SELECT v; +END| + +CREATE PROCEDURE p3() +BEGIN + DECLARE v CHAR(5) DEFAULT 'abcdef'; + SELECT v LIKE 'abc___'; +END| + +CREATE PROCEDURE p4(arg VARCHAR(2)) +BEGIN + DECLARE var VARCHAR(1); + SET var := arg; + SELECT arg, var; +END| + +CREATE PROCEDURE p5(arg CHAR(2)) +BEGIN + DECLARE var CHAR(1); + SET var := arg; + SELECT arg, var; +END| + +CREATE PROCEDURE p6(arg DECIMAL(2)) +BEGIN + DECLARE var DECIMAL(1); + SET var := arg; + SELECT arg, var; +END| + + +CALL p1(); +ERROR 22003: Out of range value for column +CALL p2(); +ERROR 22003: Result value was out of range when casting varchar to number +CALL p3(); +ERROR 22001: Data too long for column + +CALL p4('aaa'); +ERROR 22001: Data too long for column +CALL p5('aa'); +ERROR 22001: Data too long for column +CALL p6(10); +ERROR 22003: Out of range value for column + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP PROCEDURE p3; + +DROP PROCEDURE p4; +DROP PROCEDURE p5; +DROP PROCEDURE p6; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#9078 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1 (arg DECIMAL(64,2)) +BEGIN + DECLARE var DECIMAL(64,2); + + SET var = arg; + SELECT var; +END| + +CALL p1(1929); ++---------+ +| var | ++---------+ +| 1929.00 | ++---------+ +CALL p1(1929.00); ++---------+ +| var | ++---------+ +| 1929.00 | ++---------+ +CALL p1(1929.003); ++---------+ +| var | ++---------+ +| 1929.00 | ++---------+ + +DROP PROCEDURE p1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#8768 +--------------------------------------------------------------- + +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT +BEGIN + RETURN arg; +END| + +SELECT f1(-2500); ++-----------+ +| f1(-2500) | ++-----------+ +| 0 | ++-----------+ + +## SET @@sql_mode = 'traditional'; +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(-2500); ++-----------+ +| f1(-2500) | ++-----------+ +| 0 | ++-----------+ + +DROP FUNCTION f1; + +CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT +BEGIN + RETURN arg; +END| + +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(-2500); ++-----------+ +| f1(-2500) | ++-----------+ +| 0 | ++-----------+ + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP FUNCTION f1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#8769 +--------------------------------------------------------------- + +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT +BEGIN + RETURN arg; +END| + +SELECT f1(8388699); ++-------------+ +| f1(8388699) | ++-------------+ +| 8388607 | ++-------------+ + +## SET @@sql_mode = 'traditional'; +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(8388699); ++-------------+ +| f1(8388699) | ++-------------+ +| 8388607 | ++-------------+ + +DROP FUNCTION f1; + +CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT +BEGIN + RETURN arg; +END| + +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(8388699); ++-------------+ +| f1(8388699) | ++-------------+ +| 8388607 | ++-------------+ + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP FUNCTION f1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#8702 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(col VARCHAR(255)); + +INSERT INTO t1(col) VALUES('Hello, world!'); + +CREATE PROCEDURE p1() +BEGIN + DECLARE sp_var INTEGER; + + SELECT col FROM t1 LIMIT 1 INTO sp_var; + SET @user_var = sp_var; + + SELECT sp_var; + SELECT @user_var; +END| + +CALL p1(); ++--------+ +| sp_var | ++--------+ ++-----------+ +| @user_var | ++-----------+ +| 0 | +| 0 | ++--------+ ++-----------+ + +DROP PROCEDURE p1; +DROP TABLE t1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#12903 +--------------------------------------------------------------- + +DROP FUNCTION IF EXISTS f1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(txt VARCHAR(255)); + +CREATE FUNCTION f1(arg VARCHAR(255)) RETURNS VARCHAR(255) +BEGIN + DECLARE v1 VARCHAR(255); + DECLARE v2 VARCHAR(255); + + SET v1 = CONCAT(LOWER(arg), UPPER(arg)); + SET v2 = CONCAT(LOWER(v1), UPPER(v1)); + + INSERT INTO t1 VALUES(v1), (v2); + + RETURN CONCAT(LOWER(arg), UPPER(arg)); +END| + +SELECT f1('_aBcDe_'); ++----------------+ +| f1('_aBcDe_') | ++----------------+ +| _abcde__ABCDE_ | ++----------------+ + +SELECT * FROM t1; ++------------------------------+ +| txt | ++------------------------------+ +| _abcde__ABCDE_ | +| _abcde__abcde__ABCDE__ABCDE_ | ++------------------------------+ + +DROP FUNCTION f1; +DROP TABLE t1; + +########################################################################### +########################################################################### +## --echo +## --echo --------------------------------------------------------------- +## --echo BUG#13808 +## --echo --------------------------------------------------------------- +## --echo +## --disable_warnings +## DROP PROCEDURE IF EXISTS p1; +## DROP PROCEDURE IF EXISTS p2; +## DROP FUNCTION IF EXISTS f1; +## --enable_warnings +## delimiter |; +## +## CREATE PROCEDURE p1(arg ENUM('a', 'b')) +## BEGIN +## SELECT arg; +## END| +## +## CREATE PROCEDURE p2(arg ENUM('a', 'b')) +## BEGIN +## DECLARE var ENUM('c', 'd') DEFAULT arg; +## +## SELECT arg, var; +## END| +## +## CREATE FUNCTION f1(arg ENUM('a', 'b')) RETURNS ENUM('c', 'd') +## BEGIN +## RETURN arg; +## END| +## +## delimiter ;| +## +## CALL p1('c'); +## +## CALL p2('a'); +## +## SELECT f1('a'); +## DROP PROCEDURE p1; +## DROP PROCEDURE p2; +## DROP FUNCTION f1; +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#13909 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; + +CREATE PROCEDURE p1(arg VARCHAR(255)) +BEGIN + SELECT CHARSET(arg); +END| + +CREATE PROCEDURE p2(arg VARCHAR(255) CHARACTER SET UTF8) +BEGIN + SELECT CHARSET(arg); +END| + + +CALL p1('t'); ++--------------+ +| CHARSET(arg) | ++--------------+ +| utf8mb4 | ++--------------+ +CALL p1(_UTF8 't'); ++--------------+ +| CHARSET(arg) | ++--------------+ +| utf8mb4 | ++--------------+ + +CALL p2('t'); ++--------------+ +| CHARSET(arg) | ++--------------+ +| utf8mb4 | ++--------------+ +## CALL p2(_LATIN1 't'); +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#14188 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1(arg1 BINARY(2), arg2 VARBINARY(2)) +BEGIN + DECLARE var1 BINARY(2) DEFAULT 0x41; + DECLARE var2 VARBINARY(2) DEFAULT 0x42; + + SELECT HEX(arg1), HEX(arg2); + SELECT HEX(var1), HEX(var2); +END| + +CALL p1(0x41, 0x42); ++-----------+-----------+ +| HEX(arg1) | HEX(arg2) | ++-----------+-----------+ ++-----------+-----------+ +| HEX(var1) | HEX(var2) | ++-----------+-----------+ +| 4100 | 42 | +| 4100 | 42 | ++-----------+-----------+ ++-----------+-----------+ + +DROP PROCEDURE p1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#15148 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(col1 TINYINT, col2 TINYINT); + +INSERT INTO t1 VALUES(1, 2), (11, 12); + +CREATE PROCEDURE p1(arg TINYINT) +BEGIN + SELECT arg; +END| + +CALL p1((1, 2)); +ERROR 21000: Operand should contain 1 column(s) + +## --error ER_OPERAND_COLUMNS +## oceanbase not support yet +## CALL p1((SELECT * FROM t1 LIMIT 1)); +## --error ER_OPERAND_COLUMNS +## oceanbase not support yet +## CALL p1((SELECT col1, col2 FROM t1 LIMIT 1)); +DROP PROCEDURE p1; +DROP TABLE t1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#13613 +--------------------------------------------------------------- + +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; + +CREATE PROCEDURE p1(x VARCHAR(50)) +BEGIN + SET x = SUBSTRING(x, 1, 3); + SELECT x; +END| + +CREATE FUNCTION f1(x VARCHAR(50)) RETURNS VARCHAR(50) +BEGIN + RETURN SUBSTRING(x, 1, 3); +END| + + +CALL p1('abcdef'); ++------+ +| x | ++------+ +| abc | ++------+ + +SELECT f1('ABCDEF'); ++--------------+ +| f1('ABCDEF') | ++--------------+ +| ABC | ++--------------+ + +DROP PROCEDURE p1; +DROP FUNCTION f1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#13665 +--------------------------------------------------------------- + +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS VARCHAR(20000) +BEGIN + DECLARE var VARCHAR(2000); + + SET var = ''; + SET var = CONCAT(var, 'abc'); + SET var = CONCAT(var, ''); + + RETURN var; +END| + +SELECT f1(); ++------+ +| f1() | ++------+ +| abc | ++------+ + +DROP FUNCTION f1; + +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1() +BEGIN + DECLARE v_char VARCHAR(255); + DECLARE v_text VARCHAR(255) DEFAULT ''; + + SET v_char = 'abc'; + + SET v_text = v_char; + + SET v_char = 'def'; + + SET v_text = concat(v_text, '|', v_char); + + SELECT v_text; +END| + +CALL p1(); ++---------+ +| v_text | ++---------+ +| abc|def | ++---------+ + +DROP PROCEDURE p1; + + +DROP PROCEDURE IF EXISTS bug27415_text_test| +DROP PROCEDURE IF EXISTS bug27415_text_test2| +CREATE PROCEDURE bug27415_text_test(entity_id_str_in VARCHAR(255)) +BEGIN + DECLARE str_remainder VARCHAR(255); + + SET str_remainder = entity_id_str_in; + + select 'before substr', str_remainder; + SET str_remainder = SUBSTRING(str_remainder, 3); + select 'after substr', str_remainder; +END| + +CREATE PROCEDURE bug27415_text_test2(entity_id_str_in VARCHAR(255)) +BEGIN + DECLARE str_remainder VARCHAR(255); + DECLARE str_remainder2 VARCHAR(255); + + SET str_remainder2 = entity_id_str_in; + select 'before substr', str_remainder2; + SET str_remainder = SUBSTRING(str_remainder2, 3); + select 'after substr', str_remainder; +END| + +CALL bug27415_text_test('a,b,c')| ++---------------+---------------+ +| before substr | str_remainder | ++---------------+---------------+ ++--------------+---------------+ +| after substr | str_remainder | ++--------------+---------------+ +| before substr | a,b,c | +| after substr | b,c | ++---------------+---------------+ ++--------------+---------------+ +CALL bug27415_text_test('a,b,c')| ++---------------+---------------+ +| before substr | str_remainder | ++---------------+---------------+ ++--------------+---------------+ +| after substr | str_remainder | ++--------------+---------------+ +| before substr | a,b,c | +| after substr | b,c | ++---------------+---------------+ ++--------------+---------------+ +CALL bug27415_text_test2('a,b,c')| ++---------------+----------------+ +| before substr | str_remainder2 | ++---------------+----------------+ ++--------------+---------------+ +| after substr | str_remainder | ++--------------+---------------+ +| before substr | a,b,c | +| after substr | b,c | ++---------------+----------------+ ++--------------+---------------+ +CALL bug27415_text_test('a,b,c')| ++---------------+---------------+ +| before substr | str_remainder | ++---------------+---------------+ ++--------------+---------------+ +| after substr | str_remainder | ++--------------+---------------+ +| before substr | a,b,c | +| after substr | b,c | ++---------------+---------------+ ++--------------+---------------+ + +DROP PROCEDURE bug27415_text_test| +DROP PROCEDURE bug27415_text_test2| + + +drop function if exists f1; +drop table if exists t1; +create function f1() returns int +begin + if @a=1 then set @b='abc'; + else set @b=1; + end if; + set @a=1; + return 0; +end| + +create table t1 (a int)| +insert into t1 (a) values (1), (2)| + +set @b:='test'| +set @a=0| +select f1(), @b from t1| ++------+------+ +| f1() | @b | ++------+------+ +| 0 | 1 | +| 0 | abc | ++------+------+ + +set @b=1| +set @a=0| +select f1(), @b from t1| ++------+------+ +| f1() | @b | ++------+------+ +| 0 | 1 | +| 0 | 0 | ++------+------+ + + +drop function f1; +drop table t1; + +########################################################################### +########################################################################### + +--------------------------------------------------------------- +BUG#28299 +--------------------------------------------------------------- + +CREATE PROCEDURE ctest() +BEGIN + DECLARE i CHAR(16); + DECLARE j INT; + SET i= 'string'; + SET j= 1 + i; +END| + +CALL ctest(); +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'string' +DROP PROCEDURE ctest; + +CREATE PROCEDURE vctest() +BEGIN + DECLARE i VARCHAR(16); + DECLARE j INT; + SET i= 'string'; + SET j= 1 + i; +END| + +CALL vctest(); +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'string' +DROP PROCEDURE vctest; diff --git a/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp_mysql.result b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp_mysql.result new file mode 100644 index 000000000..891d617aa --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/r/mysql/sp_mysql.result @@ -0,0 +1,7600 @@ +use test; +set sql_mode=default; +drop table if exists t1,t2,t3,t4; +drop view if exists t1,t2,t3,t4; +drop view if exists v1; +drop procedure if exists p1; +drop procedure if exists p2; +drop function if exists f1; +drop function if exists f2; +create table t1 ( +id char(16) not null default '', +data int not null +); +create table t2 ( +s char(16), +i int, +d double +); +drop procedure if exists foo42; +create procedure foo42() +insert into test.t1 values ("foo", 42); +call foo42(); +select * from t1; +id data +foo 42 +delete from t1; +drop procedure foo42; +drop procedure if exists bar; +create procedure bar(x char(16), y int) +insert into test.t1 values (x, y); +call bar("bar", 666); +select * from t1; +id data +bar 666 +delete from t1; +drop procedure if exists empty| +create procedure empty() +begin +end| +call empty()| +drop procedure empty| +drop procedure if exists scope| +create procedure scope(a int, b float) +begin +declare b int; +declare c float; +begin +declare c int; +end; +end| +drop procedure scope| +drop procedure if exists two| +create procedure two(x1 char(16), x2 char(16), y int) +begin +insert into test.t1 values (x1, y); +insert into test.t1 values (x2, y); +end| +call two("one", "two", 3)| +select * from t1| +id data +one 3 +two 3 +delete from t1| +drop procedure two| +drop procedure if exists locset| +create procedure locset(x char(16), y int) +begin +declare z1, z2 int; +set z1 = y; +set z2 = z1+2; +insert into test.t1 values (x, z2); +end| +call locset("locset", 19)| +select * from t1| +id data +locset 21 +delete from t1| +drop procedure locset| +drop procedure if exists setcontext| +create procedure setcontext() +begin +declare data1 int default 2; +insert into t1 (id, data) values ("foo", 1); +replace t1 set data = data1, id = "bar"; +update t1 set id = "kaka", data = 3 where t1.data = data1; +end| +call setcontext()| +select * from t1 order by data| +id data +foo 1 +kaka 3 +delete from t1| +drop procedure setcontext| +create table t3 ( d date, i int, f double, s varchar(32) )| +drop procedure if exists nullset| +create procedure nullset() +begin +declare ld date; +declare li int; +declare lf double; +declare ls varchar(32); +set ld = null, li = null, lf = null, ls = null; +insert into t3 values (ld, li, lf, ls); +insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), +((li is null), 1, "li is null"), +((li = 0), null, "li = 0"), +((lf is null), 1, "lf is null"), +((lf = 0), null, "lf = 0"), +((ls is null), 1, "ls is null"); +end| +call nullset()| +select * from t3| +d i f s +NULL NULL NULL NULL +NULL 1 1 ld is null +NULL 1 1 li is null +NULL NULL NULL li = 0 +NULL 1 1 lf is null +NULL NULL NULL lf = 0 +NULL 1 1 ls is null +drop table t3| +drop procedure nullset| +drop procedure if exists mixset| +create procedure mixset(x char(16), y int) +begin +declare z int; +set @z = y, z = 666, @max_sp_recursion_depth = 100; +insert into test.t1 values (x, z); +end| +call mixset("mixset", 19)| +show variables like 'max_sp_recursion_depth'| +Variable_name Value +max_sp_recursion_depth 0 +select id,data,@z from t1| +id data @z +mixset 666 19 +delete from t1| +set max_sp_recursion_depth = default; +drop procedure mixset| +drop procedure if exists zip| +create procedure zip(x char(16), y int) +begin +declare z int; +call zap(y, z); +call bar(x, z); +end| +drop procedure if exists zap| +create procedure zap(x int, out y int) +begin +declare z int; +set z = x+1, y = z; +end| +call zip("zip", 99)| +select * from t1| +id data +zip 100 +delete from t1| +drop procedure zip| +drop procedure bar| +call zap(7, @zap)| +y +8 +select @zap| +@zap +8 +drop procedure zap| +drop procedure if exists c1| +create procedure c1(x int) +call c2("c", x)| +drop procedure if exists c2| +create procedure c2(s char(16), x int) +call c3(x, s)| +drop procedure if exists c3| +create procedure c3(x int, s char(16)) +call c4("level", x, s)| +drop procedure if exists c4| +create procedure c4(l char(8), x int, s char(16)) +insert into t1 values (concat(l,s), x)| +call c1(42)| +select * from t1| +id data +levelc 42 +delete from t1| +drop procedure c1| +drop procedure c2| +drop procedure c3| +drop procedure c4| +drop procedure if exists iotest| +create procedure iotest(x1 char(16), x2 char(16), y int) +begin +call inc2(x2, y); +insert into test.t1 values (x1, y); +end| +drop procedure if exists inc2| +create procedure inc2(x char(16), y int) +begin +call inc(y); +insert into test.t1 values (x, y); +end| +drop procedure if exists inc| +create procedure inc(inout io int) +set io = io + 1| +call iotest("io1", "io2", 1)| +select * from t1 order by data desc| +id data +io2 2 +io1 1 +delete from t1| +drop procedure iotest| +drop procedure inc2| +drop procedure if exists incr| +create procedure incr(inout x int) +call inc(x)| +select @zap| +@zap +8 +call incr(@zap)| +x +9 +select @zap| +@zap +9 +drop procedure inc| +drop procedure incr| +drop procedure if exists cbv1| +create procedure cbv1() +begin +declare y int default 3; +call cbv2(y+1, y); +insert into test.t1 values ("cbv1", y); +end| +drop procedure if exists cbv2| +create procedure cbv2(y1 int, inout y2 int) +begin +set y2 = 4711; +insert into test.t1 values ("cbv2", y1); +end| +call cbv1()| +select * from t1 order by data| +id data +cbv2 4 +cbv1 4711 +delete from t1| +drop procedure cbv1| +drop procedure cbv2| +insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| +drop procedure if exists sub1| +create procedure sub1(id char(16), x int) +insert into test.t1 values (id, x)| +drop procedure if exists sub2| +create procedure sub2(id char(16)) +begin +declare x int; +set x = (select sum(t.i) from test.t2 t); +insert into test.t1 values (id, x); +end| +drop function if exists sub3| +create function sub3(i int) returns int deterministic +return i+1| +call sub1("sub1a", (select 7))| +call sub1("sub1b", (select max(i) from t2))| +call sub1("sub1c", (select i,d from t2 limit 1))| +ERROR 21000: Operand should contain 1 column(s) +call sub1("sub1d", (select 1 from (select 1) a))| +call sub2("sub2")| +select * from t1 order by id| +id data +sub1a 7 +sub1b 3 +sub1d 1 +sub2 6 +select sub3((select max(i) from t2))| +sub3((select max(i) from t2)) +4 +drop procedure sub1| +drop procedure sub2| +drop function sub3| +delete from t1| +delete from t2| +drop procedure if exists a0| +create procedure a0(x int) +while x do +set x = x-1; +insert into test.t1 values ("a0", x); +end while| +call a0(3)| +select * from t1 order by data desc| +id data +a0 2 +a0 1 +a0 0 +delete from t1| +drop procedure a0| +drop procedure if exists a| +create procedure a(x int) +while x > 0 do +set x = x-1; +insert into test.t1 values ("a", x); +end while| +call a(3)| +select * from t1 order by data desc| +id data +a 2 +a 1 +a 0 +delete from t1| +drop procedure a| +drop procedure if exists b| +create procedure b(x int) +repeat +insert into test.t1 values (repeat("b",3), x); +set x = x-1; +until x = 0 end repeat| +call b(3)| +select * from t1 order by data desc| +id data +bbb 3 +bbb 2 +bbb 1 +delete from t1| +drop procedure b| +drop procedure if exists b2| +create procedure b2(x int) +repeat select 1 into outfile 'b2'; +insert into test.t1 values (repeat("b2",3), x); +set x = x-1; +until x = 0 end repeat| +drop procedure b2| +drop procedure if exists c| +create procedure c(x int) +hmm: while x > 0 do +insert into test.t1 values ("c", x); +set x = x-1; +iterate hmm; +insert into test.t1 values ("x", x); +end while hmm| +call c(3)| +select * from t1 order by data desc| +id data +c 3 +c 2 +c 1 +delete from t1| +drop procedure c| +drop procedure if exists d| +create procedure d(x int) +hmm: while x > 0 do +insert into test.t1 values ("d", x); +set x = x-1; +leave hmm; +insert into test.t1 values ("x", x); +end while| +call d(3)| +select * from t1| +id data +d 3 +delete from t1| +drop procedure d| +drop procedure if exists e| +create procedure e(x int) +foo: loop +if x = 0 then +leave foo; +end if; +insert into test.t1 values ("e", x); +set x = x-1; +end loop foo| +call e(3)| +select * from t1 order by data desc| +id data +e 3 +e 2 +e 1 +delete from t1| +drop procedure e| +drop procedure if exists f| +create procedure f(x int) +if x < 0 then +insert into test.t1 values ("f", 0); +elseif x = 0 then +insert into test.t1 values ("f", 1); +else +insert into test.t1 values ("f", 2); +end if| +call f(-2)| +call f(0)| +call f(4)| +select * from t1 order by data| +id data +f 0 +f 1 +f 2 +delete from t1| +drop procedure f| +drop procedure if exists g| +create procedure g(x int) +case +when x < 0 then +insert into test.t1 values ("g", 0); +when x = 0 then +insert into test.t1 values ("g", 1); +else +insert into test.t1 values ("g", 2); +end case| +call g(-42)| +call g(0)| +call g(1)| +select * from t1 order by data| +id data +g 0 +g 1 +g 2 +delete from t1| +drop procedure g| +drop procedure if exists h| +create procedure h(x int) +case x +when 0 then +insert into test.t1 values ("h0", x); +when 1 then +insert into test.t1 values ("h1", x); +else +insert into test.t1 values ("h?", x); +end case| +call h(0)| +call h(1)| +call h(17)| +select * from t1 order by data| +id data +h0 0 +h1 1 +h? 17 +delete from t1| +drop procedure h| +drop procedure if exists i| +create procedure i(x int) +foo: +begin +if x = 0 then +leave foo; +end if; +insert into test.t1 values ("i", x); +end foo| +call i(0)| +call i(3)| +select * from t1| +id data +i 3 +delete from t1| +drop procedure i| +insert into t1 values ("foo", 3), ("bar", 19)| +insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| +drop procedure if exists sel1| +create procedure sel1() +begin +select * from t1 order by data; +end| +call sel1()| +id data +foo 3 +bar 19 +drop procedure sel1| +drop procedure if exists sel2| +create procedure sel2() +begin +select * from t1 order by data; +select * from t2 order by s; +end| +call sel2()| +id data +s i d +foo 3 +bar 19 +x 9 4.1 +y -1 19.2 +z 3 2.2 +drop procedure sel2| +delete from t1| +delete from t2| +drop procedure if exists into_test| +create procedure into_test(x char(16), y int) +begin +insert into test.t1 values (x, y); +select id,data from test.t1 limit 1 into x,y; +insert into test.t1 values (concat(x, "2"), y+2); +end| +call into_test("into", 100)| +select * from t1 order by data| +id data +into 100 +into2 102 +delete from t1| +drop procedure into_test| +drop procedure if exists into_tes2| +create procedure into_test2(x char(16), y int) +begin +insert into test.t1 values (x, y); +select id,data from test.t1 limit 1 into x,@z; +insert into test.t1 values (concat(x, "2"), y+2); +end| +call into_test2("into", 100)| +select id,data,@z from t1 order by data| +id data @z +into 100 100 +into2 102 100 +delete from t1| +drop procedure into_test2| +drop procedure if exists into_test3| +create procedure into_test3() +begin +declare x char(16); +declare y int; +select * from test.t1 limit 1 into x,y; +insert into test.t2 values (x, y, 0.0); +end| +insert into t1 values ("into3", 19)| +call into_test3()| +call into_test3()| +select * from t2| +s i d +into3 19 0 +into3 19 0 +delete from t1| +delete from t2| +drop procedure into_test3| +drop procedure if exists into_test4| +create procedure into_test4() +begin +declare x int; +select data from test.t1 limit 1 into x; +insert into test.t3 values ("into4", x); +end| +delete from t1| +create table t3 ( s char(16), d int)| +call into_test4()| +select * from t3| +s d +into4 NULL +insert into t1 values ("i4", 77)| +call into_test4()| +select * from t3| +s d +into4 NULL +into4 77 +delete from t1| +drop table t3| +drop procedure into_test4| +drop procedure if exists into_outfile| +create procedure into_outfile(x char(16), y int) +begin +insert into test.t1 values (x, y); +select * from test.t1 into outfile "spout"; +insert into test.t1 values (concat(x, "2"), y+2); +end| +delete from t1| +drop procedure into_outfile| +drop procedure if exists into_dumpfile| +create procedure into_dumpfile(x char(16), y int) +begin +insert into test.t1 values (x, y); +select * into dumpfile "spdump" from test.t1 limit 1; +insert into test.t1 values (concat(x, "2"), y+2); +end| +delete from t1| +drop procedure into_dumpfile| +drop procedure if exists create_select| +create procedure create_select(x char(16), y int) +begin +insert into test.t1 values (x, y); +create temporary table test.t3 select * from test.t1; +insert into test.t3 values (concat(x, "2"), y+2); +end| +call create_select("cs", 90)| +select * from t1, t3| +id data id data +cs 90 cs 90 +cs 90 cs2 92 +drop table t3| +delete from t1| +drop procedure create_select| +drop function if exists e| +create function e() returns double +return 2.7182818284590452354| +set @e = e()| +select e(), @e| +e() @e +2.718281828459045 2.718281828459045 +drop function if exists inc| +create function inc(i int) returns int +return i+1| +select inc(1), inc(99), inc(-71)| +inc(1) inc(99) inc(-71) +2 100 -70 +drop function if exists mul| +create function mul(x int, y int) returns int +return x*y| +select mul(1,1), mul(3,5), mul(4711, 666)| +mul(1,1) mul(3,5) mul(4711, 666) +1 15 3137526 +drop function if exists append| +create function append(s1 char(8), s2 char(8)) returns char(16) +return concat(s1, s2)| +select append("foo", "bar")| +append("foo", "bar") +foobar +drop function if exists fac| +create function fac(n int unsigned) returns bigint unsigned +begin +declare f bigint unsigned default 1; +while n > 1 do +set f = f * n; +set n = n - 1; +end while; +return f; +end| +select fac(1), fac(2), fac(5), fac(10)| +fac(1) fac(2) fac(5) fac(10) +1 2 120 3628800 +drop function if exists fun| +create function fun(d double, i int, u int unsigned) returns double +return mul(inc(i), fac(u)) / e()| +select fun(2.3, 3, 5)| +fun(2.3, 3, 5) +176.58213176229233 +insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| +insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| +select * from t2 where s = append("a", "b")| +s i d +ab 24 1324.3659882171924 +select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2) order by i| +s i d +xxxyyy 12 2.718281828459045 +ab 24 1324.3659882171924 +select * from t2 where d = e()| +s i d +xxxyyy 12 2.718281828459045 +select * from t2 order by i| +s i d +xxxyyy 12 2.718281828459045 +ab 24 1324.3659882171924 +delete from t2| +drop function e| +drop function inc| +drop function mul| +drop function append| +drop function fun| +drop procedure if exists hndlr1| +create procedure hndlr1(val int) +begin +declare x int default 0; +declare foo condition for 1136; +declare bar condition for sqlstate '42S98'; # Just for testing syntax +declare zip condition for sqlstate value '42S99'; # Just for testing syntax +declare continue handler for foo set x = 1; +insert into test.t1 values ("hndlr1", val, 2); # Too many values +if (x) then +insert into test.t1 values ("hndlr1", val); # This instead then +end if; +end| +call hndlr1(42)| +select * from t1| +id data +hndlr1 42 +delete from t1| +drop procedure hndlr1| +drop procedure if exists hndlr2| +create procedure hndlr2(val int) +begin +declare x int default 0; +begin +declare exit handler for sqlstate '21S01' set x = 1; +insert into test.t1 values ("hndlr2", val, 2); # Too many values +end; +insert into test.t1 values ("hndlr2", x); +end| +call hndlr2(42)| +select * from t1| +id data +hndlr2 1 +delete from t1| +drop procedure hndlr2| +drop procedure if exists hndlr3| +create procedure hndlr3(val int) +begin +declare x int default 0; +declare continue handler for sqlexception # Any error +begin +declare z int; +set z = 2 * val; +set x = 1; +end; +if val < 10 then +begin +declare y int; +set y = val + 10; +insert into test.t1 values ("hndlr3", y, 2); # Too many values +if x then +insert into test.t1 values ("hndlr3", y); +end if; +end; +end if; +end| +call hndlr3(3)| +select * from t1| +id data +hndlr3 13 +delete from t1| +drop procedure hndlr3| +create table t3 ( id char(16), data int )| +drop procedure if exists hndlr4| +create procedure hndlr4() +begin +declare x int default 0; +declare val int; # No default +declare continue handler for sqlstate '02000' set x=1; +select data from test.t3 where id='z' limit 1 into val; # No hits +insert into test.t3 values ('z', val); +end| +call hndlr4()| +select * from t3| +id data +z NULL +drop table t3| +drop procedure hndlr4| +drop procedure if exists cur1| +create procedure cur1() +begin +declare a char(16); +declare b int; +declare c double; +declare done int default 0; +declare c cursor for select * from test.t2; +declare continue handler for sqlstate '02000' set done = 1; +open c; +repeat +fetch c into a, b, c; +if not done then +insert into test.t1 values (a, b+c); +end if; +until done end repeat; +close c; +end| +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| +call cur1()| +select * from t1| +id data +foo 40 +bar 15 +zap 663 +drop procedure cur1| +create table t3 ( s char(16), i int )| +drop procedure if exists cur2| +create procedure cur2() +begin +declare done int default 0; +declare c1 cursor for select id,data from test.t1 order by id,data; +declare c2 cursor for select i from test.t2 order by i; +declare continue handler for sqlstate '02000' set done = 1; +open c1; +open c2; +repeat +begin +declare a char(16); +declare b,c int; +fetch from c1 into a, b; +fetch next from c2 into c; +if not done then +if b < c then +insert into test.t3 values (a, b); +else +insert into test.t3 values (a, c); +end if; +end if; +end; +until done end repeat; +close c1; +close c2; +end| +call cur2()| +select * from t3 order by i,s| +s i +bar 3 +foo 40 +zap 663 +delete from t1| +delete from t2| +drop table t3| +drop procedure cur2| +set @old_mode=@@sql_mode| +set @@sql_mode=STRICT_ALL_TABLES| +drop procedure if exists chistics| +create procedure chistics() +language sql +modifies sql data +not deterministic +sql security definer +comment 'Characteristics procedure test' + insert into t1 values ("chistics", 1)| +show create procedure chistics| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +chistics STRICT_ALL_TABLES CREATE DEFINER = admin@% PROCEDURE `test`.`chistics` +() +COMMENT `Characteristics procedure test` + insert into t1 values ("chistics", 1) utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call chistics()| +select * from t1| +id data +chistics 1 +delete from t1| +alter procedure chistics sql security invoker| +show create procedure chistics| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +chistics STRICT_ALL_TABLES CREATE DEFINER = admin@% PROCEDURE `test`.`chistics` +() +COMMENT `Characteristics procedure test` + insert into t1 values ("chistics", 1) utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure chistics| +drop function if exists chistics| +create function chistics() returns int +language sql +deterministic +sql security invoker +comment 'Characteristics procedure test' + return 42| +show create function chistics| +Function sql_mode Create Function character_set_client collation_connection Database Collation +chistics STRICT_ALL_TABLES CREATE DEFINER = admin@% FUNCTION `test`.`chistics` +() + RETURNS int(11) +DETERMINISTIC +COMMENT `Characteristics procedure test` + return 42 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +select chistics()| +chistics() +42 +alter function chistics +no sql +comment 'Characteristics function test'| +show create function chistics| +Function sql_mode Create Function character_set_client collation_connection Database Collation +chistics STRICT_ALL_TABLES CREATE DEFINER = admin@% FUNCTION `test`.`chistics` +() + RETURNS int(11) +DETERMINISTIC +COMMENT `Characteristics procedure test` + return 42 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop function chistics| +set @@sql_mode=@old_mode| +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| +set @@sql_mode = 'ANSI'| +ERROR 0A000: Not supported feature or function +drop procedure if exists modes$ +create procedure modes(out c1 int, out c2 int) +begin +declare done int default 0; +declare x int; +declare c cursor for select data from t1; +declare continue handler for sqlstate '02000' set done = 1; +select 1 || 2 into c1; +set c2 = 0; +open c; +repeat +fetch c into x; +if not done then +set c2 = c2 + 1; +end if; +until done end repeat; +close c; +end$ +set @@sql_mode = ''| +set sql_select_limit = 1| +call modes(@c1, @c2)| +c1 c2 +1 3 +set sql_select_limit = default| +select @c1, @c2| +@c1 @c2 +1 3 +delete from t1| +drop procedure modes| +create database sp_db1| +drop database sp_db1| +create database sp_db2| +use sp_db2| +create table t3 ( s char(4), t int )| +insert into t3 values ("abcd", 42), ("dcba", 666)| +use test| +drop database sp_db2| +create database sp_db3| +use sp_db3| +drop procedure if exists dummy| +create procedure dummy(out x int) +set x = 42| +use test| +drop database sp_db3| +select type,db,name from mysql.proc where db = 'sp_db3'| +type db name +drop procedure if exists rc| +create procedure rc() +begin +delete from t1; +insert into t1 values ("a", 1), ("b", 2), ("c", 3); +end| +call rc()| +select row_count()| +row_count() +3 +update t1 set data=42 where id = "b"; +select row_count()| +row_count() +1 +delete from t1| +select row_count()| +row_count() +3 +delete from t1| +select row_count()| +row_count() +0 +select * from t1| +id data +select row_count()| +row_count() +-1 +drop procedure rc| +drop function if exists f0| +drop function if exists f1| +drop function if exists f2| +drop function if exists f3| +drop function if exists f4| +drop function if exists f5| +drop function if exists f6| +drop function if exists f7| +drop function if exists f8| +drop function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| +drop view if exists v0| +drop view if exists v1| +drop view if exists v2| +delete from t1| +delete from t2| +insert into t1 values ("a", 1), ("b", 2) | +insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | +create function f1() returns int +return (select sum(data) from t1)| +select f1()| +f1() +3 +select id, f1() from t1 order by id| +id f1() +a 3 +b 3 +create function f2() returns int +return (select data from t1 where data <= (select sum(data) from t1) order by data limit 1)| +select f2()| +f2() +1 +select id, f2() from t1 order by id| +id f2() +a 1 +b 1 +create function f3() returns int +begin +declare n int; +declare m int; +set n:= (select min(data) from t1); +set m:= (select max(data) from t1); +return n < m; +end| +select f3()| +f3() +1 +select id, f3() from t1 order by id| +id f3() +a 1 +b 1 +select f1(), f3()| +f1() f3() +3 1 +select id, f1(), f3() from t1 order by id| +id f1() f3() +a 3 1 +b 3 1 +create function f4() returns double +return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| +select f4()| +f4() +2 +select s, f4() from t2 order by s| +s f4() +a 2 +b 2 +c 2 +create function f5(i int) returns int +begin +if i <= 0 then +return 0; +elseif i = 1 then +return (select count(*) from t1 where data = i); +else +return (select count(*) + f5( i - 1) from t1 where data = i); +end if; +end| +select f5(1)| +f5(1) +1 +select f5(2)| +ERROR HY000: Recursive stored functions are not allowed. +select f5(3)| +ERROR HY000: Recursive stored functions are not allowed. +create function f6() returns int +begin +declare n int; +set n:= f1(); +return (select count(*) from t1 where data <= f7() and data <= n); +end| +create function f7() returns int +return (select sum(data) from t1 where data <= f1())| +select f6()| +f6() +2 +select id, f6() from t1 order by id| +id f6() +a 2 +b 2 +create view v1 (a) as select f1()| +select * from v1| +a +3 +select id, a from t1, v1 order by id| +id a +a 3 +b 3 +select * from v1, v1 as v| +a a +3 3 +create view v2 (a) as select a*10 from v1| +select * from v2| +a +30 +select id, a from t1, v2 order by id| +id a +a 30 +b 30 +select * from v1, v2| +a a +3 30 +create function f8 () returns int +return (select count(*) from v2)| +select *, f8() from v1| +a f8() +3 1 +drop function f1| +select * from v1| +ERROR 42000: FUNCTION f1 does not exist +create function f1() returns int +return (select sum(data) from t1) + (select sum(data) from v1)| +select f1()| +ERROR 42S22: Unknown column 'data' in 'field list' +select * from v1| +ERROR 42S22: Unknown column 'data' in 'field list' +select * from v2| +ERROR 42S22: Unknown column 'data' in 'field list' +drop function f1| +create function f1() returns int +return (select sum(data) from t1)| +create function f0() returns int +return (select * from (select 100) as r)| +select f0()| +f0() +100 +select *, f0() from (select 1) as t| +1 f0() +1 100 +create view v0 as select f0()| +select * from v0| +f0() +100 +select *, f0() from v0| +f0() f0() +100 100 +lock tables t1 read, t1 as t11 read| +select f3()| +f3() +1 +select id, f3() from t1 as t11 order by id| +id f3() +a 1 +b 1 +select f0()| +f0() +100 +select * from v0| +f0() +100 +select *, f0() from v0, (select 123) as d1| +f0() 123 f0() +100 123 100 +select id, f3() from t1| +id f3() +a 1 +b 1 +select f4()| +f4() +2 +unlock tables| +lock tables v2 read, mysql.proc read| +select * from v2| +a +30 +select * from v1| +a +3 +select f4()| +f4() +2 +unlock tables| +create function f9() returns int +begin +declare a, b int; +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +set a:= (select count(*) from t3); +set b:= (select count(*) from t3 t3_alias); +return a + b; +end| +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. +select f9()| +ERROR 42000: FUNCTION f9 does not exist +select f9() from t1 limit 1| +ERROR 42000: FUNCTION f9 does not exist +create function f10() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 select id from t4; +return (select count(*) from t3); +end| +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. +select f10()| +ERROR 42000: FUNCTION f10 does not exist +create table t4 as select 1 as id| +select f10()| +ERROR 42000: FUNCTION f10 does not exist +create function f11() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +return (select count(*) from t3 as a, t3 as b); +end| +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. +select f11()| +ERROR 42000: FUNCTION f11 does not exist +select f11() from t1| +ERROR 42000: FUNCTION f11 does not exist +create function f12_1() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +return f12_2(); +end| +ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. +create function f12_2() returns int +return (select count(*) from t3)| +drop temporary table t3| +ERROR 42S02: Unknown table 'test.t3' +select f12_1()| +ERROR 42000: FUNCTION f12_1 does not exist +select f12_1() from t1 limit 1| +ERROR 42000: FUNCTION f12_1 does not exist +drop function f0| +drop function f1| +drop function f2| +drop function f3| +drop function f4| +drop function f5| +drop function f6| +drop function f7| +drop function f8| +drop function f9| +ERROR 42000: FUNCTION test.f9 does not exist +drop function f10| +ERROR 42000: FUNCTION test.f10 does not exist +drop function f11| +ERROR 42000: FUNCTION test.f11 does not exist +drop function f12_1| +ERROR 42000: FUNCTION test.f12_1 does not exist +drop function f12_2| +drop view v0| +drop view v1| +drop view v2| +truncate table t1 | +truncate table t2 | +drop table t4| +drop table if exists t3| +create table t3 (n int unsigned not null primary key, f bigint unsigned)| +drop procedure if exists ifac| +create procedure ifac(n int unsigned) +begin +declare i int unsigned default 1; +if n > 20 then +set n = 20; # bigint overflow otherwise +end if; +while i <= n do +begin +insert into test.t3 values (i, fac(i)); +set i = i + 1; +end; +end while; +end| +call ifac(20)| +select * from t3| +n f +1 1 +2 2 +3 6 +4 24 +5 120 +6 720 +7 5040 +8 40320 +9 362880 +10 3628800 +11 39916800 +12 479001600 +13 6227020800 +14 87178291200 +15 1307674368000 +16 20922789888000 +17 355687428096000 +18 6402373705728000 +19 121645100408832000 +20 2432902008176640000 +drop table t3| +show function status like '%f%'| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +test fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure ifac| +drop function fac| +show function status like '%f%'| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +drop table if exists t3| +create table t3 ( +i int unsigned not null primary key, +p bigint unsigned not null +)| +insert into t3 values +( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), +( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), +(10, 37), (11, 41), (12, 43), (13, 47), (14, 53), +(15, 59), (16, 61), (17, 67), (18, 71), (19, 73), +(20, 79), (21, 83), (22, 89), (23, 97), (24, 101), +(25, 103), (26, 107), (27, 109), (28, 113), (29, 127), +(30, 131), (31, 137), (32, 139), (33, 149), (34, 151), +(35, 157), (36, 163), (37, 167), (38, 173), (39, 179), +(40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| +drop procedure if exists opp| +create procedure opp(n bigint unsigned, out pp bool) +begin +declare r double; +declare b, s bigint unsigned default 0; +set r = sqrt(n); +again: +loop +if s = 45 then +set b = b+200, s = 0; +else +begin +declare p bigint unsigned; +select t.p from test.t3 t where t.i = s into p; +if b+p > r then +set pp = 1; +leave again; +end if; +if mod(n, b+p) = 0 then +set pp = 0; +leave again; +end if; +set s = s+1; +end; +end if; +end loop; +end| +drop procedure if exists ip| +create procedure ip(m int unsigned) +begin +declare p bigint unsigned; +declare i int unsigned; +set i=45, p=201; +while i < m do +begin +declare pp bool default 0; +call opp(p, pp); +if pp then +insert into test.t3 values (i, p); +set i = i+1; +end if; +set p = p+2; +end; +end while; +end| +show create procedure opp| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +opp CREATE DEFINER = admin@% PROCEDURE `test`.`opp` +( + IN `n` bigint(20) unsigned, OUT `pp` tinyint(1) +) begin +declare r double; +declare b, s bigint unsigned default 0; +set r = sqrt(n); +again: +loop +if s = 45 then +set b = b+200, s = 0; +else +begin +declare p bigint unsigned; +select t.p from test.t3 t where t.i = s into p; +if b+p > r then +set pp = 1; +leave again; +end if; +if mod(n, b+p) = 0 then +set pp = 0; +leave again; +end if; +set s = s+1; +end; +end if; +end loop; +end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +show procedure status where (name = 'opp' or name = 'ip') and db='test'| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +test ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +test opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call ip(200)| +select * from t3 where i=45 or i=100 or i=199| +i p +45 211 +100 557 +199 1229 +drop table t3| +drop procedure opp| +drop procedure ip| +show procedure status where (name = 'opp' or name = 'ip') and db='test'| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +drop procedure if exists bar| +create procedure bar(x char(16), y int) +comment "111111111111" sql security invoker +insert into test.t1 values (x, y)| +show procedure status like 'bar'| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 111111111111 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +alter procedure bar comment "2222222222" sql security definer| +alter procedure bar comment "3333333333"| +alter procedure bar| +show create procedure bar| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bar CREATE DEFINER = admin@% PROCEDURE `test`.`bar` +( + IN `x` char(16), IN `y` int(11) +)COMMENT `111111111111` + insert into test.t1 values (x, y) utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +show procedure status like 'bar'| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +test bar PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER 111111111111 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure bar| +drop procedure if exists p1| +create procedure p1 () +select (select s1 from t3) from t3| +create table t3 (s1 int)| +call p1()| +(select s1 from t3) +insert into t3 values (1)| +call p1()| +(select s1 from t3) +1 +drop procedure p1| +drop table t3| +drop function if exists foo| +create function `foo` () returns int +return 5| +select `foo` ()| +`foo` () +5 +drop function `foo`| +drop function if exists t1max| +create function t1max() returns int +begin +declare x int; +select max(data) from t1 into x; +return x; +end| +insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| +select t1max()| +t1max() +5 +drop function t1max| +create table t3 ( +v char(16) not null primary key, +c int unsigned not null +)| +drop function if exists getcount;| +create function getcount(s char(16)) returns int +begin +declare x int; +select count(*) from t3 where v = s into x; +if x = 0 then +insert into t3 values (s, 1); +else +update t3 set c = c+1 where v = s; +end if; +return x; +end| +select * from t1 where data = getcount("bar")| +id data +zap 1 +select * from t3| +v c +bar 4 +select getcount("zip")| +getcount("zip") +0 +select getcount("zip")| +getcount("zip") +1 +select * from t3| +v c +bar 4 +zip 2 +select getcount(id) from t1 where data = 3| +getcount(id) +0 +select getcount(id) from t1 where data = 5| +getcount(id) +1 +select * from t3| +v c +bar 4 +foo 1 +zip 3 +drop table t3| +drop function getcount| +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +create table t3 (a smallint primary key)| +insert into t3 (a) values (1)| +create procedure h_ee() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (bad)' as 'h_ee'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_ee'; +insert into t3 values (1); +end; +end| +create procedure h_es() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (bad)' as 'h_es'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_es'; +insert into t3 values (1); +end; +end| +create procedure h_en() +deterministic +begin +declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA +select 'Outer (bad)' as 'h_en'; +begin +declare x int; +declare continue handler for sqlstate '02000' -- no data +select 'Inner (good)' as 'h_en'; +select a from t3 where a = 42 into x; +end; +end| +create procedure h_ew() +deterministic +begin +declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE +select 'Outer (bad)' as 'h_ew'; +begin +declare continue handler for sqlwarning +select 'Inner (good)' as 'h_ew'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ex() +deterministic +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Outer (bad)' as 'h_ex'; +begin +declare continue handler for sqlexception +select 'Inner (good)' as 'h_ex'; +insert into t3 values (1); +end; +end| +create procedure h_se() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_se'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_se'; +insert into t3 values (1); +end; +end| +create procedure h_ss() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_ss'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Inner (good)' as 'h_ss'; +insert into t3 values (1); +end; +end| +create procedure h_sn() +deterministic +begin +-- Note: '02000' is more specific than NOT FOUND ; +-- there might be other not found states +declare continue handler for sqlstate '02000' -- no data +select 'Outer (bad)' as 'h_sn'; +begin +declare x int; +declare continue handler for not found +select 'Inner (good)' as 'h_sn'; +select a from t3 where a = 42 into x; +end; +end| +create procedure h_sw() +deterministic +begin +-- data exception - numeric value out of range +declare continue handler for sqlstate '22003' + select 'Outer (bad)' as 'h_sw'; +begin +declare continue handler for sqlwarning +select 'Inner (good)' as 'h_sw'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_sx() +deterministic +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' +select 'Outer (bad)' as 'h_sx'; +begin +declare continue handler for sqlexception +select 'Inner (good)' as 'h_sx'; +insert into t3 values (1); +end; +end| +create procedure h_ne() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_ne'; +begin +declare x int; +declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA +select 'Inner (good)' as 'h_ne'; +select a from t3 where a = 42 into x; +end; +end| +create procedure h_ns() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_ns'; +begin +declare x int; +declare continue handler for sqlstate '02000' -- no data +select 'Inner (good)' as 'h_ns'; +select a from t3 where a = 42 into x; +end; +end| +create procedure h_nn() +deterministic +begin +declare continue handler for not found +select 'Outer (bad)' as 'h_nn'; +begin +declare x int; +declare continue handler for not found +select 'Inner (good)' as 'h_nn'; +select a from t3 where a = 42 into x; +end; +end| +create procedure h_we() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_we'; +begin +declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE +select 'Inner (good)' as 'h_we'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ws() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_ws'; +begin +-- data exception - numeric value out of range +declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_ww() +deterministic +begin +declare continue handler for sqlwarning +select 'Outer (bad)' as 'h_ww'; +begin +declare continue handler for sqlwarning +select 'Inner (good)' as 'h_ww'; +insert into t3 values (123456789012); +end; +delete from t3; +insert into t3 values (1); +end| +create procedure h_xe() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xe'; +begin +declare continue handler for 1062 -- ER_DUP_ENTRY +select 'Inner (good)' as 'h_xe'; +insert into t3 values (1); +end; +end| +create procedure h_xs() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xs'; +begin +-- integrity constraint violation +declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; +insert into t3 values (1); +end; +end| +create procedure h_xx() +deterministic +begin +declare continue handler for sqlexception +select 'Outer (bad)' as 'h_xx'; +begin +declare continue handler for sqlexception +select 'Inner (good)' as 'h_xx'; +insert into t3 values (1); +end; +end| +call h_ee()| +h_ee +Inner (good) +call h_es()| +h_es +Inner (good) +call h_en()| +h_en +Inner (good) +call h_ew()| +call h_ex()| +h_ex +Inner (good) +call h_se()| +h_se +Inner (good) +call h_ss()| +h_ss +Inner (good) +call h_sn()| +h_sn +Inner (good) +call h_sw()| +call h_sx()| +h_sx +Inner (good) +call h_ne()| +h_ne +Inner (good) +call h_ns()| +h_ns +Inner (good) +call h_nn()| +h_nn +Inner (good) +call h_we()| +call h_ws()| +call h_ww()| +call h_xe()| +h_xe +Inner (good) +call h_xs()| +h_xs +Inner (good) +call h_xx()| +h_xx +Inner (good) +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| +drop procedure if exists bug822| +create procedure bug822(a_id char(16), a_data int) +begin +declare n int; +select count(*) from t1 where id = a_id and data = a_data into n; +if n = 0 then +insert into t1 (id, data) values (a_id, a_data); +end if; +end| +delete from t1| +call bug822('foo', 42)| +call bug822('foo', 42)| +call bug822('bar', 666)| +select * from t1 order by data| +id data +foo 42 +bar 666 +delete from t1| +drop procedure bug822| +drop procedure if exists bug1495| +create procedure bug1495() +begin +declare x int; +select data from t1 order by id limit 1 into x; +if x > 10 then +insert into t1 values ("less", x-10); +else +insert into t1 values ("more", x+10); +end if; +end| +insert into t1 values ('foo', 12)| +call bug1495()| +delete from t1 where id='foo'| +insert into t1 values ('bar', 7)| +call bug1495()| +delete from t1 where id='bar'| +select * from t1 order by data| +id data +less 2 +more 17 +delete from t1| +drop procedure bug1495| +drop procedure if exists bug1547| +create procedure bug1547(s char(16)) +begin +declare x int; +select data from t1 where s = id limit 1 into x; +if x > 10 then +insert into t1 values ("less", x-10); +else +insert into t1 values ("more", x+10); +end if; +end| +insert into t1 values ("foo", 12), ("bar", 7)| +call bug1547("foo")| +call bug1547("bar")| +select * from t1 order by id| +id data +bar 7 +foo 12 +less 2 +more 17 +delete from t1| +drop procedure bug1547| +drop table if exists t70| +create table t70 (s1 int,s2 int)| +insert into t70 values (1,2)| +drop procedure if exists bug1656| +create procedure bug1656(out p1 int, out p2 int) +select * from t70 into p1, p1| +call bug1656(@1, @2)| +p1 p2 +2 NULL +select @1, @2| +@1 @2 +2 NULL +drop table t70| +drop procedure bug1656| +create table t3(a int)| +drop procedure if exists bug1862| +create procedure bug1862() +begin +insert into t3 values(2); +flush tables; +end| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'flush tables' at line 4 +call bug1862()| +ERROR 42000: procedure test.bug1862 does not exist +call bug1862()| +ERROR 42000: procedure test.bug1862 does not exist +select * from t3| +a +drop table t3| +drop procedure bug1862| +ERROR 42000: PROCEDURE test.bug1862 does not exist +drop procedure if exists bug1874| +create procedure bug1874() +begin +declare x int; +declare y double; +select max(data) from t1 into x; +insert into t2 values ("max", x, 0); +select min(data) from t1 into x; +insert into t2 values ("min", x, 0); +select sum(data) from t1 into x; +insert into t2 values ("sum", x, 0); +select avg(data) from t1 into y; +insert into t2 values ("avg", 0, y); +end| +insert into t1 (data) values (3), (1), (5), (9), (4)| +call bug1874()| +select * from t2 order by i| +s i d +avg 0 4.4 +min 1 0 +max 9 0 +sum 22 0 +delete from t1| +delete from t2| +drop procedure bug1874| +drop procedure if exists bug2260| +create procedure bug2260() +begin +declare v1 int; +declare c1 cursor for select data from t1; +declare continue handler for not found set @x2 = 1; +open c1; +fetch c1 into v1; +set @x2 = 2; +close c1; +end| +call bug2260()| +select @x2| +@x2 +2 +drop procedure bug2260| +drop procedure if exists bug2267_1| +create procedure bug2267_1() +begin +show procedure status where db='test'; +end| +drop procedure if exists bug2267_2| +create procedure bug2267_2() +begin +show function status where db='test'; +end| +drop procedure if exists bug2267_3| +create procedure bug2267_3() +begin +show create procedure bug2267_1; +end| +drop procedure if exists bug2267_4| +drop function if exists bug2267_4| +create procedure bug2267_4() +begin +show create function bug2267_4; +end| +create function bug2267_4() returns int return 100| +call bug2267_1()| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +test bug2267_1 PROCEDURE 'admin'@'%' 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +test bug2267_2 PROCEDURE 'admin'@'%' 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +test bug2267_3 PROCEDURE 'admin'@'%' 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +test bug2267_4 PROCEDURE 'admin'@'%' 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call bug2267_2()| +Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation +test bug2267_4 FUNCTION 'admin'@'%' 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER NULL utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call bug2267_3()| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug2267_1 CREATE DEFINER = admin@% PROCEDURE `test`.`bug2267_1` +() + begin +show procedure status where db='test'; +end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call bug2267_4()| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug2267_4 CREATE DEFINER = admin@% FUNCTION `test`.`bug2267_4` +() + RETURNS int(11) return 100 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure bug2267_1| +drop procedure bug2267_2| +drop procedure bug2267_3| +drop procedure bug2267_4| +drop function bug2267_4| +drop procedure if exists bug2227| +create procedure bug2227(x int) +begin +declare y float default 2.6; +declare z char(16) default "zzz"; +select 1.3, x, y, 42, z; +end| +call bug2227(9)| +1.3 x y 42 z +1.3 9 2.6 42 zzz +drop procedure bug2227| +drop procedure if exists bug2614| +create procedure bug2614() +begin +drop table if exists t3; +create table t3 (id int default '0' not null); +insert into t3 select 12; +insert into t3 select * from t3; +end| +call bug2614()| +call bug2614()| +drop table t3| +drop procedure bug2614| +drop function if exists bug2674| +create function bug2674() returns int +return @@ob_bnl_join_cache_size| +set @osbs = @@ob_bnl_join_cache_size| +set @@ob_bnl_join_cache_size = 262000| +select bug2674()| +bug2674() +262000 +drop function bug2674| +set @@ob_bnl_join_cache_size = @osbs| +drop procedure if exists bug3259_1 | +create procedure bug3259_1 () begin end| +drop procedure if exists BUG3259_2 | +create procedure BUG3259_2 () begin end| +drop procedure if exists Bug3259_3 | +create procedure Bug3259_3 () begin end| +call BUG3259_1()| +call BUG3259_1()| +call bug3259_2()| +call Bug3259_2()| +call bug3259_3()| +call bUG3259_3()| +drop procedure bUg3259_1| +drop procedure BuG3259_2| +drop procedure BUG3259_3| +drop function if exists bug2772| +create function bug2772() returns char(10) character set latin2 +return 'a'| +ERROR 42000: Unknown character set: 'latin2' +select bug2772()| +ERROR 42000: FUNCTION bug2772 does not exist +drop function bug2772| +ERROR 42000: FUNCTION test.bug2772 does not exist +create table t3 (s1 smallint)| +insert into t3 values (123456789012)| +drop procedure if exists bug2780| +create procedure bug2780() +begin +declare exit handler for sqlwarning set @x = 1; +set @x = 0; +insert into t3 values (123456789012); +insert into t3 values (0); +end| +call bug2780()| +select @x| +@x +0 +select * from t3| +s1 +32767 +32767 +0 +drop procedure bug2780| +drop table t3| +create table t3 (content varchar(10) )| +insert into t3 values ("test1")| +insert into t3 values ("test2")| +create table t4 (f1 int, rc int, t3 int)| +drop procedure if exists bug1863| +create procedure bug1863(in1 int) +begin +declare ind int default 0; +declare t1 int; +declare t2 int; +declare t3 int; +declare rc int default 0; +declare continue handler for 1065 set rc = 1; +drop temporary table if exists temp_t1; +create temporary table temp_t1 ( +f1 int auto_increment, f2 varchar(20), primary key (f1) +); +insert into temp_t1 (f2) select content from t3; +select f2 into t3 from temp_t1 where f1 = 10; +if (rc) then +insert into t4 values (1, rc, t3); +end if; +insert into t4 values (2, rc, t3); +end| +call bug1863(10)| +select * from t4| +f1 rc t3 +2 0 NULL +drop procedure bug1863| +drop temporary table temp_t1| +drop table t3, t4| +create table t3 ( +OrderID int not null, +MarketID int, +primary key (OrderID) +)| +create table t4 ( +MarketID int not null, +Market varchar(60), +Status char(1), +primary key (MarketID) +)| +insert t3 (OrderID,MarketID) values (1,1)| +insert t3 (OrderID,MarketID) values (2,2)| +insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| +insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| +drop procedure if exists bug2656_1| +create procedure bug2656_1() +begin +select +m.Market +from t4 m JOIN t3 o +ON o.MarketID != 1 and o.MarketID = m.MarketID; +end | +drop procedure if exists bug2656_2| +create procedure bug2656_2() +begin +select +m.Market +from +t4 m, t3 o +where +m.MarketID != 1 and m.MarketID = o.MarketID; +end | +call bug2656_1()| +Market +MarketID Two +call bug2656_1()| +Market +MarketID Two +call bug2656_2()| +Market +MarketID Two +call bug2656_2()| +Market +MarketID Two +drop procedure bug2656_1| +drop procedure bug2656_2| +drop table t3, t4| +drop procedure if exists bug3426| +create procedure bug3426(in_time int unsigned, out x int) +begin +if in_time is null then +set @stamped_time=10; +set x=1; +else +set @stamped_time=in_time; +set x=2; +end if; +end| +set time_zone='+03:00'; +call bug3426(1000, @i)| +x +2 +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +2 01-01-1970 03:16:40 +call bug3426(NULL, @i)| +x +1 +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +1 01-01-1970 03:00:10 +alter procedure bug3426 sql security invoker| +call bug3426(NULL, @i)| +x +1 +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +1 01-01-1970 03:00:10 +call bug3426(1000, @i)| +x +2 +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +@i time +2 01-01-1970 03:16:40 +drop procedure bug3426| +drop procedure if exists bug3863| +create procedure bug3863() +begin +set @a = 0; +while @a < 5 do +set @a = @a + 1; +end while; +end| +call bug3863()| +select @a| +@a +5 +call bug3863()| +select @a| +@a +5 +drop procedure bug3863| +create table t3 ( +id int(10) unsigned not null default 0, +rid int(10) unsigned not null default 0, +msg varchar(1024) not null, +primary key (id), +unique key rid (rid, id) +)| +drop procedure if exists bug2460_1| +create procedure bug2460_1(in v int) +begin +( select n0.id from t3 as n0 where n0.id = v ) +union +( select n0.id from t3 as n0, t3 as n1 +where n0.id = n1.rid and n1.id = v ) +union +( select n0.id from t3 as n0, t3 as n1, t3 as n2 +where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ) order by id; +end| +call bug2460_1(2)| +id +call bug2460_1(2)| +id +insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| +call bug2460_1(2)| +id +1 +2 +call bug2460_1(2)| +id +1 +2 +drop procedure if exists bug2460_2| +create procedure bug2460_2() +begin +drop table if exists t3; +create temporary table t3 (s1 int); +insert into t3 select 1 union select 1; +end| +call bug2460_2()| +select * from t3| +s1 +1 +drop procedure bug2460_1| +drop procedure bug2460_2| +drop table t3| +set @@sql_mode = ''| +drop procedure if exists bug2564_1| +create procedure bug2564_1() +comment 'Joe''s procedure' + insert into `t1` values ("foo", 1)| +set @@sql_mode = 'ANSI_QUOTES'| +drop procedure if exists bug2564_2| +create procedure bug2564_2() +insert into "t1" values ('foo', 1)| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'insert into "t1" values ('foo', 1)' at line 2 +set @@sql_mode = ''$ +drop function if exists bug2564_3$ +create function bug2564_3(x int, y int) returns int +return x || y$ +set @@sql_mode = 'ANSI'$ +ERROR 0A000: Not supported feature or function +drop function if exists bug2564_4$ +create function bug2564_4(x int, y int) returns int +return x || y$ +set @@sql_mode = ''| +show create procedure bug2564_1| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug2564_1 CREATE DEFINER = admin@% PROCEDURE `test`.`bug2564_1` +() +COMMENT `Joe's procedure` + insert into `t1` values ("foo", 1) utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +show create procedure bug2564_2| +ERROR 42000: procedure/function does not exist +show create function bug2564_3| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug2564_3 CREATE DEFINER = admin@% FUNCTION `test`.`bug2564_3` +( + `x` int(11), `y` int(11) +) RETURNS int(11) return x || y utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +show create function bug2564_4| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug2564_4 CREATE DEFINER = admin@% FUNCTION `test`.`bug2564_4` +( + `x` int(11), `y` int(11) +) RETURNS int(11) return x || y utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure bug2564_1| +drop procedure bug2564_2| +ERROR 42000: PROCEDURE test.bug2564_2 does not exist +drop function bug2564_3| +drop function bug2564_4| +drop function if exists bug3132| +create function bug3132(s char(20)) returns char(50) +return concat('Hello, ', s, '!')| +select bug3132('Bob') union all select bug3132('Judy')| +bug3132('Bob') +Hello, Bob! +Hello, Judy! +drop function bug3132| +drop procedure if exists bug3843| +create procedure bug3843() +analyze table t1| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'analyze table t1' at line 2 +call bug3843()| +ERROR 42000: procedure test.bug3843 does not exist +call bug3843()| +ERROR 42000: procedure test.bug3843 does not exist +select 1+2| +1+2 +3 +drop procedure bug3843| +ERROR 42000: PROCEDURE test.bug3843 does not exist +create table t3 ( s1 char(10) )| +insert into t3 values ('a'), ('b')| +drop procedure if exists bug3368| +create procedure bug3368(v char(10)) +begin +select group_concat(v) from t3; +end| +call bug3368('x')| +group_concat(v) +x,x +call bug3368('yz')| +group_concat(v) +yz,yz +drop procedure bug3368| +drop table t3| +create table t3 (f1 int, f2 int)| +insert into t3 values (1,1)| +drop procedure if exists bug4579_1| +create procedure bug4579_1 () +begin +declare sf1 int; +select f1 from t3 where f1=1 and f2=1 into sf1; +update t3 set f2 = f2 + 1 where f1=1 and f2=1; +call bug4579_2(); +end| +drop procedure if exists bug4579_2| +create procedure bug4579_2 () +begin +end| +call bug4579_1()| +call bug4579_1()| +call bug4579_1()| +drop procedure bug4579_1| +drop procedure bug4579_2| +drop table t3| +drop function if exists bug2773| +create function bug2773() returns int return null| +create table t3 as select bug2773()| +show create table t3| +Table Create Table +t3 CREATE TABLE `t3` ( + `bug2773()` int(11) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 COMPRESSION = 'lz4_1.0' REPLICA_NUM = NUM BLOCK_SIZE = SIZE USE_BLOOM_FILTER = FALSE TABLET_SIZE = SIZE PCTFREE = 10 +drop table t3| +drop function bug2773| +drop procedure if exists bug3788| +create function bug3788() returns date return cast("2005-03-04" as date)| +select bug3788()| +bug3788() +2005-03-04 +drop function bug3788| +create function bug3788() returns binary(1) return 5| +select bug3788()| +bug3788() +5 +drop function bug3788| +create table t3 (f1 int, f2 int, f3 int)| +insert into t3 values (1,1,1)| +drop procedure if exists bug4726| +create procedure bug4726() +begin +declare tmp_o_id INT; +declare tmp_d_id INT default 1; +while tmp_d_id <= 2 do +begin +select f1 from t3 where f2=1 and f3=1 into tmp_o_id; +set tmp_d_id = tmp_d_id + 1; +end; +end while; +end| +call bug4726()| +call bug4726()| +call bug4726()| +drop procedure bug4726| +drop table t3| +drop procedure if exists bug4902| +create procedure bug4902() +begin +show charset like 'foo'; +show collation like 'foo'; +show create table t1; +show create database test; +show databases like 'foo'; +show errors; +show columns from t1; +show keys from t1; +#show open tables like 'foo'; +# Removed because result will differ in embedded mode. +#show privileges; +show status like 'foo'; +show tables like 'foo'; +show variables like 'foo'; +show warnings; +end| +drop procedure bug4902| +drop procedure if exists bug4904| +create procedure bug4904() +begin +declare continue handler for sqlstate 'HY000' begin end; +create table t2 as select * from t3; +end| +call bug4904()| +ERROR 42S02: Table 'test.t3' doesn't exist +drop procedure bug4904| +create table t3 (s1 char character set latin1, s2 char character set latin2)| +ERROR 42000: Unknown character set: 'latin1' +create table t3 (s1 char character set utf8, s2 char character set utf8)| +drop procedure if exists bug4904| +create procedure bug4904 () +begin +declare continue handler for sqlstate 'HY000' begin end; +select s1 from t3 union select s2 from t3; +end| +call bug4904()| +s1 +drop procedure bug4904| +drop table t3| +drop procedure if exists bug336| +create procedure bug336(out y int) +begin +declare x int; +set x = (select sum(t.data) from test.t1 t); +set y = x; +end| +insert into t1 values ("a", 2), ("b", 3)| +call bug336(@y)| +y +5 +select @y| +@y +5 +delete from t1| +drop procedure bug336| +drop procedure if exists bug3157| +create procedure bug3157() +begin +if exists(select * from t1) then +set @n= @n + 1; +end if; +if (select count(*) from t1) then +set @n= @n + 1; +end if; +end| +set @n = 0| +insert into t1 values ("a", 1)| +call bug3157()| +select @n| +@n +2 +delete from t1| +drop procedure bug3157| +drop procedure if exists bug5251| +create procedure bug5251() +begin +end| +select created from mysql.proc +where db='test' and name='bug5251' into @c1| +alter procedure bug5251 comment 'foobar'| +select count(*) from mysql.proc +where db='test' and name='bug5251' and created = @c1| +count(*) +1 +drop procedure bug5251| +drop procedure if exists bug5251| +create procedure bug5251() +checksum table t1| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'checksum table t1' at line 2 +call bug5251()| +ERROR 42000: procedure test.bug5251 does not exist +call bug5251()| +ERROR 42000: procedure test.bug5251 does not exist +drop procedure bug5251| +ERROR 42000: PROCEDURE test.bug5251 does not exist +drop procedure if exists bug5287| +create procedure bug5287(param1 int) +label1: +begin +declare c cursor for select 5; +loop +if param1 >= 0 then +leave label1; +end if; +end loop; +end| +call bug5287(1)| +drop procedure bug5287| +drop procedure if exists bug5307| +create procedure bug5307() +begin +end; set @x = 3| +call bug5307()| +select @x| +@x +3 +drop procedure bug5307| +drop procedure if exists bug5258| +create procedure bug5258() +begin +end| +drop procedure if exists bug5258_aux| +create procedure bug5258_aux() +begin +declare c, m char(27); +select created,modified from mysql.proc where name = 'bug5258' into c,m; +if c = m then +select 'Ok'; +else +select c, m; +end if; +end| +call bug5258_aux()| +Ok +Ok +drop procedure bug5258| +drop procedure bug5258_aux| +drop function if exists bug4487| +create function bug4487() returns char +begin +declare v char; +return v; +end| +select bug4487()| +bug4487() +NULL +drop function bug4487| +drop procedure if exists bug4941| +drop procedure if exists bug4941| +create procedure bug4941(out x int) +begin +declare c cursor for select i from t2 limit 1; +open c; +fetch c into x; +close c; +end| +insert into t2 values (null, null, null)| +set @x = 42| +call bug4941(@x)| +x +NULL +select @x| +@x +NULL +delete from t1| +drop procedure bug4941| +drop procedure if exists bug4905| +create table t3 (s1 int,primary key (s1))| +drop procedure if exists bug4905| +create procedure bug4905() +begin +declare v int; +declare continue handler for sqlstate '23000' set v = 5; +insert into t3 values (1); +end| +call bug4905()| +select row_count()| +row_count() +1 +call bug4905()| +select row_count()| +row_count() +0 +call bug4905()| +select row_count()| +row_count() +0 +select * from t3| +s1 +1 +drop procedure bug4905| +drop table t3| +drop procedure if exists bug6029| +drop procedure if exists bug6029| +create procedure bug6029() +begin +declare exit handler for 1136 select '1136'; +declare exit handler for sqlstate '23000' select 'sqlstate 23000'; +declare continue handler for sqlexception select 'sqlexception'; +insert into t3 values (1); +insert into t3 values (1,2); +end| +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1)| +call bug6029()| +sqlstate 23000 +sqlstate 23000 +delete from t3| +call bug6029()| +1136 +1136 +drop procedure bug6029| +drop table t3| +drop procedure if exists bug8540| +create procedure bug8540() +begin +declare x int default 1; +select x as y, x+0 as z; +end| +call bug8540()| +y z +1 1 +drop procedure bug8540| +create table t3 (s1 int)| +drop procedure if exists bug6642| +create procedure bug6642() +select abs(count(s1)) from t3| +call bug6642()| +abs(count(s1)) +0 +call bug6642()| +abs(count(s1)) +0 +drop procedure bug6642| +insert into t3 values (0),(1)| +drop procedure if exists bug7013| +create procedure bug7013() +select s1,count(s1) from t3 group by s1 with rollup| +call bug7013()| +s1 count(s1) +0 1 +1 1 +NULL 2 +call bug7013()| +s1 count(s1) +0 1 +1 1 +NULL 2 +drop procedure bug7013| +drop table if exists t4| +create table t4 ( +a mediumint(8) unsigned not null auto_increment, +b smallint(5) unsigned not null, +c char(32) not null, +primary key (a) +) engine=myisam default charset=latin1| +ERROR 42000: Unknown character set: 'latin1' +create table t4 ( +a mediumint(8) unsigned not null auto_increment, +b smallint(5) unsigned not null, +c char(32) not null, +primary key (a) +) engine=myisam default charset=utf8mb4| +Warnings: +Warning 1286 Unknown storage engine 'myisam' +insert into t4 values (1, 2, 'oneword')| +insert into t4 values (2, 2, 'anotherword')| +drop procedure if exists bug7743| +create procedure bug7743 ( searchstring char(28) ) +begin +declare var mediumint(8) unsigned; +select a from t4 where b = 2 and c = binary searchstring limit 1 into var; +select var; +end| +call bug7743("oneword")| +var +1 +call bug7743("OneWord")| +var +NULL +call bug7743("anotherword")| +var +2 +call bug7743("AnotherWord")| +var +NULL +drop procedure bug7743| +drop table t4| +delete from t3| +insert into t3 values(1)| +drop procedure if exists bug7992_1| +drop procedure if exists bug7992_2| +create procedure bug7992_1() +begin +declare i int; +select max(s1)+1 from t3 into i; +end| +create procedure bug7992_2() +insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| +call bug7992_1()| +call bug7992_1()| +call bug7992_2()| +call bug7992_2()| +drop procedure bug7992_1| +drop procedure bug7992_2| +drop table t3| +create table t3 ( userid bigint(20) not null default 0 )| +drop procedure if exists bug8116| +create procedure bug8116(in _userid int) +select * from t3 where userid = _userid| +call bug8116(42)| +userid +call bug8116(42)| +userid +drop procedure bug8116| +drop table t3| +drop procedure if exists bug6857| +create procedure bug6857() +begin +declare t0, t1 int; +declare plus bool default 0; +set t0 = unix_timestamp(); +select sleep(1.1); +set t1 = unix_timestamp(); +if t1 > t0 then +set plus = 1; +end if; +select plus; +end| +call bug6857()| +sleep(1.1) +plus +0 +1 +drop procedure bug6857| +drop procedure if exists bug8757| +create procedure bug8757() +begin +declare x int; +declare c1 cursor for select data from t1 limit 1; +begin +declare y int; +declare c2 cursor for select i from t2 limit 1; +open c2; +fetch c2 into y; +close c2; +select 2,y; +end; +open c1; +fetch c1 into x; +close c1; +select 1,x; +end| +delete from t1| +delete from t2| +insert into t1 values ("x", 1)| +insert into t2 values ("y", 2, 0.0)| +call bug8757()| +2 y +1 x +2 2 +1 1 +delete from t1| +delete from t2| +drop procedure bug8757| +drop procedure if exists bug8762| +drop procedure if exists bug8762| +create procedure bug8762() begin end| +drop procedure if exists bug8762| +create procedure bug8762() begin end| +drop procedure bug8762| +drop function if exists bug5240| +create function bug5240 () returns int +begin +declare x int; +declare c cursor for select data from t1 limit 1; +open c; +fetch c into x; +close c; +return x; +end| +delete from t1| +insert into t1 values ("answer", 42)| +select id, bug5240() from t1| +id bug5240() +answer 42 +drop function bug5240| +drop procedure if exists p1| +create table t3(id int)| +insert into t3 values(1)| +create procedure bug7992() +begin +declare i int; +select max(id)+1 from t3 into i; +end| +call bug7992()| +call bug7992()| +drop procedure bug7992| +drop table t3| +drop table if exists t3;| +create table t3 ( +lpitnumber int(11) default null, +lrecordtype int(11) default null +)| +drop table if exists t4;| +create table t4 ( +lbsiid int(11) not null default '0', +ltradingmodeid int(11) not null default '0', +ltradingareaid int(11) not null default '0', +csellingprice decimal(19,4) default null, +primary key (lbsiid,ltradingmodeid,ltradingareaid) +)| +drop table if exists t5;| +create table t5 ( +lbsiid int(11) not null default '0', +ltradingareaid int(11) not null default '0', +primary key (lbsiid,ltradingareaid) +)| +drop procedure if exists bug8849| +create procedure bug8849() +begin +insert into t5 +( +t5.lbsiid, +t5.ltradingareaid +) +select distinct t3.lpitnumber, t4.ltradingareaid +from +t4 join t3 on +t3.lpitnumber = t4.lbsiid +and t3.lrecordtype = 1 +left join t4 as price01 on +price01.lbsiid = t4.lbsiid and +price01.ltradingmodeid = 1 and +t4.ltradingareaid = price01.ltradingareaid; +end| +call bug8849()| +call bug8849()| +call bug8849()| +drop procedure bug8849| +drop tables t3,t4,t5| +drop procedure if exists bug8937| +create procedure bug8937() +begin +declare s,x,y,z int; +declare a float; +select sum(data),avg(data),min(data),max(data) from t1 into s,x,y,z; +select s,x,y,z; +select avg(data) from t1 into a; +select a; +end| +delete from t1| +insert into t1 (data) values (1), (2), (3), (4), (6)| +call bug8937()| +s x y z +a +16 3 1 6 +3.2 +drop procedure bug8937| +delete from t1| +drop procedure if exists bug6900| +drop procedure if exists bug9074| +drop procedure if exists bug6900_9074| +create table t3 (w char unique, x char)| +insert into t3 values ('a', 'b')| +create procedure bug6900() +begin +declare exit handler for sqlexception select '1'; +begin +declare exit handler for sqlexception select '2'; +insert into t3 values ('x', 'y', 'z'); +end; +end| +create procedure bug9074() +begin +declare x1, x2, x3, x4, x5, x6 int default 0; +begin +declare continue handler for sqlstate '23000' set x5 = 1; +insert into t3 values ('a', 'b'); +set x6 = 1; +end; +begin1_label: +begin +declare continue handler for sqlstate '23000' set x1 = 1; +insert into t3 values ('a', 'b'); +set x2 = 1; +begin2_label: +begin +declare exit handler for sqlstate '23000' set x3 = 1; +set x4= 1; +insert into t3 values ('a','b'); +set x4= 0; +end begin2_label; +end begin1_label; +select x1, x2, x3, x4, x5, x6; +end| +create procedure bug6900_9074(z int) +begin +declare exit handler for sqlstate '23000' select '23000'; +begin +declare exit handler for sqlexception select 'sqlexception'; +if z = 1 then +insert into t3 values ('a', 'b'); +else +insert into t3 values ('x', 'y', 'z'); +end if; +end; +end| +call bug6900()| +2 +2 +call bug9074()| +x1 x2 x3 x4 x5 x6 +1 1 1 1 1 1 +call bug6900_9074(0)| +sqlexception +sqlexception +call bug6900_9074(1)| +sqlexception +sqlexception +drop procedure bug6900| +drop procedure bug9074| +drop procedure bug6900_9074| +drop table t3| +drop procedure if exists avg| +create procedure avg () +begin +end| +call avg ()| +drop procedure avg| +drop procedure if exists bug6129| +set @old_mode= @@sql_mode| +set @@sql_mode= "ONLY_FULL_GROUP_BY"| +create procedure bug6129() +select @@sql_mode| +call bug6129()| +@@sql_mode +ONLY_FULL_GROUP_BY +set @@sql_mode= "PAD_CHAR_TO_FULL_LENGTH,PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"| +call bug6129()| +@@sql_mode +ONLY_FULL_GROUP_BY +set @@sql_mode= "PIPES_AS_CONCAT"| +call bug6129()| +@@sql_mode +ONLY_FULL_GROUP_BY +set @@sql_mode=@old_mode; +drop procedure bug6129| +drop procedure if exists bug9856| +create procedure bug9856() +begin +declare v int; +declare c cursor for select data from t1; +declare exit handler for sqlexception, not found select '16'; +open c; +fetch c into v; +select v; +end| +delete from t1| +call bug9856()| +16 +16 +call bug9856()| +16 +16 +drop procedure bug9856| +drop procedure if exists bug9674_1| +drop procedure if exists bug9674_2| +create procedure bug9674_1(out arg int) +begin +declare temp_in1 int default 0; +declare temp_fl1 int default 0; +set temp_in1 = 100; +set temp_fl1 = temp_in1/10; +set arg = temp_fl1; +end| +create procedure bug9674_2() +begin +declare v int default 100; +select v/10; +end| +call bug9674_1(@sptmp)| +arg +10 +call bug9674_1(@sptmp)| +arg +10 +select @sptmp| +@sptmp +10 +call bug9674_2()| +v/10 +10.0000 +call bug9674_2()| +v/10 +10.0000 +drop procedure bug9674_1| +drop procedure bug9674_2| +drop procedure if exists bug9598_1| +drop procedure if exists bug9598_2| +create procedure bug9598_1(in var_1 char(16), +out var_2 integer, out var_3 integer) +begin +set var_2 = 50; +set var_3 = 60; +end| +create procedure bug9598_2(in v1 char(16), +in v2 integer, +in v3 integer, +in v4 integer, +in v5 integer) +begin +select v1,v2,v3,v4,v5; +call bug9598_1(v1,@tmp1,@tmp2); +select v1,v2,v3,v4,v5; +end| +call bug9598_2('Test',2,3,4,5)| +v1 v2 v3 v4 v5 +v1 v2 v3 v4 v5 +Test 2 3 4 5 +Test 2 3 4 5 +select @tmp1, @tmp2| +@tmp1 @tmp2 +50 60 +drop procedure bug9598_1| +drop procedure bug9598_2| +drop procedure if exists bug9902| +create function bug9902() returns int(11) +begin +set @x = @x + 1; +return @x; +end| +set @qcs1 = @@query_cache_size| +set global query_cache_size = 102400| +set @x = 1| +insert into t1 values ("qc", 42)| +set global query_cache_size = @qcs1| +delete from t1| +drop function bug9902| +drop function if exists bug9102| +create function bug9102() returns blob return 'a'| +drop function if exists bug9102| +create function bug9102() returns varchar(1024) return 'a'| +select bug9102()| +bug9102() +a +drop function bug9102| +drop function if exists bug7648| +create function bug7648() returns bit(8) return 'a'| +select bug7648()| +bug7648() +a +drop function bug7648| +drop function if exists bug9775| +create function bug9775(v1 char(1)) returns enum('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('c')| +bug9775('a') bug9775('b') bug9775('c') +a b +drop function bug9775| +create function bug9775(v1 int) returns enum('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3)| +bug9775(1) bug9775(2) bug9775(3) +a b +drop function bug9775| +create function bug9775(v1 char(1)) returns set('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| +bug9775('a') bug9775('b') bug9775('a,b') bug9775('c') +a b a +drop function bug9775| +create function bug9775(v1 int) returns set('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| +bug9775(1) bug9775(2) bug9775(3) bug9775(4) +a b a,b +drop function bug9775| +drop function if exists bug8861| +create function bug8861(v1 int) returns year return v1| +select bug8861(05)| +bug8861(05) +2005 +set @x = bug8861(05)| +select @x| +@x +2005 +drop function bug8861| +drop procedure if exists bug9004_1| +drop procedure if exists bug9004_2| +create procedure bug9004_1(x char(16)) +begin +insert into t1 values (x, 42); +insert into t1 values (x, 17); +end| +create procedure bug9004_2(x char(16)) +call bug9004_1(x)| +call bug9004_1('12345678901234567')| +call bug9004_2('12345678901234567890')| +delete from t1| +drop procedure bug9004_1| +drop procedure bug9004_2| +drop procedure if exists bug7293| +insert into t1 values ('secret', 0)| +create procedure bug7293(p1 varchar(100)) +begin +if exists (select id from t1 where soundex(p1)=soundex(id)) then +select 'yes'; +end if; +end;| +call bug7293('secret')| +yes +yes +call bug7293 ('secrete')| +yes +yes +drop procedure bug7293| +delete from t1| +drop procedure if exists bug9841| +drop view if exists v1| +create view v1 as select * from t1, t2 where id = s| +create procedure bug9841 () +update v1 set data = 10| +call bug9841()| +drop view v1| +drop procedure bug9841| +drop procedure if exists bug5963_1| +drop procedure if exists bug5963_2| +create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| +create table t3 (s1 int)| +insert into t3 values (5)| +call bug5963_1()| +v +5 +call bug5963_1()| +v +5 +drop procedure bug5963_1| +drop table t3| +create procedure bug5963_2 (cfk_value int) +begin +if cfk_value in (select cpk from t3) then +set @x = 5; +end if; +end; +| +create table t3 (cpk int)| +insert into t3 values (1)| +call bug5963_2(1)| +call bug5963_2(1)| +drop procedure bug5963_2| +drop table t3| +drop function if exists bug9559| +create function bug9559() +returns int +begin +set @y = -6/2; +return @y; +end| +select bug9559()| +bug9559() +-3 +drop function bug9559| +drop procedure if exists bug10961| +create procedure bug10961() +begin +declare v char; +declare x int; +declare c cursor for select * from dual; +declare continue handler for sqlexception select x; +set x = 1; +open c; +set x = 2; +fetch c into v; +set x = 3; +close c; +end| +call bug10961()| +x +x +x +1 +2 +3 +call bug10961()| +x +x +x +1 +2 +3 +drop procedure bug10961| +DROP PROCEDURE IF EXISTS bug6866| +DROP VIEW IF EXISTS tv| +DROP TABLE IF EXISTS tt1,tt2,tt3| +Warnings: +Note 1051 Unknown table 'test.tt1' +Note 1051 Unknown table 'test.tt2' +Note 1051 Unknown table 'test.tt3' +CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| +CREATE TABLE tt2 (a2 int, data2 varchar(10))| +CREATE TABLE tt3 (a3 int, data3 varchar(10))| +INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| +INSERT INTO tt2 VALUES (1, 'a')| +INSERT INTO tt2 VALUES (2, 'b')| +INSERT INTO tt2 VALUES (3, 'c')| +INSERT INTO tt3 VALUES (4, 'd')| +INSERT INTO tt3 VALUES (5, 'e')| +INSERT INTO tt3 VALUES (6, 'f')| +CREATE VIEW tv AS +SELECT tt1.*, tt2.data2, tt3.data3 +FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 +LEFT JOIN tt3 ON tt1.a3 = tt3.a3 +ORDER BY tt1.a1, tt2.a2, tt3.a3| +CREATE PROCEDURE bug6866 (_a1 int) +BEGIN +SELECT * FROM tv WHERE a1 = _a1; +END| +CALL bug6866(1)| +a1 a2 a3 data data2 data3 +1 1 4 xx a d +CALL bug6866(1)| +a1 a2 a3 data data2 data3 +1 1 4 xx a d +CALL bug6866(1)| +a1 a2 a3 data data2 data3 +1 1 4 xx a d +DROP PROCEDURE bug6866; +DROP VIEW tv| +DROP TABLE tt1, tt2, tt3| +DROP PROCEDURE IF EXISTS bug10136| +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin +declare done int default 3; +repeat +select * from t3; +set done = done - 1; +until done <= 0 end repeat; +end| +call bug10136()| +name val +name val +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +aaaaa 1 +bbbbb 2 +ccccc 3 +aaaaa 1 +bbbbb 2 +ccccc 3 +call bug10136()| +name val +name val +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +aaaaa 1 +bbbbb 2 +ccccc 3 +aaaaa 1 +bbbbb 2 +ccccc 3 +call bug10136()| +name val +name val +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +aaaaa 1 +bbbbb 2 +ccccc 3 +aaaaa 1 +bbbbb 2 +ccccc 3 +drop procedure bug10136| +drop table t3| +drop procedure if exists bug11529| +create procedure bug11529() +begin +declare c cursor for select id, data from t1 where data in (10,13); +open c; +begin +declare vid char(16); +declare vdata int; +declare exit handler for not found begin end; +while true do +fetch c into vid, vdata; +end while; +end; +close c; +end| +insert into t1 values +('Name1', 10), +('Name2', 11), +('Name3', 12), +('Name4', 13), +('Name5', 14)| +call bug11529()| +call bug11529()| +delete from t1| +drop procedure bug11529| +set character set utf8| +drop procedure if exists bug6063| +drop procedure if exists bug7088_1| +drop procedure if exists bug7088_2| +create procedure bug6063() +begin +lâbel: begin end; +label: begin end; +label1: begin end; +end| +create procedure bug7088_1() +label1: begin end label1| +create procedure bug7088_2() +läbel1: begin end| +call bug6063()| +call bug7088_1()| +call bug7088_2()| +set character set default| +show create procedure bug6063| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug6063 CREATE DEFINER = admin@% PROCEDURE `test`.`bug6063` +() + begin +lâbel: begin end; +label: begin end; +label1: begin end; +end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +show create procedure bug7088_1| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug7088_1 CREATE DEFINER = admin@% PROCEDURE `test`.`bug7088_1` +() + label1: begin end label1 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +show create procedure bug7088_2| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug7088_2 CREATE DEFINER = admin@% PROCEDURE `test`.`bug7088_2` +() + läbel1: begin end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure bug6063| +drop procedure bug7088_1| +drop procedure bug7088_2| +drop procedure if exists bug9565_sub| +drop procedure if exists bug9565| +create procedure bug9565_sub() +begin +select * from t1; +end| +create procedure bug9565() +begin +insert into t1 values ("one", 1); +call bug9565_sub(); +end| +call bug9565()| +id data +one 1 +delete from t1| +drop procedure bug9565_sub| +drop procedure bug9565| +drop procedure if exists bug9538| +create procedure bug9538() +set @@ob_bnl_join_cache_size = 1000000| +set @x = @@ob_bnl_join_cache_size| +set @@ob_bnl_join_cache_size = 2000000| +select @@ob_bnl_join_cache_size| +@@ob_bnl_join_cache_size +2000000 +call bug9538()| +select @@ob_bnl_join_cache_size| +@@ob_bnl_join_cache_size +1000000 +set @@ob_bnl_join_cache_size = @x| +drop procedure bug9538| +drop procedure if exists bug8692| +create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| +insert into t3 values ('', '', '', '', '', '', NULL)| +create procedure bug8692() +begin +declare v1 VARCHAR(10); +declare v2 VARCHAR(10); +declare v3 VARCHAR(10); +declare v4 VARCHAR(10); +declare v5 VARCHAR(10); +declare v6 VARCHAR(10); +declare v7 VARCHAR(10); +declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; +open c8692; +fetch c8692 into v1,v2,v3,v4,v5,v6,v7; +select v1, v2, v3, v4, v5, v6, v7; +end| +call bug8692()| +v1 v2 v3 v4 v5 v6 v7 + NULL +drop procedure bug8692| +drop table t3| +drop function if exists bug10055| +create function bug10055(v char(255)) returns char(255) return lower(v)| +select t.column_name, bug10055(t.column_name) +from information_schema.columns as t +where t.table_schema = 'test' and t.table_name = 't1'| +column_name bug10055(t.column_name) +id id +data data +drop function bug10055| +drop procedure if exists bug12297| +create procedure bug12297(lim int) +begin +set @x = 0; +repeat +insert into t1(id,data) +values('aa', @x); +set @x = @x + 1; +until @x >= lim +end repeat; +end| +call bug12297(10)| +drop procedure bug12297| +drop function if exists f_bug11247| +drop procedure if exists p_bug11247| +create function f_bug11247(param int) +returns int +return param + 1| +create procedure p_bug11247(lim int) +begin +declare v int default 0; +while v < lim do +set v= f_bug11247(v); +end while; +end| +call p_bug11247(10)| +drop function f_bug11247| +drop procedure p_bug11247| +drop procedure if exists bug12168| +drop table if exists t3, t4| +create table t3 (a int)| +insert into t3 values (1),(2),(3),(4)| +create table t4 (a int)| +create procedure bug12168(arg1 char(1)) +begin +declare b, c integer; +if arg1 = 'a' then +begin +declare c1 cursor for select a from t3 where a % 2; +declare continue handler for not found set b = 1; +set b = 0; +open c1; +c1_repeat: repeat +fetch c1 into c; +if (b = 1) then +leave c1_repeat; +end if; +insert into t4 values (c); +until b = 1 +end repeat; +end; +end if; +if arg1 = 'b' then +begin +declare c2 cursor for select a from t3 where not a % 2; +declare continue handler for not found set b = 1; +set b = 0; +open c2; +c2_repeat: repeat +fetch c2 into c; +if (b = 1) then +leave c2_repeat; +end if; +insert into t4 values (c); +until b = 1 +end repeat; +end; +end if; +end| +call bug12168('a')| +select * from t4| +a +1 +3 +truncate t4| +call bug12168('b')| +select * from t4| +a +2 +4 +truncate t4| +call bug12168('a')| +select * from t4| +a +1 +3 +truncate t4| +call bug12168('b')| +select * from t4| +a +2 +4 +truncate t4| +drop table t3, t4| +drop procedure if exists bug12168| +drop table if exists t3| +drop procedure if exists bug11333| +create table t3 (c1 char(128))| +insert into t3 values +('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| +create procedure bug11333(i int) +begin +declare tmp varchar(128); +set @x = 0; +repeat +select c1 from t3 +where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' into tmp; +set @x = @x + 1; +until @x >= i +end repeat; +end| +call bug11333(10)| +drop procedure bug11333| +drop table t3| +drop function if exists bug9048| +create function bug9048(f1 char binary) returns char +begin +set f1= concat( 'hello', f1 ); +return f1; +end| +drop function bug9048| +create function bug9048(f1 char binary) returns char binary +begin +set f1= concat( 'hello', f1 ); +return f1; +end| +select bug9048('1')| +bug9048('1') +h +drop function bug9048| +drop procedure if exists bug12849_1| +create procedure bug12849_1(inout x char) select x into x| +set @var='a'| +call bug12849_1(@var)| +x +a +select @var| +@var +a +drop procedure bug12849_1| +drop procedure if exists bug12849_2| +create procedure bug12849_2(inout foo varchar(15)) +begin +select concat(foo, foo) INTO foo; +end| +set @var='abcd'| +call bug12849_2(@var)| +foo +abcdabcd +select @var| +@var +abcdabcd +drop procedure bug12849_2| +drop procedure if exists bug131333| +drop function if exists bug131333| +create procedure bug131333() +begin +begin +declare a int; +select a; +set a = 1; +select a; +end; +begin +declare b int; +select b; +end; +end| +create function bug131333() +returns int +begin +begin +declare a int; +set a = 1; +end; +begin +declare b int; +return b; +end; +end| +call bug131333()| +a +a +b +NULL +1 +NULL +select bug131333()| +bug131333() +NULL +drop procedure bug131333| +drop function bug131333| +drop function if exists bug12379| +drop procedure if exists bug12379_1| +drop procedure if exists bug12379_2| +drop procedure if exists bug12379_3| +drop table if exists t3| +create table t3 (c1 char(1) primary key not null)| +create function bug12379() +returns integer +begin +insert into t3 values('X'); +insert into t3 values('X'); +return 0; +end| +create procedure bug12379_1() +begin +declare exit handler for sqlexception select 42; +select bug12379(); +END| +create procedure bug12379_2() +begin +declare exit handler for sqlexception begin end; +select bug12379(); +end| +create procedure bug12379_3() +begin +select bug12379(); +end| +select bug12379()| +Got one of the listed errors +select 1| +1 +1 +call bug12379_1()| +42 +42 +select 2| +2 +2 +call bug12379_2()| +select 3| +3 +3 +call bug12379_3()| +Got one of the listed errors +select 4| +4 +4 +drop function bug12379| +drop procedure bug12379_1| +drop procedure bug12379_2| +drop procedure bug12379_3| +drop table t3| +drop procedure if exists bug13124| +create procedure bug13124() +begin +declare y integer; +set @x=y; +end| +call bug13124()| +drop procedure bug13124| +drop procedure if exists bug12979_1| +create procedure bug12979_1(inout d decimal(5)) set d = d / 2| +set @bug12979_user_var = NULL| +call bug12979_1(@bug12979_user_var)| +d +NULL +drop procedure bug12979_1| +drop procedure if exists bug12979_2| +create procedure bug12979_2() +begin +declare internal_var decimal(5); +set internal_var= internal_var / 2; +select internal_var; +end| +call bug12979_2()| +internal_var +NULL +drop procedure bug12979_2| +drop table if exists t3| +drop procedure if exists bug6127| +create table t3 (s1 int unique)| +set @sm=@@sql_mode| +set sql_mode='traditional'| +ERROR 0A000: Not supported feature or function +create procedure bug6127() +begin +declare continue handler for sqlstate '23000' + begin +declare continue handler for sqlstate '22003' + insert into t3 values (0); +insert into t3 values (1000000000000000); +end; +insert into t3 values (1); +insert into t3 values (1); +end| +call bug6127()| +select * from t3| +s1 +1 +2147483647 +call bug6127()| +ERROR 23000: Duplicate entry '2147483647' for key 's1' +select * from t3| +s1 +1 +2147483647 +set sql_mode=@sm| +drop table t3| +drop procedure bug6127| +drop procedure if exists bug12589_1| +drop procedure if exists bug12589_2| +drop procedure if exists bug12589_3| +create procedure bug12589_1() +begin +declare spv1 decimal(3,3); +set spv1= 123.456; +set spv1 = 'test'; +create temporary table tm1 as select spv1; +show create table tm1; +drop temporary table tm1; +end| +create procedure bug12589_2() +begin +declare spv1 decimal(6,3); +set spv1= 123.456; +create temporary table tm1 as select spv1; +show create table tm1; +drop temporary table tm1; +end| +create procedure bug12589_3() +begin +declare spv1 decimal(6,3); +set spv1= -123.456; +create temporary table tm1 as select spv1; +show create table tm1; +drop temporary table tm1; +end| +call bug12589_1()| +Table Create Table +tm1 CREATE TEMPORARY TABLE `tm1` ( + `spv1` decimal(3,3) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 +call bug12589_2()| +Table Create Table +tm1 CREATE TEMPORARY TABLE `tm1` ( + `spv1` decimal(6,3) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 +call bug12589_3()| +Table Create Table +tm1 CREATE TEMPORARY TABLE `tm1` ( + `spv1` decimal(6,3) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 +drop procedure bug12589_1| +drop procedure bug12589_2| +drop procedure bug12589_3| +drop table if exists t3| +drop procedure if exists bug7049_1| +drop procedure if exists bug7049_2| +drop procedure if exists bug7049_3| +drop procedure if exists bug7049_4| +drop function if exists bug7049_1| +drop function if exists bug7049_2| +create table t3 ( x int unique )| +create procedure bug7049_1() +begin +insert into t3 values (42); +insert into t3 values (42); +end| +create procedure bug7049_2() +begin +declare exit handler for sqlexception +select 'Caught it' as 'Result'; +call bug7049_1(); +select 'Missed it' as 'Result'; +end| +create procedure bug7049_3() +call bug7049_1()| +create procedure bug7049_4() +begin +declare exit handler for sqlexception +select 'Caught it' as 'Result'; +call bug7049_3(); +select 'Missed it' as 'Result'; +end| +create function bug7049_1() +returns int +begin +insert into t3 values (42); +insert into t3 values (42); +return 42; +end| +create function bug7049_2() +returns int +begin +declare x int default 0; +declare continue handler for sqlexception +set x = 1; +set x = bug7049_1(); +return x; +end| +call bug7049_2()| +Result +Caught it +select * from t3| +x +42 +delete from t3| +call bug7049_4()| +Result +Caught it +select * from t3| +x +42 +select bug7049_2()| +bug7049_2() +1 +drop table t3| +drop procedure bug7049_1| +drop procedure bug7049_2| +drop procedure bug7049_3| +drop procedure bug7049_4| +drop function bug7049_1| +drop function bug7049_2| +drop function if exists bug13941| +drop procedure if exists bug13941| +create function bug13941(p_input_str varchar(1024)) +returns varchar(1024) +begin +declare p_output_str varchar(1024); +set p_output_str = p_input_str; +set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); +set p_output_str = replace(p_output_str, 'test', 'prova'); +set p_output_str = replace(p_output_str, 'this', 'questo'); +set p_output_str = replace(p_output_str, ' a ', 'una '); +set p_output_str = replace(p_output_str, 'is', ''); +return p_output_str; +end| +create procedure bug13941(out sout varchar(128)) +begin +set sout = 'Local'; +set sout = ifnull(sout, 'DEF'); +end| +select bug13941('this is a test')| +bug13941('this is a test') +questo una prova +call bug13941(@a)| +sout +Local +select @a| +@a +Local +drop function bug13941| +drop procedure bug13941| +DROP PROCEDURE IF EXISTS bug13095; +DROP TABLE IF EXISTS bug13095_t1; +DROP VIEW IF EXISTS bug13095_v1; +CREATE PROCEDURE bug13095(tbl_name varchar(32)) +BEGIN +SET @str = +CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); +SELECT @str; +PREPARE stmt1 FROM @str; +EXECUTE stmt1; +SET @str = +CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); +SELECT @str; +PREPARE stmt2 FROM @str; +EXECUTE stmt2; +SET @str = +CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); +SELECT @str; +PREPARE stmt3 FROM @str; +EXECUTE stmt3; +SELECT * FROM bug13095_v1; +SET @str = +"DROP VIEW bug13095_v1"; +SELECT @str; +PREPARE stmt4 FROM @str; +EXECUTE stmt4; +END| +CALL bug13095('bug13095_t1'); +@str +@str +@str +c1 +@str +CREATE TABLE bug13095_t1(stuff char(15)) +INSERT INTO bug13095_t1 VALUES('row1'),('row2'),('row3') +CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM bug13095_t1 +row1 +row2 +row3 +DROP VIEW bug13095_v1 +DROP PROCEDURE IF EXISTS bug13095; +DROP VIEW IF EXISTS bug13095_v1; +DROP TABLE IF EXISTS bug13095_t1; +create procedure bug14845() +begin +declare a char(255); +declare done int default 0; +declare c cursor for select count(*) from t1 where 1 = 0; +declare continue handler for sqlstate '02000' set done = 1; +open c; +repeat +fetch c into a; +if not done then +select a; +end if; +until done end repeat; +close c; +end| +call bug14845()| +a +0 +drop procedure bug14845| +drop procedure if exists bug13549_1| +drop procedure if exists bug13549_2| +CREATE PROCEDURE `bug13549_2`() +begin +call bug13549_1(); +end| +CREATE PROCEDURE `bug13549_1`() +begin +declare done int default 0; +set done= not done; +end| +CALL bug13549_2()| +drop procedure bug13549_2| +drop procedure bug13549_1| +drop function if exists bug10100f| +drop procedure if exists bug10100p| +drop procedure if exists bug10100t| +drop procedure if exists bug10100pt| +drop procedure if exists bug10100pv| +drop procedure if exists bug10100pd| +drop procedure if exists bug10100pc| +create function bug10100f(prm int) returns int +begin +if prm > 1 then +return prm * bug10100f(prm - 1); +end if; +return 1; +end| +create procedure bug10100p(prm int, inout res int) +begin +set res = res * prm; +if prm > 1 then +call bug10100p(prm - 1, res); +end if; +end| +create procedure bug10100t(prm int) +begin +declare res int; +set res = 1; +call bug10100p(prm, res); +select res; +end| +create table t3 (a int)| +insert into t3 values (0)| +create view v1 as select a from t3| +create procedure bug10100pt(level int, lim int) +begin +if level < lim then +update t3 set a=level; +FLUSH TABLES; +call bug10100pt(level+1, lim); +else +select * from t3; +end if; +end| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'FLUSH TABLES' at line 5 +create procedure bug10100pv(level int, lim int) +begin +if level < lim then +update v1 set a=level; +FLUSH TABLES; +call bug10100pv(level+1, lim); +else +select * from v1; +end if; +end| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'FLUSH TABLES' at line 5 +prepare stmt2 from "select * from t3;"| +create procedure bug10100pd(level int, lim int) +begin +if level < lim then +select level; +prepare stmt1 from "update t3 set a=a+2"; +execute stmt1; +FLUSH TABLES; +execute stmt1; +FLUSH TABLES; +execute stmt1; +FLUSH TABLES; +deallocate prepare stmt1; +execute stmt2; +select * from t3; +call bug10100pd(level+1, lim); +else +execute stmt2; +end if; +end| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'FLUSH TABLES' at line 7 +create procedure bug10100pc(level int, lim int) +begin +declare lv int; +declare c cursor for select a from t3; +open c; +if level < lim then +select level; +fetch c into lv; +select lv; +update t3 set a=level+lv; +FLUSH TABLES; +call bug10100pc(level+1, lim); +else +select * from t3; +end if; +close c; +end| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'FLUSH TABLES' at line 11 +set @@max_sp_recursion_depth=4| +select @@max_sp_recursion_depth| +@@max_sp_recursion_depth +4 +select bug10100f(3)| +ERROR HY000: Recursive stored functions are not allowed. +select bug10100f(6)| +ERROR HY000: Recursive stored functions are not allowed. +call bug10100t(5)| +res +120 +call bug10100pt(1,5)| +ERROR 42000: procedure test.bug10100pt does not exist +call bug10100pv(1,5)| +ERROR 42000: procedure test.bug10100pv does not exist +update t3 set a=1| +call bug10100pd(1,5)| +ERROR 42000: procedure test.bug10100pd does not exist +select * from t3| +a +1 +update t3 set a=1| +call bug10100pc(1,5)| +ERROR 42000: procedure test.bug10100pc does not exist +select * from t3| +a +1 +set @@max_sp_recursion_depth=0| +select @@max_sp_recursion_depth| +@@max_sp_recursion_depth +0 +select bug10100f(5)| +ERROR HY000: Recursive stored functions are not allowed. +call bug10100t(5)| +ERROR HY000: Recursive limit 0 (as set by the max_sp_recursion_depth variable) was exceeded for routine +deallocate prepare stmt2| +drop function bug10100f| +drop procedure bug10100p| +drop procedure bug10100t| +drop procedure bug10100pt| +ERROR 42000: PROCEDURE test.bug10100pt does not exist +drop procedure bug10100pv| +ERROR 42000: PROCEDURE test.bug10100pv does not exist +drop procedure bug10100pd| +ERROR 42000: PROCEDURE test.bug10100pd does not exist +drop procedure bug10100pc| +ERROR 42000: PROCEDURE test.bug10100pc does not exist +drop view v1| +drop procedure if exists bug13729| +drop table if exists t3| +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1),(2)| +create procedure bug13729() +begin +declare continue handler for sqlexception select 55; +update t3 set s1 = 1; +end| +call bug13729()| +55 +55 +select * from t3| +s1 +1 +2 +drop procedure bug13729| +drop table t3| +drop procedure if exists bug14643_1| +drop procedure if exists bug14643_2| +create procedure bug14643_1() +begin +declare continue handler for sqlexception select 'boo' as 'Handler'; +begin +declare v int default undefined_var; +if v = 1 then +select 1; +else +select v, isnull(v); +end if; +end; +end| +ERROR 42000: Undeclared variable: undefined_var +create procedure bug14643_2() +begin +declare continue handler for sqlexception select 'boo' as 'Handler'; +case undefined_var +when 1 then +select 1; +else +select 2; +end case; +select undefined_var; +end| +ERROR 42000: Undeclared variable: undefined_var +drop procedure if exists bug14304| +drop table if exists t3, t4| +create table t3(a int primary key auto_increment)| +create table t4(a int primary key auto_increment)| +create procedure bug14304() +begin +insert into t3 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 set a=null; +insert into t4 select null as a; +insert into t3 set a=null; +insert into t3 set a=null; +select * from t3; +end| +call bug14304()| +a +1 +2 +3 +drop procedure bug14304| +drop table t3, t4| +drop procedure if exists bug14376| +create procedure bug14376() +begin +declare x int default x; +end| +ERROR 42000: Undeclared variable: x +create procedure bug14376() +begin +declare x int default 42; +begin +declare x int default x; +select x; +end; +end| +call bug14376()| +x +42 +drop procedure bug14376| +create procedure bug14376(x int) +begin +declare x int default x; +select x; +end| +call bug14376(4711)| +x +4711 +drop procedure bug14376| +drop procedure if exists bug5967| +drop table if exists t3| +create table t3 (a varchar(255))| +insert into t3 (a) values ("a - table column")| +create procedure bug5967(a varchar(255)) +begin +declare i varchar(255); +declare c cursor for select a from t3; +select a; +select a from t3 into i; +select i as 'Parameter takes precedence over table column'; open c; +fetch c into i; +close c; +select i as 'Parameter takes precedence over table column in cursors'; +begin +declare a varchar(255) default 'a - local variable'; +declare c1 cursor for select a from t3; +select a as 'A local variable takes precedence over parameter'; +open c1; +fetch c1 into i; +close c1; +select i as 'A local variable takes precedence over parameter in cursors'; +begin +declare a varchar(255) default 'a - local variable in a nested compound statement'; +declare c2 cursor for select a from t3; +select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; +select a from t3 into i; +select i as 'A local variable in a nested compound statement takes precedence over table column'; +open c2; +fetch c2 into i; +close c2; +select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; +end; +end; +end| +call bug5967("a - stored procedure parameter")| +a +Parameter takes precedence over table column +Parameter takes precedence over table column in cursors +A local variable takes precedence over parameter +A local variable takes precedence over parameter in cursors +A local variable in a nested compound statement takes precedence over a local variable in the outer statement +A local variable in a nested compound statement takes precedence over table column +A local variable in a nested compound statement takes precedence over table column in cursors +a - stored procedure parameter +a - stored procedure parameter +a - stored procedure parameter +a - local variable +a - local variable +a - local variable in a nested compound statement +a - local variable in a nested compound statement +a - local variable in a nested compound statement +drop procedure bug5967| +drop procedure if exists bug13012| +create procedure bug13012() +BEGIN +REPAIR TABLE t1; +END| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'REPAIR TABLE t1' at line 3 +call bug13012()| +ERROR 42000: procedure test.bug13012 does not exist +drop procedure bug13012| +ERROR 42000: PROCEDURE test.bug13012 does not exist +create view v1 as select * from t1| +create procedure bug13012() +BEGIN +REPAIR TABLE t1,t2,t3,v1; +OPTIMIZE TABLE t1,t2,t3,v1; +ANALYZE TABLE t1,t2,t3,v1; +END| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'REPAIR TABLE t1,t2,t3,v1' at line 3 +call bug13012()| +ERROR 42000: procedure test.bug13012 does not exist +call bug13012()| +ERROR 42000: procedure test.bug13012 does not exist +call bug13012()| +ERROR 42000: procedure test.bug13012 does not exist +drop procedure bug13012| +ERROR 42000: PROCEDURE test.bug13012 does not exist +drop view v1| +select * from t1 order by data| +id data +aa 0 +aa 1 +aa 2 +aa 3 +aa 4 +aa 5 +aa 6 +aa 7 +aa 8 +aa 9 +drop schema if exists mysqltest1| +Warnings: +Note 1008 Can't drop database 'mysqltest1'; database doesn't exist +drop schema if exists mysqltest2| +Warnings: +Note 1008 Can't drop database 'mysqltest2'; database doesn't exist +drop schema if exists mysqltest3| +Warnings: +Note 1008 Can't drop database 'mysqltest3'; database doesn't exist +create schema mysqltest1| +create schema mysqltest2| +create schema mysqltest3| +use mysqltest3| +create procedure mysqltest1.p1 (out prequestid varchar(100)) +begin +call mysqltest2.p2('call mysqltest3.p3(1, 2)'); +end| +create procedure mysqltest2.p2(in psql varchar(1024)) +begin +declare lsql varchar(1024); +set @lsql= psql; +prepare lstatement from @lsql; +execute lstatement; +deallocate prepare lstatement; +end| +create procedure mysqltest3.p3(in p1 int) +begin +select p1; +end| +call mysqltest1.p1(@rs)| +ERROR 42000: Incorrect number of arguments +call mysqltest1.p1(@rs)| +ERROR 42000: Incorrect number of arguments +call mysqltest1.p1(@rs)| +ERROR 42000: Incorrect number of arguments +drop procedure mysqltest1.p1| +drop procedure mysqltest2.p2| +drop procedure mysqltest3.p3| +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +use test| +drop table if exists t3| +drop procedure if exists bug15441| +create table t3 (id int not null primary key, county varchar(25))| +insert into t3 (id, county) values (1, 'York')| +create procedure bug15441(c varchar(25)) +begin +update t3 set id=2, county=values(c); +end| +call bug15441('county')| +ERROR 42S22: Unknown column 'c' in 'field list' +drop procedure bug15441| +create procedure bug15441(county varchar(25)) +begin +declare c varchar(25) default "hello"; +insert into t3 (id, county) values (1, county) +on duplicate key update county= values(county); +select * from t3; +update t3 set id=2, county=values(id); +select * from t3; +end| +call bug15441('Yale')| +id county +id county +1 Yale +2 NULL +drop table t3| +drop procedure bug15441| +drop procedure if exists bug14498_1| +drop procedure if exists bug14498_2| +drop procedure if exists bug14498_3| +drop procedure if exists bug14498_4| +drop procedure if exists bug14498_5| +create procedure bug14498_1() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +if v then +select 'yes' as 'v'; +else +select 'no' as 'v'; +end if; +select 'done' as 'End'; +end| +ERROR 42000: Undeclared variable: v +create procedure bug14498_2() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +while v do +select 'yes' as 'v'; +end while; +select 'done' as 'End'; +end| +ERROR 42000: Undeclared variable: v +create procedure bug14498_3() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +repeat +select 'maybe' as 'v'; +until v end repeat; +select 'done' as 'End'; +end| +ERROR 42000: Undeclared variable: v +create procedure bug14498_4() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +case v +when 1 then +select '1' as 'v'; +when 2 then +select '2' as 'v'; +else +select '?' as 'v'; +end case; +select 'done' as 'End'; +end| +ERROR 42000: Undeclared variable: v +create procedure bug14498_5() +begin +declare continue handler for sqlexception select 'error' as 'Handler'; +case +when v = 1 then +select '1' as 'v'; +when v = 2 then +select '2' as 'v'; +else +select '?' as 'v'; +end case; +select 'done' as 'End'; +end| +ERROR 42000: Undeclared variable: v +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| +drop procedure if exists bug15231_5| +drop procedure if exists bug15231_6| +create table t3 (id int not null)| +create procedure bug15231_1() +begin +declare xid integer; +declare xdone integer default 0; +declare continue handler for not found set xdone = 1; +set xid=null; +call bug15231_2(xid); +select xid, xdone; +end| +create procedure bug15231_2(inout ioid integer) +begin +select "Before NOT FOUND condition is triggered" as '1'; +select id from t3 where id=ioid into ioid; +select "After NOT FOUND condtition is triggered" as '2'; +if ioid is null then +set ioid=1; +end if; +end| +create procedure bug15231_3() +begin +declare exit handler for sqlwarning +select 'Caught it (correct)' as 'Result'; +call bug15231_4(); +end| +create procedure bug15231_4() +begin +declare x decimal(2,1); +set x = 'zap'; +select 'Missed it (correct)' as 'Result'; +show warnings; +end| +create procedure bug15231_5() +begin +declare exit handler for sqlwarning +select 'Caught it (wrong)' as 'Result'; +call bug15231_6(); +end| +create procedure bug15231_6() +begin +declare x decimal(2,1); +set x = 'zap'; +select 'Missed it (correct)' as 'Result'; +select id from t3; +end| +call bug15231_1()| +1 +2 +xid xdone +Before NOT FOUND condition is triggered +After NOT FOUND condtition is triggered +1 0 +call bug15231_3()| +Result +Level Code Message +Missed it (correct) +call bug15231_5()| +Result +id +Missed it (correct) +drop table t3| +drop procedure bug15231_1| +drop procedure bug15231_2| +drop procedure bug15231_3| +drop procedure bug15231_4| +drop procedure bug15231_5| +drop procedure bug15231_6| +drop procedure if exists bug15011| +create table t3 (c1 int primary key)| +insert into t3 values (1)| +create procedure bug15011() +deterministic +begin +declare continue handler for 1062 +select 'Outer' as 'Handler'; +begin +declare continue handler for 1062 +select 'Inner' as 'Handler'; +insert into t3 values (1); +end; +end| +call bug15011()| +Handler +Inner +drop procedure bug15011| +drop table t3| +drop procedure if exists bug17476| +create table t3 ( d date )| +insert into t3 values +( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ), +( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )| +create procedure bug17476(pDateFormat varchar(10)) +select date_format(t3.d, pDateFormat), count(*) +from t3 +group by date_format(t3.d, pDateFormat)| +call bug17476('%Y-%m')| +date_format(t3.d, pDateFormat) count(*) +2005-01 4 +2005-02 2 +call bug17476('%Y-%m')| +date_format(t3.d, pDateFormat) count(*) +2005-01 4 +2005-02 2 +drop table t3| +drop procedure bug17476| +drop table if exists t3| +drop procedure if exists bug16887| +create table t3 ( c varchar(1) )| +insert into t3 values +(' '),('.'),(';'),(','),('-'),('_'),('('),(')'),('/'),('\\')| +create procedure bug16887() +begin +declare i int default 10; +again: +while i > 0 do +begin +declare breakchar varchar(1); +declare done int default 0; +declare t3_cursor cursor for select c from t3; +declare continue handler for not found set done = 1; +set i = i - 1; +select i; +if i = 3 then +iterate again; +end if; +open t3_cursor; +loop +fetch t3_cursor into breakchar; +if done = 1 then +begin +close t3_cursor; +iterate again; +end; +end if; +end loop; +end; +end while; +end| +call bug16887()| +i +i +i +i +i +i +i +i +i +i +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 +drop table t3| +drop procedure bug16887| +drop procedure if exists bug16474_1| +drop procedure if exists bug16474_2| +delete from t1| +insert into t1 values ('c', 2), ('b', 3), ('a', 1)| +create procedure bug16474_1() +begin +declare x int; +select id from t1 order by x, id; +end| +drop procedure if exists bug14945| +create table t3 (id int not null auto_increment primary key)| +create procedure bug14945() deterministic truncate t3| +insert into t3 values (null)| +call bug14945()| +insert into t3 values (null)| +select * from t3| +id +1 +drop table t3| +drop procedure bug14945| +create procedure bug16474_2(x int) +select id from t1 order by x, id| +call bug16474_1()| +id +a +b +c +call bug16474_2(1)| +id +a +b +c +call bug16474_2(2)| +id +a +b +c +drop procedure bug16474_1| +drop procedure bug16474_2| +set @x = 2| +select * from t1 order by @x, data| +id data +a 1 +c 2 +b 3 +delete from t1| +drop function if exists bug15728| +drop table if exists t3| +create table t3 ( +id int not null auto_increment, +primary key (id) +)| +create function bug15728() returns int(11) +return last_insert_id()| +insert into t3 values (0)| +select last_insert_id()| +last_insert_id() +1 +select bug15728()| +bug15728() +0 +drop function bug15728| +drop table t3| +drop procedure if exists bug18787| +create procedure bug18787() +begin +declare continue handler for sqlexception begin end; +select no_such_function(); +end| +call bug18787()| +drop procedure bug18787| +create database bug18344_012345678901| +use bug18344_012345678901| +create procedure bug18344() begin end| +create procedure bug18344_2() begin end| +create database bug18344_0123456789012| +use bug18344_0123456789012| +create procedure bug18344() begin end| +create procedure bug18344_2() begin end| +use test| +select schema_name from information_schema.schemata where +schema_name like 'bug18344%'| +schema_name +bug18344_012345678901 +bug18344_0123456789012 +select routine_name,routine_schema from information_schema.routines where +routine_schema like 'bug18344%'| +routine_name routine_schema +bug18344 bug18344_012345678901 +bug18344_2 bug18344_012345678901 +bug18344 bug18344_0123456789012 +bug18344_2 bug18344_0123456789012 +drop database bug18344_012345678901| +drop database bug18344_0123456789012| +select schema_name from information_schema.schemata where +schema_name like 'bug18344%'| +schema_name +select routine_name,routine_schema from information_schema.routines where +routine_schema like 'bug18344%'| +routine_name routine_schema +drop function if exists bug12472| +create function bug12472() returns int return (select count(*) from t1)| +show create table t3| +ERROR 42S02: Table 'test.t3' doesn't exist +select * from t3| +ERROR 42S02: Table 'test.t3' doesn't exist +drop table t3| +ERROR 42S02: Unknown table 'test.t3' +create view v1 as select bug12472() as j| +create table t3 as select * from v1| +show create table t3| +Table Create Table +t3 CREATE TABLE `t3` ( + `j` int(11) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 +select * from t3| +j +0 +drop table t3| +drop view v1| +drop function bug12472| +DROP FUNCTION IF EXISTS bug18589_f1| +DROP PROCEDURE IF EXISTS bug18589_p1| +DROP PROCEDURE IF EXISTS bug18589_p2| +CREATE FUNCTION bug18589_f1(arg varchar(1024)) RETURNS varchar(1024) +BEGIN +RETURN CONCAT(arg, ""); +END| +CREATE PROCEDURE bug18589_p1(arg varchar(1024), OUT ret varchar(1024)) +BEGIN +SET ret = CONCAT(arg, ""); +END| +CREATE PROCEDURE bug18589_p2(arg varchar(1024)) +BEGIN +DECLARE v varchar(1024); +CALL bug18589_p1(arg, v); +SELECT v; +END| +SELECT bug18589_f1(REPEAT("a", 767))| +bug18589_f1(REPEAT("a", 767)) +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +SET @bug18589_v1 = ""| +CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)| +ret +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +SELECT @bug18589_v1| +@bug18589_v1 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +CALL bug18589_p2(REPEAT("a", 767))| +v +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +DROP FUNCTION bug18589_f1| +DROP PROCEDURE bug18589_p1| +DROP PROCEDURE bug18589_p2| +DROP FUNCTION IF EXISTS bug18037_f1| +DROP PROCEDURE IF EXISTS bug18037_p1| +DROP PROCEDURE IF EXISTS bug18037_p2| +CREATE FUNCTION bug18037_f1() RETURNS INT +BEGIN +RETURN @@ob_org_cluster_id; +END| +CREATE PROCEDURE bug18037_p1() +BEGIN +DECLARE v INT DEFAULT @@ob_org_cluster_id; +END| +CREATE PROCEDURE bug18037_p2() +BEGIN +CASE @@ob_org_cluster_id +WHEN -1 THEN +SELECT 0; +ELSE +SELECT 1; +END CASE; +END| +SELECT bug18037_f1()| +bug18037_f1() +0 +CALL bug18037_p1()| +CALL bug18037_p2()| +1 +1 +DROP FUNCTION bug18037_f1| +DROP PROCEDURE bug18037_p1| +DROP PROCEDURE bug18037_p2| +use test| +create table t3 (i int)| +insert into t3 values (1), (2)| +create database mysqltest1| +use mysqltest1| +create function bug17199() returns varchar(2) deterministic return 'ok'| +use test| +select *, mysqltest1.bug17199() from t3| +i mysqltest1.bug17199() +1 ok +2 ok +use mysqltest1| +create function bug18444(i int) returns int no sql deterministic return i + 1| +use test| +select mysqltest1.bug18444(i) from t3| +mysqltest1.bug18444(i) +2 +3 +drop database mysqltest1| +create database mysqltest1 charset=utf8| +create database mysqltest2 charset=utf8| +create procedure mysqltest1.p1() +begin +-- alters the default collation of database test +alter database character set koi8r; +end| +use mysqltest1| +call p1()| +ERROR 42000: Unknown character set: 'koi8r' +drop procedure mysqltest1.p1| +create procedure mysqltest1.p1() +begin +-- alters the default collation of database test +alter database character set binary; +end| +show create database mysqltest1| +Database Create Database +mysqltest1 CREATE DATABASE `mysqltest1` DEFAULT CHARACTER SET = utf8mb4 REPLICA_NUM = NUM +show create database mysqltest2| +Database Create Database +mysqltest2 CREATE DATABASE `mysqltest2` DEFAULT CHARACTER SET = utf8mb4 REPLICA_NUM = NUM +alter database mysqltest1 character set utf8| +use mysqltest2| +call mysqltest1.p1()| +show create database mysqltest1| +Database Create Database +mysqltest1 CREATE DATABASE `mysqltest1` DEFAULT CHARACTER SET = binary REPLICA_NUM = NUM +show create database mysqltest2| +Database Create Database +mysqltest2 CREATE DATABASE `mysqltest2` DEFAULT CHARACTER SET = utf8mb4 REPLICA_NUM = NUM +drop procedure mysqltest1.p1| +drop database mysqltest1| +drop database mysqltest2| +use test| +drop table if exists t3| +drop procedure if exists bug15217| +create table t3 as select 1| +create procedure bug15217() +begin +declare var1 char(255); +declare cur1 cursor for select * from t3; +open cur1; +fetch cur1 into var1; +select concat('data was: /', var1, '/'); +close cur1; +end | +call bug15217()| +concat('data was: /', var1, '/') +data was: /1/ +flush tables | +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'flush tables' at line 1 +call bug15217()| +concat('data was: /', var1, '/') +data was: /1/ +drop table t3| +drop procedure bug15217| +DROP PROCEDURE IF EXISTS bug21013 | +CREATE PROCEDURE bug21013(IN lim INT) +BEGIN +DECLARE i INT DEFAULT 0; +WHILE (i < lim) DO +SET @b = LOCATE(_utf8mb4'b', @a, 1); +SET i = i + 1; +END WHILE; +END | +SET @a = _utf8mb4"aaaaaaaaaa" | +CALL bug21013(10) | +DROP PROCEDURE bug21013 | +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8| +use mysqltest1| +CREATE FUNCTION bug16211_f1() RETURNS CHAR(10) +RETURN ""| +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r +RETURN ""| +ERROR 42000: Unknown character set: 'koi8r' +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET binary +RETURN ""| +CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10) +RETURN ""| +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r +RETURN ""| +ERROR 42000: Unknown character set: 'koi8r' +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET binary +RETURN ""| +SHOW CREATE FUNCTION bug16211_f1| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f1 CREATE DEFINER = admin@% FUNCTION `mysqltest1`.`bug16211_f1` +() + RETURNS char(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SHOW CREATE FUNCTION bug16211_f2| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f2 CREATE DEFINER = admin@% FUNCTION `mysqltest1`.`bug16211_f2` +() + RETURNS binary(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f3 CREATE DEFINER = admin@% FUNCTION `mysqltest2`.`bug16211_f3` +() + RETURNS char(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f4 CREATE DEFINER = admin@% FUNCTION `mysqltest2`.`bug16211_f4` +() + RETURNS binary(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| +dtd_identifier +NULL +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| +dtd_identifier +NULL +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| +dtd_identifier +NULL +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| +dtd_identifier +NULL +SELECT CHARSET(bug16211_f1())| +CHARSET(bug16211_f1()) +utf8mb4 +SELECT CHARSET(bug16211_f2())| +CHARSET(bug16211_f2()) +binary +SELECT CHARSET(mysqltest2.bug16211_f3())| +CHARSET(mysqltest2.bug16211_f3()) +utf8mb4 +SELECT CHARSET(mysqltest2.bug16211_f4())| +CHARSET(mysqltest2.bug16211_f4()) +binary +ALTER DATABASE mysqltest1 CHARACTER SET cp1251| +ERROR 42000: Unknown character set: 'cp1251' +ALTER DATABASE mysqltest1 CHARACTER SET utf8mb4| +ALTER DATABASE mysqltest2 CHARACTER SET cp1251| +ERROR 42000: Unknown character set: 'cp1251' +ALTER DATABASE mysqltest2 CHARACTER SET utf8mb4| +SHOW CREATE FUNCTION bug16211_f1| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f1 CREATE DEFINER = admin@% FUNCTION `mysqltest1`.`bug16211_f1` +() + RETURNS char(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SHOW CREATE FUNCTION bug16211_f2| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f2 CREATE DEFINER = admin@% FUNCTION `mysqltest1`.`bug16211_f2` +() + RETURNS binary(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f3 CREATE DEFINER = admin@% FUNCTION `mysqltest2`.`bug16211_f3` +() + RETURNS char(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| +Function sql_mode Create Function character_set_client collation_connection Database Collation +bug16211_f4 CREATE DEFINER = admin@% FUNCTION `mysqltest2`.`bug16211_f4` +() + RETURNS binary(10) RETURN "" utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| +dtd_identifier +NULL +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| +dtd_identifier +NULL +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| +dtd_identifier +NULL +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| +dtd_identifier +NULL +SELECT CHARSET(bug16211_f1())| +CHARSET(bug16211_f1()) +utf8mb4 +SELECT CHARSET(bug16211_f2())| +CHARSET(bug16211_f2()) +binary +SELECT CHARSET(mysqltest2.bug16211_f3())| +CHARSET(mysqltest2.bug16211_f3()) +utf8mb4 +SELECT CHARSET(mysqltest2.bug16211_f4())| +CHARSET(mysqltest2.bug16211_f4()) +binary +use test| +DROP DATABASE mysqltest1| +DROP DATABASE mysqltest2| +DROP DATABASE IF EXISTS mysqltest1| +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +use mysqltest1| +CREATE PROCEDURE bug16676_p1( +IN p1 CHAR(10), +INOUT p2 CHAR(10), +OUT p3 CHAR(10)) +BEGIN +SELECT CHARSET(p1), COLLATION(p1); +SELECT CHARSET(p2), COLLATION(p2); +SELECT CHARSET(p3), COLLATION(p3); +END| +CREATE PROCEDURE bug16676_p2( +IN p1 CHAR(10) CHARSET koi8r, +INOUT p2 CHAR(10) CHARSET cp1251, +OUT p3 CHAR(10) CHARSET greek) +BEGIN +SELECT CHARSET(p1), COLLATION(p1); +SELECT CHARSET(p2), COLLATION(p2); +SELECT CHARSET(p3), COLLATION(p3); +END| +ERROR 42000: Unknown character set: 'koi8r' +CREATE PROCEDURE bug16676_p2( +IN p1 CHAR(10) CHARSET binary, +INOUT p2 CHAR(10) CHARSET binary, +OUT p3 CHAR(10) CHARSET binary) +BEGIN +SELECT CHARSET(p1), COLLATION(p1); +SELECT CHARSET(p2), COLLATION(p2); +SELECT CHARSET(p3), COLLATION(p3); +END| +SET @v2 = 'b'| +SET @v3 = 'c'| +CALL bug16676_p1('a', @v2, @v3)| +CHARSET(p1) COLLATION(p1) +CHARSET(p2) COLLATION(p2) +CHARSET(p3) COLLATION(p3) +p2 p3 +utf8mb4 utf8mb4_general_ci +utf8mb4 utf8mb4_general_ci +binary binary +b NULL +CALL bug16676_p2('a', @v2, @v3)| +CHARSET(p1) COLLATION(p1) +CHARSET(p2) COLLATION(p2) +CHARSET(p3) COLLATION(p3) +p2 p3 +binary binary +binary binary +binary binary +b NULL +use test| +DROP DATABASE mysqltest1| +drop table if exists t3| +drop table if exists t4| +drop procedure if exists bug8153_subselect| +drop procedure if exists bug8153_subselect_a| +drop procedure if exists bug8153_subselect_b| +drop procedure if exists bug8153_proc_a| +drop procedure if exists bug8153_proc_b| +create table t3 (a int)| +create table t4 (a int)| +insert into t3 values (1), (1), (2), (3)| +insert into t4 values (1), (1)| +create procedure bug8153_subselect() +begin +declare continue handler for sqlexception +begin +select 'statement failed'; +end; +update t3 set a=a+1 where (select a from t4 where a=1) is null; +select 'statement after update'; +end| +call bug8153_subselect()| +statement failed +statement after update +statement failed +statement after update +select * from t3| +a +1 +1 +2 +3 +call bug8153_subselect()| +statement failed +statement after update +statement failed +statement after update +select * from t3| +a +1 +1 +2 +3 +drop procedure bug8153_subselect| +create procedure bug8153_subselect_a() +begin +declare continue handler for sqlexception +begin +select 'in continue handler'; +end; +select 'reachable code a1'; +call bug8153_subselect_b(); +select 'reachable code a2'; +end| +create procedure bug8153_subselect_b() +begin +select 'reachable code b1'; +update t3 set a=a+1 where (select a from t4 where a=1) is null; +select 'unreachable code b2'; +end| +call bug8153_subselect_a()| +reachable code a1 +reachable code b1 +in continue handler +reachable code a2 +reachable code a1 +reachable code b1 +in continue handler +reachable code a2 +select * from t3| +a +1 +1 +2 +3 +call bug8153_subselect_a()| +reachable code a1 +reachable code b1 +in continue handler +reachable code a2 +reachable code a1 +reachable code b1 +in continue handler +reachable code a2 +select * from t3| +a +1 +1 +2 +3 +drop procedure bug8153_subselect_a| +drop procedure bug8153_subselect_b| +create procedure bug8153_proc_a() +begin +declare continue handler for sqlexception +begin +select 'in continue handler'; +end; +select 'reachable code a1'; +call bug8153_proc_b(); +select 'reachable code a2'; +end| +create procedure bug8153_proc_b() +begin +select 'reachable code b1'; +select no_such_function(); +select 'unreachable code b2'; +end| +call bug8153_proc_a()| +reachable code a1 +reachable code b1 +in continue handler +reachable code a2 +reachable code a1 +reachable code b1 +in continue handler +reachable code a2 +drop procedure bug8153_proc_a| +drop procedure bug8153_proc_b| +drop table t3| +drop table t4| +drop procedure if exists bug19862| +DROP TABLE if exists t11| +DROP TABLE if exists t12| +DROP FUNCTION if exists bug19862| +CREATE TABLE t11 (a INT)| +CREATE TABLE t12 (a INT)| +drop function if exists bug19862| +CREATE FUNCTION bug19862(x INT) RETURNS INT +BEGIN +INSERT INTO t11 VALUES (x); +RETURN x+1; +END| +INSERT INTO t12 VALUES (1), (2)| +SELECT bug19862(a) FROM t12 ORDER BY 1| +bug19862(a) +2 +3 +SELECT * FROM t11| +a +1 +2 +DROP TABLE t11, t12| +DROP FUNCTION bug19862| +drop table if exists t3| +drop database if exists mysqltest1| +create table t3 (a int)| +insert into t3 (a) values (1), (2)| +create database mysqltest1| +use mysqltest1| +drop database mysqltest1| +select database()| +database() +NULL +select * from (select 1 as a) as t1 natural join (select * from test.t3) as t2| +a +1 +use test| +drop table t3| +DROP PROCEDURE IF EXISTS bug16899_p1| +DROP FUNCTION IF EXISTS bug16899_f1| +CREATE DEFINER=1234567890abcdefGHIKL@localhost PROCEDURE bug16899_p1() +BEGIN +SET @a = 1; +END| +Warnings: +Warning 1449 User not exist +CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY +FUNCTION bug16899_f1() RETURNS INT +BEGIN +RETURN 1; +END| +Warnings: +Warning 1449 User not exist +DROP PROCEDURE bug16899_p1| +DROP FUNCTION bug16899_f1| +drop procedure if exists bug21416| +create procedure bug21416() show create procedure bug21416| +call bug21416()| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +bug21416 CREATE DEFINER = admin@% PROCEDURE `test`.`bug21416` +() + show create procedure bug21416 utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure bug21416| +DROP PROCEDURE IF EXISTS bug21414| +CREATE PROCEDURE bug21414() SELECT 1| +FLUSH TABLES WITH READ LOCK| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'FLUSH TABLES WITH READ LOCK' at line 1 +DROP PROCEDURE bug21414| +UNLOCK TABLES| +The following should succeed. +DROP PROCEDURE bug21414| +ERROR 42000: PROCEDURE test.bug21414 does not exist +set names utf8| +drop database if exists това_е_дълго_име_за_база_данни_нали| +create database това_е_дълго_име_за_база_данни_нали| +INSERT INTO mysql.proc VALUES ('това_е_дълго_име_за_база_данни_нали','това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго','PROCEDURE','това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго','SQL','CONTAINS_SQL','NO','DEFINER','','','bad_body','root@localhost',now(), now(),'','', 'utf8', 'utf8_general_ci', 'utf8_general_ci', 'n/a')| +call това_е_дълго_име_за_база_данни_нали.това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго()| +ERROR 42000: procedure това_е_дълго_име_за_база_данни_нали.това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго does not exist +drop database това_е_дълго_име_за_база_данни_нали| +CREATE TABLE t3 ( +Member_ID varchar(15) NOT NULL, +PRIMARY KEY (Member_ID) +)| +CREATE TABLE t4 ( +ID int(10) unsigned NOT NULL auto_increment, +Member_ID varchar(15) NOT NULL default '', +Action varchar(12) NOT NULL, +Action_Date datetime NOT NULL, +Track varchar(15) default NULL, +User varchar(12) default NULL, +Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update +CURRENT_TIMESTAMP, +PRIMARY KEY (ID), +KEY Action (Action), +KEY Action_Date (Action_Date) +)| +INSERT INTO t3(Member_ID) VALUES +('111111'), ('222222'), ('333333'), ('444444'), ('555555'), ('666666')| +INSERT INTO t4(Member_ID, Action, Action_Date, Track) VALUES +('111111', 'Disenrolled', '2006-03-01', 'CAD' ), +('111111', 'Enrolled', '2006-03-01', 'CAD' ), +('111111', 'Disenrolled', '2006-07-03', 'CAD' ), +('222222', 'Enrolled', '2006-03-07', 'CAD' ), +('222222', 'Enrolled', '2006-03-07', 'CHF' ), +('222222', 'Disenrolled', '2006-08-02', 'CHF' ), +('333333', 'Enrolled', '2006-03-01', 'CAD' ), +('333333', 'Disenrolled', '2006-03-01', 'CAD' ), +('444444', 'Enrolled', '2006-03-01', 'CAD' ), +('555555', 'Disenrolled', '2006-03-01', 'CAD' ), +('555555', 'Enrolled', '2006-07-21', 'CAD' ), +('555555', 'Disenrolled', '2006-03-01', 'CHF' ), +('666666', 'Enrolled', '2006-02-09', 'CAD' ), +('666666', 'Enrolled', '2006-05-12', 'CHF' ), +('666666', 'Disenrolled', '2006-06-01', 'CAD' )| +DROP FUNCTION IF EXISTS bug21493| +CREATE FUNCTION bug21493(paramMember VARCHAR(15)) RETURNS varchar(45) +BEGIN +DECLARE tracks VARCHAR(45); +SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t4 +WHERE Member_ID=paramMember AND Action='Enrolled' AND +(Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t4 +WHERE Member_ID=paramMember GROUP BY Track) INTO tracks; +RETURN tracks; +END| +SELECT bug21493('111111')| +bug21493('111111') +NULL +SELECT bug21493('222222')| +bug21493('222222') +CAD +SELECT bug21493(Member_ID) FROM t3| +bug21493(Member_ID) +NULL +CAD +CAD +CAD +CAD +CHF +DROP FUNCTION bug21493| +DROP TABLE t3,t4| +drop function if exists func_20028_a| +drop function if exists func_20028_b| +drop function if exists func_20028_c| +drop procedure if exists proc_20028_a| +drop procedure if exists proc_20028_b| +drop procedure if exists proc_20028_c| +drop table if exists table_20028| +create table table_20028 (i int)| +SET @save_sql_mode=@@sql_mode| +SET sql_mode=''| +create function func_20028_a() returns integer +begin +declare temp integer; +select i from table_20028 limit 1 into temp; +return ifnull(temp, 0); +end| +create function func_20028_b() returns integer +begin +return func_20028_a(); +end| +create function func_20028_c() returns integer +begin +declare div_zero integer; +# set SQL_MODE='TRADITIONAL'; +set SQL_MODE='ONLY_FULL_GROUP_BY'; +select 1/0 into div_zero; +return div_zero; +end| +create procedure proc_20028_a() +begin +declare temp integer; +select i from table_20028 limit 1 into temp; +end| +create procedure proc_20028_b() +begin +call proc_20028_a(); +end| +create procedure proc_20028_c() +begin +declare div_zero integer; +# set SQL_MODE='TRADITIONAL'; +set SQL_MODE='ONLY_FULL_GROUP_BY'; +select 1/0 into div_zero; +end| +select func_20028_a()| +func_20028_a() +0 +select func_20028_b()| +func_20028_b() +0 +select func_20028_c()| +func_20028_c() +NULL +call proc_20028_a()| +call proc_20028_b()| +call proc_20028_c()| +set SQL_MODE='ONLY_FULL_GROUP_BY'; +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +create function func_20028_a() returns integer +begin +declare temp integer; +select i from table_20028 limit 1 into temp; +return ifnull(temp, 0); +end| +create function func_20028_b() returns integer +begin +return func_20028_a(); +end| +create function func_20028_c() returns integer +begin +declare div_zero integer; +set SQL_MODE=''; +select 1/0 into div_zero; +return div_zero; +end| +create procedure proc_20028_a() +begin +declare temp integer; +select i from table_20028 limit 1 into temp; +end| +create procedure proc_20028_b() +begin +call proc_20028_a(); +end| +create procedure proc_20028_c() +begin +declare div_zero integer; +set SQL_MODE=''; +select 1/0 into div_zero; +end| +select func_20028_a()| +func_20028_a() +0 +select func_20028_b()| +func_20028_b() +0 +select func_20028_c()| +func_20028_c() +NULL +call proc_20028_a()| +call proc_20028_b()| +call proc_20028_c()| +SET @@sql_mode=@save_sql_mode| +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +drop table table_20028| +drop procedure if exists proc_21462_a| +drop procedure if exists proc_21462_b| +create procedure proc_21462_a() +begin +select "Called A"; +end| +create procedure proc_21462_b(x int) +begin +select "Called B"; +end| +call proc_21462_a| +Called A +Called A +call proc_21462_a()| +Called A +Called A +call proc_21462_a(1)| +ERROR 42000: Incorrect number of arguments +call proc_21462_b| +ERROR 42000: Incorrect number of arguments +call proc_21462_b()| +ERROR 42000: Incorrect number of arguments +call proc_21462_b(1)| +Called B +Called B +drop procedure proc_21462_a| +drop procedure proc_21462_b| +drop table if exists t3| +drop procedure if exists proc_bug19733| +create table t3 (s1 int)| +create procedure proc_bug19733() +begin +declare v int default 0; +while v < 5 do +create index i on t3 (s1); +drop index i on t3; +set v = v + 1; +end while; +end| +set ob_query_timeout=10000000000; +call proc_bug19733()| +call proc_bug19733()| +call proc_bug19733()| +set ob_query_timeout=default; +drop procedure proc_bug19733| +drop table t3| +DROP PROCEDURE IF EXISTS p1| +DROP VIEW IF EXISTS v1, v2| +DROP TABLE IF EXISTS t3, t4| +CREATE TABLE t3 (t3_id INT)| +INSERT INTO t3 VALUES (0)| +INSERT INTO t3 VALUES (1)| +CREATE TABLE t4 (t4_id INT)| +INSERT INTO t4 VALUES (2)| +CREATE VIEW v1 AS +SELECT t3.t3_id, t4.t4_id +FROM t3 JOIN t4 ON t3.t3_id = 0| +CREATE VIEW v2 AS +SELECT t3.t3_id AS t3_id_1, v1.t3_id AS t3_id_2, v1.t4_id +FROM t3 LEFT JOIN v1 ON t3.t3_id = 0| +CREATE PROCEDURE p1() SELECT * FROM v2| +CALL p1()| +t3_id_1 t3_id_2 t4_id +0 0 2 +1 NULL NULL +CALL p1()| +t3_id_1 t3_id_2 t4_id +0 0 2 +1 NULL NULL +DROP PROCEDURE p1| +DROP VIEW v1, v2| +DROP TABLE t3, t4| +End of 5.0 tests +Begin of 5.1 tests +drop function if exists pi; +create function pi() returns varchar(50) +return "pie, my favorite desert."; +SET @save_sql_mode=@@sql_mode; +SET SQL_MODE='IGNORE_SPACE'; +ERROR 0A000: Not supported feature or function +select pi(), pi (); +pi() pi () +3.141593 3.141593 +select test.pi(), test.pi (); +test.pi() test.pi () +pie, my favorite desert. pie, my favorite desert. +SET SQL_MODE=''; +select pi(), pi (); +pi() pi () +3.141593 3.141593 +select test.pi(), test.pi (); +test.pi() test.pi () +pie, my favorite desert. pie, my favorite desert. +SET @@sql_mode=@save_sql_mode; +drop function pi; +drop function if exists test.database; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'database' at line 1 +drop function if exists test.current_user; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'current_user' at line 1 +drop function if exists test.md5; +create database nowhere; +use nowhere; +drop database nowhere; +SET @save_sql_mode=@@sql_mode; +SET SQL_MODE='IGNORE_SPACE'; +ERROR 0A000: Not supported feature or function +select database(), database (); +database() database () +NULL NULL +select current_user(), current_user (); +current_user() current_user () +admin@% admin@% +select md5("aaa"), md5 ("aaa"); +md5("aaa") md5 ("aaa") +47bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 +SET SQL_MODE=''; +select database(), database (); +database() database () +NULL NULL +select current_user(), current_user (); +current_user() current_user () +admin@% admin@% +select md5("aaa"), md5 ("aaa"); +md5("aaa") md5 ("aaa") +47bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 +use test; +drop function if exists `database`; +drop function if exists `current_user`; +drop function if exists `md5`; +create function `database`() returns varchar(50) +return "Stored function database"; +create function `current_user`() returns varchar(50) +return "Stored function current_user"; +create function md5(x varchar(50)) returns varchar(50) +return "Stored function md5"; +SET SQL_MODE='IGNORE_SPACE'; +ERROR 0A000: Not supported feature or function +select database(), database (); +database() database () +test test +select current_user(), current_user (); +current_user() current_user () +admin@% admin@% +select md5("aaa"), md5 ("aaa"); +md5("aaa") md5 ("aaa") +47bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 +select test.database(), test.database (); +test.database() test.database () +Stored function database Stored function database +select test.current_user(), test.current_user (); +test.current_user() test.current_user () +Stored function current_user Stored function current_user +select test.md5("aaa"), test.md5 ("aaa"); +test.md5("aaa") test.md5 ("aaa") +Stored function md5 Stored function md5 +SET SQL_MODE=''; +select database(), database (); +database() database () +test test +select current_user(), current_user (); +current_user() current_user () +admin@% admin@% +select md5("aaa"), md5 ("aaa"); +md5("aaa") md5 ("aaa") +47bce5c74f589f4867dbd57e9ca9f808 47bce5c74f589f4867dbd57e9ca9f808 +select test.database(), test.database (); +test.database() test.database () +Stored function database Stored function database +select test.current_user(), test.current_user (); +test.current_user() test.current_user () +Stored function current_user Stored function current_user +select test.md5("aaa"), test.md5 ("aaa"); +test.md5("aaa") test.md5 ("aaa") +Stored function md5 Stored function md5 +SET @@sql_mode=@save_sql_mode; +drop function test.database; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'database' at line 1 +drop function test.current_user; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'current_user' at line 1 +drop function md5; +use test; +End of 5.1 tests +DROP TABLE IF EXISTS bug23760| +DROP TABLE IF EXISTS bug23760_log| +DROP PROCEDURE IF EXISTS bug23760_update_log| +DROP PROCEDURE IF EXISTS bug23760_test_row_count| +DROP FUNCTION IF EXISTS bug23760_rc_test| +CREATE TABLE bug23760 ( +id INT NOT NULL AUTO_INCREMENT , +num INT NOT NULL , +PRIMARY KEY ( id ) +)| +CREATE TABLE bug23760_log ( +id INT NOT NULL AUTO_INCREMENT , +reason VARCHAR(50)NULL , +ammount INT NOT NULL , +PRIMARY KEY ( id ) +)| +CREATE PROCEDURE bug23760_update_log(r Varchar(50), a INT) +BEGIN +INSERT INTO bug23760_log (reason, ammount) VALUES(r, a); +END| +CREATE PROCEDURE bug23760_test_row_count() +BEGIN +UPDATE bug23760 SET num = num + 1; +CALL bug23760_update_log('Test is working', ROW_COUNT()); +UPDATE bug23760 SET num = num - 1; +END| +CREATE PROCEDURE bug23760_test_row_count2(level INT) +BEGIN +IF level THEN +UPDATE bug23760 SET num = num + 1; +CALL bug23760_update_log('Test2 is working', ROW_COUNT()); +CALL bug23760_test_row_count2(level - 1); +END IF; +END| +CREATE FUNCTION bug23760_rc_test(in_var INT) RETURNS INT RETURN in_var| +INSERT INTO bug23760 (num) VALUES (0), (1), (1), (2), (3), (5), (8)| +SELECT ROW_COUNT()| +ROW_COUNT() +7 +CALL bug23760_test_row_count()| +SELECT * FROM bug23760_log ORDER BY id| +id reason ammount +1 Test is working 7 +SET @save_max_sp_recursion= @@max_sp_recursion_depth| +SELECT @save_max_sp_recursion| +@save_max_sp_recursion +0 +SET max_sp_recursion_depth= 5| +SELECT @@max_sp_recursion_depth| +@@max_sp_recursion_depth +5 +CALL bug23760_test_row_count2(2)| +SELECT ROW_COUNT()| +ROW_COUNT() +1 +SELECT * FROM bug23760_log ORDER BY id| +id reason ammount +1 Test is working 7 +2 Test2 is working 7 +3 Test2 is working 7 +SELECT * FROM bug23760 ORDER by ID| +id num +1 2 +2 3 +3 3 +4 4 +5 5 +6 7 +7 10 +SET max_sp_recursion_depth= @save_max_sp_recursion| +SELECT bug23760_rc_test(123)| +bug23760_rc_test(123) +123 +INSERT INTO bug23760 (num) VALUES (13), (21), (34), (55)| +SELECT bug23760_rc_test(ROW_COUNT())| +bug23760_rc_test(ROW_COUNT()) +4 +DROP TABLE bug23760, bug23760_log| +DROP PROCEDURE bug23760_update_log| +DROP PROCEDURE bug23760_test_row_count| +DROP PROCEDURE bug23760_test_row_count2| +DROP FUNCTION bug23760_rc_test| +DROP PROCEDURE IF EXISTS bug24117| +DROP TABLE IF EXISTS t3| +CREATE TABLE t3(c1 ENUM('abc'))| +INSERT INTO t3 VALUES('abc')| +CREATE PROCEDURE bug24117() +BEGIN +DECLARE t3c1 ENUM('abc'); +DECLARE mycursor CURSOR FOR SELECT c1 FROM t3; +OPEN mycursor; +FLUSH TABLES; +FETCH mycursor INTO t3c1; +CLOSE mycursor; +END| +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near 'FLUSH TABLES' at line 6 +CREATE PROCEDURE bug24117() +BEGIN +DECLARE t3c1 ENUM('abc'); +DECLARE mycursor CURSOR FOR SELECT c1 FROM t3; +OPEN mycursor; +FETCH mycursor INTO t3c1; +CLOSE mycursor; +END| +CALL bug24117()| +DROP PROCEDURE bug24117| +DROP TABLE t3| +drop function if exists func_8407_a| +drop function if exists func_8407_b| +create function func_8407_a() returns int +begin +declare x int; +declare continue handler for sqlexception +begin +end; +select 1 from no_such_view limit 1 into x; +return x; +end| +create function func_8407_b() returns int +begin +declare x int default 0; +declare continue handler for sqlstate '42S02' + begin +set x:= x+1000; +end; +case (select 1 from no_such_view limit 1) +when 1 then set x:= x+1; +when 2 then set x:= x+2; +else set x:= x+100; +end case; +set x:=x + 500; +return x; +end| +select func_8407_a()| +func_8407_a() +NULL +select func_8407_b()| +func_8407_b() +1500 +drop function func_8407_a| +drop function func_8407_b| +drop table if exists table_26503| +drop procedure if exists proc_26503_ok_1| +drop procedure if exists proc_26503_ok_2| +drop procedure if exists proc_26503_ok_3| +drop procedure if exists proc_26503_ok_4| +create table table_26503(a int unique)| +create procedure proc_26503_ok_1(v int) +begin +declare i int default 5; +declare continue handler for sqlexception +begin +select 'caught something'; +retry: +while i > 0 do +begin +set i = i - 1; +select 'looping', i; +iterate retry; +select 'dead code'; +end; +end while retry; +select 'leaving handler'; +end; +select 'do something'; +insert into table_26503 values (v); +select 'do something again'; +insert into table_26503 values (v); +end| +create procedure proc_26503_ok_2(v int) +begin +declare i int default 5; +declare continue handler for sqlexception +begin +select 'caught something'; +retry: +while i > 0 do +begin +set i = i - 1; +select 'looping', i; +leave retry; +select 'dead code'; +end; +end while; +select 'leaving handler'; +end; +select 'do something'; +insert into table_26503 values (v); +select 'do something again'; +insert into table_26503 values (v); +end| +create procedure proc_26503_ok_3(v int) +begin +declare i int default 5; +retry: +begin +declare continue handler for sqlexception +begin +select 'caught something'; +retry: +while i > 0 do +begin +set i = i - 1; +select 'looping', i; +iterate retry; +select 'dead code'; +end; +end while retry; +select 'leaving handler'; +end; +select 'do something'; +insert into table_26503 values (v); +select 'do something again'; +insert into table_26503 values (v); +end; +end| +create procedure proc_26503_ok_4(v int) +begin +declare i int default 5; +retry: +begin +declare continue handler for sqlexception +begin +select 'caught something'; +retry: +while i > 0 do +begin +set i = i - 1; +select 'looping', i; +leave retry; +select 'dead code'; +end; +end while; +select 'leaving handler'; +end; +select 'do something'; +insert into table_26503 values (v); +select 'do something again'; +insert into table_26503 values (v); +end; +end| +call proc_26503_ok_1(1)| +do something +do something again +caught something +looping i +looping i +looping i +looping i +looping i +leaving handler +do something +do something again +caught something +looping 4 +looping 3 +looping 2 +looping 1 +looping 0 +leaving handler +call proc_26503_ok_2(2)| +do something +do something again +caught something +looping i +leaving handler +do something +do something again +caught something +looping 4 +leaving handler +call proc_26503_ok_3(3)| +do something +do something again +caught something +looping i +looping i +looping i +looping i +looping i +leaving handler +do something +do something again +caught something +looping 4 +looping 3 +looping 2 +looping 1 +looping 0 +leaving handler +call proc_26503_ok_4(4)| +do something +do something again +caught something +looping i +leaving handler +do something +do something again +caught something +looping 4 +leaving handler +drop table table_26503| +drop procedure proc_26503_ok_1| +drop procedure proc_26503_ok_2| +drop procedure proc_26503_ok_3| +drop procedure proc_26503_ok_4| +DROP FUNCTION IF EXISTS bug25373| +CREATE FUNCTION bug25373(p1 INTEGER) RETURNS INTEGER +LANGUAGE SQL DETERMINISTIC +RETURN p1;| +CREATE TABLE t3 (f1 INT, f2 FLOAT)| +INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| +SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY f1 WITH ROLLUP| +SUM(f2) bug25373(f1) +6.300000071525574 1 +15 2 +21.300000071525574 NULL +DROP FUNCTION bug25373| +DROP TABLE t3| +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +CREATE DATABASE mysqltest1| +CREATE DATABASE mysqltest2| +CREATE PROCEDURE mysqltest1.p1() +DROP DATABASE mysqltest2| +use mysqltest2| +CALL mysqltest1.p1()| +SELECT DATABASE()| +DATABASE() +mysqltest2 +drop procedure mysqltest1.p1| +DROP DATABASE mysqltest1| +use test| +drop function if exists bug20777| +drop table if exists examplebug20777| +create function bug20777(f1 bigint unsigned) returns bigint unsigned +begin +set f1 = (f1 - 10); set f1 = (f1 + 10); +return f1; +end| +select bug20777(9223372036854775803) as '9223372036854775803 2**63-5'; +9223372036854775803 2**63-5 +9223372036854775803 +select bug20777(9223372036854775804) as '9223372036854775804 2**63-4'; +9223372036854775804 2**63-4 +9223372036854775804 +select bug20777(9223372036854775805) as '9223372036854775805 2**63-3'; +9223372036854775805 2**63-3 +9223372036854775805 +select bug20777(9223372036854775806) as '9223372036854775806 2**63-2'; +9223372036854775806 2**63-2 +9223372036854775806 +select bug20777(9223372036854775807) as '9223372036854775807 2**63-1'; +9223372036854775807 2**63-1 +9223372036854775807 +select bug20777(9223372036854775808) as '9223372036854775808 2**63+0'; +9223372036854775808 2**63+0 +9223372036854775808 +select bug20777(9223372036854775809) as '9223372036854775809 2**63+1'; +9223372036854775809 2**63+1 +9223372036854775809 +select bug20777(9223372036854775810) as '9223372036854775810 2**63+2'; +9223372036854775810 2**63+2 +9223372036854775810 +select bug20777(-9223372036854775808) as 'lower bounds signed bigint'; +ERROR 22003: BIGINT UNSIGNED value is out of range in ''(0 - 10)'' +select bug20777(9223372036854775807) as 'upper bounds signed bigint'; +upper bounds signed bigint +9223372036854775807 +select bug20777(0) as 'lower bounds unsigned bigint'; +ERROR 22003: BIGINT UNSIGNED value is out of range in ''(0 - 10)'' +select bug20777(18446744073709551615) as 'upper bounds unsigned bigint'; +upper bounds unsigned bigint +18446744073709551615 +select bug20777(18446744073709551616) as 'upper bounds unsigned bigint + 1'; +upper bounds unsigned bigint + 1 +18446744073709551615 +select bug20777(-1) as 'lower bounds unsigned bigint - 1'; +ERROR 22003: BIGINT UNSIGNED value is out of range in ''(0 - 10)'' +create table examplebug20777 as select +0 as 'i', +bug20777(9223372036854775806) as '2**63-2', +bug20777(9223372036854775807) as '2**63-1', +bug20777(9223372036854775808) as '2**63', +bug20777(9223372036854775809) as '2**63+1', +bug20777(18446744073709551614) as '2**64-2', +bug20777(18446744073709551615) as '2**64-1', +bug20777(18446744073709551616) as '2**64'; +insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616); +show create table examplebug20777; +Table Create Table +examplebug20777 CREATE TABLE `examplebug20777` ( + `i` bigint(1) NOT NULL, + `2**63-2` bigint(20) unsigned DEFAULT NULL, + `2**63-1` bigint(20) unsigned DEFAULT NULL, + `2**63` bigint(20) unsigned DEFAULT NULL, + `2**63+1` bigint(20) unsigned DEFAULT NULL, + `2**64-2` bigint(20) unsigned DEFAULT NULL, + `2**64-1` bigint(20) unsigned DEFAULT NULL, + `2**64` bigint(20) unsigned DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 COMPRESSION = 'lz4_1.0' REPLICA_NUM = NUM BLOCK_SIZE = SIZE USE_BLOOM_FILTER = FALSE TABLET_SIZE = SIZE PCTFREE = 10 +select * from examplebug20777 order by i; +i 2**63-2 2**63-1 2**63 2**63+1 2**64-2 2**64-1 2**64 +0 9223372036854775806 9223372036854775807 9223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 18446744073709551615 +1 9223372036854775806 9223372036854775807 223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 8446744073709551616 +drop table examplebug20777; +select bug20777(18446744073709551613)+1; +bug20777(18446744073709551613)+1 +18446744073709551614 +drop function bug20777; +DROP FUNCTION IF EXISTS bug5274_f1| +DROP FUNCTION IF EXISTS bug5274_f2| +CREATE FUNCTION bug5274_f1(p1 CHAR) RETURNS CHAR +RETURN CONCAT(p1, p1)| +CREATE FUNCTION bug5274_f2() RETURNS CHAR +BEGIN +DECLARE v1 INT DEFAULT 0; +DECLARE v2 CHAR DEFAULT 'x'; +WHILE v1 < 30 DO +SET v1 = v1 + 1; +SET v2 = bug5274_f1(v2); +END WHILE; +RETURN v2; +END| +SELECT bug5274_f2()| +bug5274_f2() +x +DROP FUNCTION bug5274_f1| +DROP FUNCTION bug5274_f2| +drop procedure if exists proc_21513| +create procedure proc_21513()`my_label`:BEGIN END| +show create procedure proc_21513| +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +proc_21513 CREATE DEFINER = admin@% PROCEDURE `test`.`proc_21513` +() + `my_label`:BEGIN END utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +drop procedure proc_21513| +End of 5.0 tests. +drop table t1,t2; +CREATE TABLE t1 (a int auto_increment primary key) engine=MyISAM; +CREATE TABLE t2 (a int auto_increment primary key, b int) engine=innodb; +set @a=0; +drop function if exists bug27354; +CREATE function bug27354() RETURNS int not deterministic +begin +insert into t1 values (null); +set @a=@a+1; +return @a; +end| +update t2 set b=1 where a=bug27354(); +select count(t_1.a),count(t_2.a) from t1 as t_1, t2 as t_2 /* must be 0,0 */; +count(t_1.a) count(t_2.a) +0 0 +insert into t2 values (1,1),(2,2),(3,3); +update t2 set b=-b where a=bug27354(); +select * from t2 /* must return 1,-1 ... */; +a b +1 -1 +2 -2 +3 -3 +select count(*) from t1 /* must be 3 */; +count(*) +3 +drop table t1,t2; +drop function bug27354; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE FUNCTION metered(a INT) RETURNS INT RETURN 12; +CREATE VIEW v1 AS SELECT test.metered(a) as metered FROM t1; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW `v1` AS select `test`.`metered`(`test`.`t1`.`a`) AS `metered` from `test`.`t1` utf8mb4 utf8mb4_general_ci +DROP VIEW v1; +DROP FUNCTION metered; +DROP TABLE t1; +SET @p1_p2_cnt= 2; +CREATE TABLE t1 (c1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; +PREPARE s1 FROM 'SELECT c1 FROM v1'; +EXECUTE s1; +c1 +EXECUTE s1; +c1 +CREATE PROCEDURE p1(IN loops BIGINT(19) UNSIGNED) +BEGIN +WHILE loops > 0 DO +SELECT c1 FROM v1; +SET loops = loops - 1; +END WHILE; +END| +CREATE PROCEDURE p2(IN loops BIGINT(19) UNSIGNED) +BEGIN +WHILE loops > 0 DO +SELECT c1 FROM v1; +CALL p1(@p1_p2_cnt); +SET loops = loops - 1; +END WHILE; +END| +CREATE FUNCTION f1(loops INT UNSIGNED) +RETURNS INT +BEGIN +DECLARE tmp INT; +WHILE loops > 0 DO +SELECT c1 FROM v1 INTO tmp; +SET loops = loops - 1; +END WHILE; +RETURN loops; +END| +CALL p1(2); +c1 +c1 +CALL p2(2); +c1 +c1 +c1 +c1 +c1 +c1 +SELECT f1(2); +f1(2) +0 +PREPARE s1 FROM 'SELECT f1(2)'; +EXECUTE s1; +f1(2) +0 +EXECUTE s1; +f1(2) +0 +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP FUNCTION f1; +DROP VIEW v1; +DROP TABLE t1; +drop database if exists mysqltest_db1; +create database mysqltest_db1; +create procedure mysqltest_db1.sp_bug28551() begin end; +call mysqltest_db1.sp_bug28551(); +show warnings; +Level Code Message +drop database mysqltest_db1; +drop database if exists mysqltest_db1; +drop table if exists test.t1; +drop procedure if exists test.sp_bug29050; +create database mysqltest_db1; +use mysqltest_db1; +drop database mysqltest_db1; +create table test.t1 (id int); +insert into test.t1 (id) values (1); +create procedure test.sp_bug29050() begin select * from t1; end// +show warnings; +Level Code Message +call test.sp_bug29050(); +id +1 +show warnings; +Level Code Message +use test; +drop procedure sp_bug29050; +drop table t1; +drop procedure if exists proc_25411_a; +drop procedure if exists proc_25411_b; +drop procedure if exists proc_25411_c; +create procedure proc_25411_a() +begin +/* real comment */ +select 1; +/*! select 2; */ +select 3; +/*!00000 select 4; */ +/*!99999 select 5; */ +end +$$ +create procedure proc_25411_b( +/* real comment */ +/*! p1 int, */ +/*!00000 p2 int */ +/*!99999 ,p3 int */ +) +begin +select p1, p2; +end +$$ +create procedure proc_25411_c() +begin +select 1/*!,2*//*!00000,3*//*!99999,4*/; +select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/; +select 1/*!,2 *//*!00000,3 *//*!99999,4 */; +select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */; +select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ; +end +$$ +show create procedure proc_25411_a; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +proc_25411_a CREATE DEFINER = admin@% PROCEDURE `test`.`proc_25411_a` +() + begin +/* real comment */ +select 1; +/*! select 2; */ +select 3; +/*!00000 select 4; */ +/*!99999 select 5; */ +end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call proc_25411_a(); +1 +2 +3 +4 +5 +1 +2 +3 +4 +5 +show create procedure proc_25411_b; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +proc_25411_b CREATE DEFINER = admin@% PROCEDURE `test`.`proc_25411_b` +( + IN `p1` int(11), IN `p2` int(11), IN `p3` int(11) +) begin +select p1, p2; +end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +select name, param_list, body from mysql.proc where name like "%25411%"; +name param_list body +proc_25411_a begin +/* real comment */ +select 1; +/*! select 2; */ +select 3; +/*!00000 select 4; */ +/*!99999 select 5; */ +end +proc_25411_b IN `p1` int(11), IN `p2` int(11), IN `p3` int(11) begin +select p1, p2; +end +proc_25411_c begin +select 1/*!,2*//*!00000,3*//*!99999,4*/; +select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/; +select 1/*!,2 *//*!00000,3 *//*!99999,4 */; +select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */; +select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ; +end +call proc_25411_b(10, 20); +ERROR 42000: Incorrect number of arguments +show create procedure proc_25411_c; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +proc_25411_c CREATE DEFINER = admin@% PROCEDURE `test`.`proc_25411_c` +() + begin +select 1/*!,2*//*!00000,3*//*!99999,4*/; +select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/; +select 1/*!,2 *//*!00000,3 *//*!99999,4 */; +select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */; +select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ; +end utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +call proc_25411_c(); +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +drop procedure proc_25411_a; +drop procedure proc_25411_b; +drop procedure proc_25411_c; +drop procedure if exists proc_26302; +create procedure proc_26302() +select 1 /* testing */; +show create procedure proc_26302; +Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation +proc_26302 CREATE DEFINER = admin@% PROCEDURE `test`.`proc_26302` +() + select 1 /* testing */ utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES +where ROUTINE_NAME = "proc_26302"; +ROUTINE_NAME ROUTINE_DEFINITION +proc_26302 select 1 /* testing */ +drop procedure proc_26302; +CREATE FUNCTION f1() RETURNS INT DETERMINISTIC RETURN 2; +CREATE FUNCTION f2(I INT) RETURNS INT DETERMINISTIC RETURN 3; +CREATE TABLE t1 (c1 INT, INDEX(c1)); +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); +CREATE VIEW v1 AS SELECT c1 FROM t1; +DROP VIEW v1; +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP TABLE t1; +create function f1() +returns int(11) +not deterministic +contains sql +sql security definer +comment '' +begin +declare x int(11); +set x=-1; +return x; +end| +create view v1 as select 1 as one, f1() as days; +show create view test.v1; +View Create View character_set_client collation_connection +v1 CREATE VIEW `v1` AS select 1 AS `one`,`test`.`f1`() AS `days` utf8mb4 utf8mb4_general_ci +select column_name from information_schema.columns +where table_name='v1' and table_schema='test'; +column_name +one +days +drop view v1; +drop function f1; + +# Bug#13675. + +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP TABLE IF EXISTS t1; + +CREATE PROCEDURE p1(v DATETIME) CREATE TABLE t1 SELECT v; +CREATE PROCEDURE p2(v INT) CREATE TABLE t1 SELECT v; + +CALL p1(NOW()); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` datetime DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 + +DROP TABLE t1; + +CALL p1('text'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` datetime DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 + +DROP TABLE t1; + +CALL p2(10); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` int(11) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 + +DROP TABLE t1; + +CALL p2('text'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` int(11) DEFAULT NULL +) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 2 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 + +DROP TABLE t1; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +# +# Bug#31035. +# + +# +# - Prepare. +# + +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; + +# +# - Create required objects. +# + +CREATE TABLE t1(c1 INT); + +INSERT INTO t1 VALUES (1), (2), (3); + +CREATE FUNCTION f1() +RETURNS INT +NOT DETERMINISTIC +RETURN 1; + +CREATE FUNCTION f2(p INT) +RETURNS INT +NOT DETERMINISTIC +RETURN 1; + +CREATE FUNCTION f3() +RETURNS INT +DETERMINISTIC +RETURN 1; + +CREATE FUNCTION f4(p INT) +RETURNS INT +DETERMINISTIC +RETURN 1; + +# +# - Check. +# + +SELECT f1() AS a FROM t1 GROUP BY a; +a +1 + +SELECT f2(@a) AS a FROM t1 GROUP BY a; +a +1 + +SELECT f3() AS a FROM t1 GROUP BY a; +a +1 + +SELECT f4(0) AS a FROM t1 GROUP BY a; +a +1 + +SELECT f4(@a) AS a FROM t1 GROUP BY a; +a +1 + +# +# - Cleanup. +# + +DROP TABLE t1; +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; + +# +# Bug#31191. +# + +# +# - Prepare. +# + +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP FUNCTION IF EXISTS f1; + +# +# - Create required objects. +# + +CREATE TABLE t1 ( +id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, +barcode INT(8) UNSIGNED ZEROFILL nOT NULL, +PRIMARY KEY (id), +UNIQUE KEY barcode (barcode) +); + +INSERT INTO t1 (id, barcode) VALUES (1, 12345678); +INSERT INTO t1 (id, barcode) VALUES (2, 12345679); + +CREATE TABLE test.t2 ( +id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, +barcode BIGINT(11) UNSIGNED ZEROFILL NOT NULL, +PRIMARY KEY (id) +); + +INSERT INTO test.t2 (id, barcode) VALUES (1, 12345106708); +INSERT INTO test.t2 (id, barcode) VALUES (2, 12345106709); + +CREATE FUNCTION f1(p INT(8)) +RETURNS BIGINT(11) UNSIGNED +READS SQL DATA +RETURN FLOOR(p/1000)*1000000 + 100000 + FLOOR((p MOD 1000)/10)*100 + (p MOD 10); + +# +# - Check. +# + +SELECT DISTINCT t1.barcode, f1(t1.barcode) +FROM t1 +INNER JOIN t2 +ON f1(t1.barcode) = t2.barcode +WHERE t1.barcode=12345678; +barcode f1(t1.barcode) +12345678 12345106708 + +# +# - Cleanup. +# + +DROP TABLE t1; +DROP TABLE t2; +DROP FUNCTION f1; + +# +# Bug#31226. +# + +# +# - Prepare. +# + +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS f1; + +# +# - Create required objects. +# + +CREATE TABLE t1(id INT); + +INSERT INTO t1 VALUES (1), (2), (3); + +CREATE FUNCTION f1() +RETURNS DATETIME +NOT DETERMINISTIC NO SQL +RETURN NOW(); + +# +# - Check. +# + +SELECT f1() FROM t1 GROUP BY 1; +f1() + + +# +# - Cleanup. +# + +DROP TABLE t1; +DROP FUNCTION f1; + +DROP PROCEDURE IF EXISTS db28318_a.t1; +ERROR 42000: Unknown database 'db28318_a' +DROP PROCEDURE IF EXISTS db28318_b.t2; +ERROR 42000: Unknown database 'db28318_b' +DROP DATABASE IF EXISTS db28318_a; +DROP DATABASE IF EXISTS db28318_b; +CREATE DATABASE db28318_a; +CREATE DATABASE db28318_b; +CREATE PROCEDURE db28318_a.t1() SELECT "db28318_a.t1"; +CREATE PROCEDURE db28318_b.t2() CALL t1(); +use db28318_a; +CALL db28318_b.t2(); +Got one of the listed errors +DROP PROCEDURE db28318_a.t1; +DROP PROCEDURE db28318_b.t2; +DROP DATABASE db28318_a; +DROP DATABASE db28318_b; +use test; +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS bug29770; +CREATE TABLE t1(a int); +CREATE PROCEDURE bug29770() +BEGIN +DECLARE CONTINUE HANDLER FOR SQLSTATE '42S22' SET @state:= 'run'; +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @exception:= 'run'; +SELECT x FROM t1; +END| +CALL bug29770(); +SELECT @state, @exception; +@state @exception +run NULL +DROP TABLE t1; +DROP PROCEDURE bug29770; +use test; +drop table if exists t_33618; +drop procedure if exists proc_33618; +create table t_33618 (`a` int, unique(`a`), `b` varchar(30)) engine=myisam; +Warnings: +Warning 1286 Unknown storage engine 'myisam' +insert into t_33618 (`a`,`b`) values (1,'1'),(2,'2'); +create procedure proc_33618(num int) +begin +declare count1 int default '0'; +declare vb varchar(30); +declare last_row int; +while(num>=1) do +set num=num-1; +begin +declare cur1 cursor for select `a` from t_33618; +declare continue handler for not found set last_row = 1; +set last_row:=0; +open cur1; +rep1: +repeat +begin +declare exit handler for 1062 begin end; +fetch cur1 into vb; +if (last_row = 1) then +leave rep1; +end if; +end; +until last_row=1 +end repeat; +close cur1; +end; +end while; +end// +call proc_33618(20); +drop table t_33618; +drop procedure proc_33618; +# +# Bug#30787: Stored function ignores user defined alias. +# +use test; +drop function if exists func30787; +create table t1(f1 int); +insert into t1 values(1),(2); +create function func30787(p1 int) returns int +begin +return p1; +end | +select (select func30787(f1)) as ttt from t1; +ttt +1 +2 +drop function func30787; +drop table t1; +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1),(2),(3),(4); +CREATE PROCEDURE test_sp() +SELECT t1.* FROM t1 RIGHT JOIN t1 t2 ON t1.id=t2.id; +CALL test_sp(); +id +1 +2 +3 +4 +CALL test_sp(); +id +1 +2 +3 +4 +DROP PROCEDURE test_sp; +DROP TABLE t1; +create table t1(c1 INT); +create function f1(p1 int) returns varchar(32) +return 'aaa'; +create view v1 as select f1(c1) as parent_control_name from t1; +create procedure p1() +begin +select parent_control_name as c1 from v1; +end // +call p1(); +c1 +call p1(); +c1 +drop procedure p1; +drop function f1; +drop view v1; +drop table t1; +drop procedure if exists `p2` $ +create procedure `p2`(in `a` varchar(1024) charset utf8) +begin +declare `pos` int default 1; +declare `str` varchar(1024) charset utf8; +set `str` := `a`; +select substr(`str`, `pos`+ 1 ) into `str`; +end $ +call `p2`('s s s s s s'); +drop procedure `p2`; +drop table if exists t1; +drop procedure if exists p1; +create procedure p1() begin select * from t1; end$ +call p1$ +ERROR 42S02: Table 'test.t1' doesn't exist +create table t1 (a integer)$ +call p1$ +a +alter table t1 add b integer; +call p1$ +a b +drop table t1; +drop procedure p1; +# ------------------------------------------------------------------ +# -- End of 5.0 tests +# ------------------------------------------------------------------ + +# +# Bug#20550. +# + +# +# - Prepare. +# + +DROP VIEW IF EXISTS v1; +DROP VIEW IF EXISTS v2; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; + +# +# - Create required objects. +# + +CREATE FUNCTION f1() RETURNS VARCHAR(65525) RETURN 'Hello'; + +CREATE FUNCTION f2() RETURNS TINYINT RETURN 1; + +CREATE VIEW v1 AS SELECT f1(); + +CREATE VIEW v2 AS SELECT f2(); + +# +# - Check. +# + +SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'v1'; +DATA_TYPE +varchar + +SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'v2'; +DATA_TYPE +tinyint + +# +# - Cleanup. +# + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP VIEW v1; +DROP VIEW v2; + +# +# - Bug#24923: prepare. +# + +DROP FUNCTION IF EXISTS f1; + +# +# - Bug#24923: create required objects. +# + +CREATE FUNCTION f1(p INT) +RETURNS ENUM ('Very_long_enum_element_identifier', +'Another_very_long_enum_element_identifier') +BEGIN +CASE p +WHEN 1 THEN +RETURN 'Very_long_enum_element_identifier'; +ELSE +RETURN 'Another_very_long_enum_element_identifier'; +END CASE; +END| + +# +# - Bug#24923: check. +# + +SELECT f1(1); +f1(1) +Very_long_enum_element_identifier + +SELECT f1(2); +f1(2) +Another_very_long_enum_element_identifier + +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 CREATE DEFINER = admin@% FUNCTION `test`.`f1` +( + `p` int(11) +) RETURNS enum BEGIN +CASE p +WHEN 1 THEN +RETURN 'Very_long_enum_element_identifier'; +ELSE +RETURN 'Another_very_long_enum_element_identifier'; +END CASE; +END utf8mb4 utf8mb4_general_ci utf8mb4_general_ci +# +# - Bug#24923: cleanup. +# + +DROP FUNCTION f1; + +drop procedure if exists p; +set @old_mode= @@sql_mode; +set @@sql_mode= cast(pow(2,32)-1 as unsigned integer); +ERROR 0A000: Value for sql_mode not supported +select @@sql_mode into @full_mode; +create procedure p() begin end; +call p(); +set @@sql_mode= @old_mode; +select replace(@full_mode, ',,,', ',NOT_USED,') into @full_mode; +select replace(@full_mode, 'ALLOW_INVALID_DATES', 'INVALID_DATES') into @full_mode; +select name from mysql.proc where name = 'p' and sql_mode = @full_mode; +name +p +drop procedure p; +CREATE DEFINER = 'root'@'localhost' PROCEDURE p1() +NOT DETERMINISTIC +CONTAINS SQL +SQL SECURITY DEFINER +COMMENT '' +BEGIN +SHOW TABLE STATUS like 't1'; +END;// +Warnings: +Warning 1449 User not exist +drop procedure p1// +CREATE DEFINER = root PROCEDURE p1() +NOT DETERMINISTIC +CONTAINS SQL +SQL SECURITY DEFINER +COMMENT '' +BEGIN +SHOW TABLE STATUS like 't1'; +END;// +CREATE TABLE t1 (f1 INT); +CALL p1(); +CALL p1(); +CALL p1(); +CALL p1(); +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 ( f1 integer, primary key (f1)); +CREATE TABLE t2 LIKE t1; +CREATE TEMPORARY TABLE t3 LIKE t1; +CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t3 AS A WHERE A.f1 IN ( SELECT f1 FROM t3 ) ; +END| +CALL p1; +f1 +DROP TABLE t3; +CREATE VIEW t3 AS SELECT f1 FROM t2 A WHERE A.f1 IN ( SELECT f1 FROM t2 ); +CALL p1; +f1 +CALL p1; +f1 +DROP PROCEDURE p1; +DROP TABLE t1, t2; +DROP VIEW t3; +# +# Bug #46629: Item_in_subselect::val_int(): Assertion `0' +# on subquery inside a SP +# +CREATE TABLE t1(a INT); +CREATE TABLE t2(a INT, b INT PRIMARY KEY); +CREATE PROCEDURE p1 () +BEGIN +SELECT a FROM t1 A WHERE A.b IN (SELECT b FROM t2 AS B); +END| +CALL p1; +ERROR 42S22: Unknown column 'a.b' in 'where clause' +CALL p1; +ERROR 42S22: Unknown column 'a.b' in 'where clause' +DROP PROCEDURE p1; +DROP TABLE t1, t2; +# +# Bug#47627: SET @@{global.session}.local_variable in stored routine causes crash +# Bug#48626: Crash or lost connection using SET for declared variables with @@ +# +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +CREATE PROCEDURE p1() +BEGIN +DECLARE v INT DEFAULT 0; +SET @@SESSION.v= 10; +END// +ERROR 42000: Undeclared variable: v +CREATE PROCEDURE p2() +BEGIN +DECLARE v INT DEFAULT 0; +SET v= 10; +END// +call p2()// +CREATE PROCEDURE p3() +BEGIN +DECLARE v INT DEFAULT 0; +SELECT @@SESSION.v; +END// +call p3()// +ERROR HY000: Unknown system variable 'v' +CREATE PROCEDURE p4() +BEGIN +DECLARE v INT DEFAULT 0; +SET @@GLOBAL.v= 10; +END// +ERROR 42000: Undeclared variable: v +CREATE PROCEDURE p5() +BEGIN +DECLARE init_connect INT DEFAULT 0; +SET init_connect= 10; +SET @@GLOBAL.init_connect= 'SELECT 1'; +SET @@SESSION.IDENTITY= 1; +SELECT @@SESSION.IDENTITY; +SELECT @@GLOBAL.init_connect; +SELECT init_connect; +END// +CREATE PROCEDURE p6() +BEGIN +DECLARE v INT DEFAULT 0; +SET @@v= 0; +END// +ERROR 42000: Undeclared variable: v +SET @old_init_connect= @@GLOBAL.init_connect; +CALL p5(); +@@SESSION.IDENTITY +@@GLOBAL.init_connect +init_connect +1 +SELECT 1 +10 +SET @@GLOBAL.init_connect= @old_init_connect; +DROP PROCEDURE p2; +DROP PROCEDURE p3; +DROP PROCEDURE p5; +# +# Bug#11840395 (formerly known as bug#60347): +# The string "versiondata" seems +# to be 'leaking' into the schema name space +# +DROP DATABASE IF EXISTS mixedCaseDbName; +CREATE DATABASE mixedCaseDbName; +CREATE PROCEDURE mixedCaseDbName.tryMyProc() begin end| +CREATE FUNCTION mixedCaseDbName.tryMyFunc() returns varchar(1024) begin return 'IT WORKS'; end +| +call mixedCaseDbName.tryMyProc(); +select mixedCaseDbName.tryMyFunc(); +mixedCaseDbName.tryMyFunc() +IT WORKS +DROP DATABASE mixedCaseDbName; +# +# Bug#11766594 59736: SELECT DISTINCT.. INCORRECT RESULT WITH DETERMINISTIC FUNCTION IN WHERE C +# +CREATE TABLE t1 (a INT, b INT, KEY(b)); +CREATE TABLE t2 (c INT, d INT, KEY(c)); +INSERT INTO t1 VALUES (1,1),(1,1),(1,2); +INSERT INTO t2 VALUES (1,1),(1,2); +CREATE FUNCTION f1() RETURNS INT DETERMINISTIC +BEGIN +DECLARE a int; +-- SQL statement inside +SELECT 1 INTO a; +RETURN a; +END $ +SELECT COUNT(DISTINCT d) FROM t1, t2 WHERE a = c AND b = f1(); +COUNT(DISTINCT d) +2 +DROP FUNCTION f1; +DROP TABLE t1, t2; +# ------------------------------------------------------------------ +# -- End of 5.1 tests +# ------------------------------------------------------------------ +DROP FUNCTION IF EXISTS f1; +DROP TABLE IF EXISTS t_non_existing; +DROP TABLE IF EXISTS t1; +CREATE FUNCTION f1() RETURNS INT +BEGIN +DECLARE v INT; +SELECT a FROM t_non_existing INTO v; +RETURN 1; +END| +CREATE TABLE t1 (a INT) ENGINE = myisam; +Warnings: +Warning 1286 Unknown storage engine 'myisam' +INSERT INTO t1 VALUES (1); +SELECT * FROM t1 WHERE a = f1(); +ERROR 42S02: Table 'test.t_non_existing' doesn't exist +DROP FUNCTION f1; +DROP TABLE t1; +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1(a INT, b CHAR) +BEGIN +IF a > 0 THEN +CALL p1(a-1, 'ab'); +ELSE +SELECT 1; +END IF; +END| +SET @save_max_sp_recursion= @@max_sp_recursion_depth; +SET @@max_sp_recursion_depth= 5; +CALL p1(4, 'a'); +1 +1 +SET @@max_sp_recursion_depth= @save_max_sp_recursion; +DROP PROCEDURE p1; +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1(a CHAR) +BEGIN +SELECT 1; +SELECT CAST('10 ' as UNSIGNED INTEGER); +SELECT 1; +END| +CALL p1('data truncated parameter'); +1 +CAST('10 ' as UNSIGNED INTEGER) +1 +1 +10 +1 +DROP PROCEDURE p1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +DROP PROCEDURE IF EXISTS p4; +CREATE PROCEDURE p1() +CALL p2()| +CREATE PROCEDURE p2() +CALL p3()| +CREATE PROCEDURE p3() +CALL p4()| +CREATE PROCEDURE p4() +BEGIN +SELECT 1; +SELECT CAST('10 ' as UNSIGNED INTEGER); +SELECT 2; +END| +CALL p1(); +1 +CAST('10 ' as UNSIGNED INTEGER) +2 +1 +10 +2 +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP PROCEDURE p3; +DROP PROCEDURE p4; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a CHAR(2)); +INSERT INTO t1 VALUES ('aa'); +CREATE FUNCTION f1() RETURNS CHAR +RETURN (SELECT f2())| +CREATE FUNCTION f2() RETURNS CHAR +RETURN (SELECT f3())| +CREATE FUNCTION f3() RETURNS CHAR +RETURN (SELECT f4())| +CREATE FUNCTION f4() RETURNS CHAR +BEGIN +RETURN (SELECT a FROM t1); +END| +SELECT f1(); +f1() +aa +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; +DROP TABLE t1; +# +# Bug#34197: CREATE PROCEDURE fails when COMMENT truncated in non +# strict SQL mode +# +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1 () +COMMENT +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' +BEGIN +END; +SELECT comment FROM mysql.proc WHERE name = "p1" and db = database(); +comment +12345678901234567890123456789012345678901234567890123456789012345678901234567890 +DROP PROCEDURE p1; +# +# Bug #47313 assert in check_key_in_view during CALL procedure +# +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS t1, t2_unrelated; +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); +CREATE VIEW t1 AS SELECT 10 AS f1; +# t1 refers to the view +CALL p1(1); +ERROR HY000: The target table t1 of the INSERT is not insertable-into +CREATE TEMPORARY TABLE t1 (f1 INT); +# t1 still refers to the view since it was inlined +# https://work.aone.alibaba-inc.com/issue/32172786 +CALL p1(2); +DROP VIEW t1; +# t1 now refers to the temporary table +CALL p1(3); +# Check which values were inserted into the temp table. +SELECT * FROM t1; +f1 +2 +3 +DROP TEMPORARY TABLE t1; +DROP VIEW t1; +ERROR 42S02: Unknown table 'test.t1' +DROP PROCEDURE p1; +# Now test what happens if the sp cache is invalidated. +DROP VIEW IF EXISTS v2_unrelated; +CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); +CREATE VIEW t1 AS SELECT 10 AS f1; +CREATE VIEW v2_unrelated AS SELECT 1 AS r1; +# Load the procedure into the sp cache +CALL p1(4); +ERROR HY000: The target table t1 of the INSERT is not insertable-into +CREATE TEMPORARY TABLE t1 (f1 int); +ALTER VIEW v2_unrelated AS SELECT 2 AS r1; +# Alter view causes the sp cache to be invalidated. +# Now t1 refers to the temporary table, not the view. +CALL p1(5); +# Check which values were inserted into the temp table. +SELECT * FROM t1; +f1 +5 +DROP TEMPORARY TABLE t1; +DROP VIEW t1, v2_unrelated; +DROP PROCEDURE p1; +CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); +CREATE TEMPORARY TABLE t1 (f1 INT); +# t1 refers to the temporary table +CALL p1(6); +CREATE VIEW t1 AS SELECT 10 AS f1; +# Create view causes the sp cache to be invalidated. +# t1 still refers to the temporary table since it shadows the view. +CALL p1(7); +DROP VIEW t1; +# Check which values were inserted into the temp table. +SELECT * FROM t1; +f1 +6 +7 +DROP TEMPORARY TABLE t1; +DROP PROCEDURE p1; +# +# Bug #11918 Can't use a declared variable in LIMIT clause +# +drop table if exists t1; +drop procedure if exists p1; +create table t1 (c1 int); +insert into t1 (c1) values (1), (2), (3), (4), (5); +create procedure p1() +begin +declare a integer; +declare b integer; +select * from t1 limit a, b; +end| +# How do we handle NULL limit values? +call p1(); +c1 +drop table t1; +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4), (5); +# +# Do we correctly resolve identifiers in LIMIT? +# +call p1(); +a +drop table t1; +create table t1 (c1 int); +insert into t1 (c1) values (1), (2), (3), (4), (5); +drop procedure p1; +# Try to create a procedure that +# refers to non-existing variables. +create procedure p1(p1 integer, p2 integer) +select * from t1 limit a, b; +Warnings: +Warning 5002 Resolve error +# +# Try to use data types not allowed in LIMIT +# +drop procedure p1; +create procedure p1(p1 date, p2 date) select * from t1 limit p1, p2; +drop procedure p1; +create procedure p1(p1 integer, p2 float) select * from t1 limit p1, p2; +drop procedure p1; +create procedure p1(p1 integer, p2 char(1)) select * from t1 limit p1, p2; +drop procedure p1; +create procedure p1(p1 varchar(5), p2 char(1)) select * from t1 limit p1, p2; +drop procedure p1; +create procedure p1(p1 decimal, p2 decimal) select * from t1 limit p1, p2; +drop procedure p1; +create procedure p1(p1 double, p2 double) select * from t1 limit p1, p2; +# +# Finally, test the valid case. +# +drop procedure p1; +create procedure p1(p1 integer, p2 integer) +select * from t1 limit p1, p2; +call p1(NULL, NULL); +c1 +call p1(0, 0); +c1 +call p1(0, -1); +c1 +call p1(-1, 0); +c1 +call p1(-1, -1); +c1 +call p1(0, 1); +c1 +1 +call p1(1, 0); +c1 +call p1(1, 5); +c1 +2 +3 +4 +5 +call p1(3, 2); +c1 +4 +5 +# Try to create a function that +# refers to non-existing variables. +create function f1(p1 integer, p2 integer) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit a, b); +return a; +end| +Warnings: +Warning 5002 Resolve error +drop function f1| +create function f1() +returns int +begin +declare a, b, c int; +set a = (select count(*) from t1 limit b, c); +return a; +end| +# How do we handle NULL limit values? +select f1(); +f1() +NULL +drop function f1; +# +# Try to use data types not allowed in LIMIT +# +create function f1(p1 date, p2 date) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit p1, p2); +return a; +end| +drop function f1| +create function f1(p1 integer, p2 float) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit p1, p2); +return a; +end| +drop function f1| +create function f1(p1 integer, p2 char(1)) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit p1, p2); +return a; +end| +drop function f1| +create function f1(p1 varchar(5), p2 char(1)) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit p1, p2); +return a; +end| +drop function f1| +create function f1(p1 decimal, p2 decimal) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit p1, p2); +return a; +end| +drop function f1| +create function f1(p1 double, p2 double) +returns int +begin +declare a int; +set a = (select count(*) from t1 limit p1, p2); +return a; +end| +# +# Finally, test the valid case. +# +drop function f1| +create function f1(p1 integer, p2 integer) +returns int +begin +declare count int; +set count= (select count(*) from (select * from t1 limit p1, p2) t_1); +return count; +end| +select f1(0, 0); +f1(0, 0) +0 +select f1(0, -1); +f1(0, -1) +0 +select f1(-1, 0); +f1(-1, 0) +0 +select f1(-1, -1); +f1(-1, -1) +0 +select f1(0, 1); +f1(0, 1) +1 +select f1(1, 0); +f1(1, 0) +0 +select f1(1, 5); +f1(1, 5) +4 +select f1(3, 2); +f1(3, 2) +2 +# Cleanup +drop table t1; +drop procedure p1; +drop function f1; +# +# BUG#11766234: 59299: ASSERT (TABLE_REF->TABLE || TABLE_REF->VIEW) +# FAILS IN SET_FIELD_ITERATOR +# +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +CREATE VIEW v1 AS SELECT a FROM t2; +DROP PROCEDURE IF EXISTS proc; +CREATE PROCEDURE proc() SELECT * FROM t1 NATURAL JOIN v1; +ALTER TABLE t2 CHANGE COLUMN a b CHAR; + +CALL proc(); +ERROR 42S22: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +CALL proc(); +ERROR 42S22: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them + +DROP TABLE t1,t2; +DROP VIEW v1; +DROP PROCEDURE proc; + +# -- +# -- Bug 11765684 - 58674: SP-cache does not detect changes in +# -- pre-locking list caused by triggers +# --- +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP PROCEDURE IF EXISTS p1; +CREATE TABLE t1(a INT); +CREATE TABLE t2(a INT); +CREATE TABLE t3(a INT); +CREATE PROCEDURE p1() +INSERT INTO t1(a) VALUES (1); + +CREATE TRIGGER t1_ai AFTER INSERT ON t1 +FOR EACH ROW +INSERT INTO t2(a) VALUES (NEW.a); + +CALL p1(); + +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 +FOR EACH ROW +INSERT INTO t3(a) VALUES (NEW.a); + +CALL p1(); + +DROP TABLE t1, t2, t3; +DROP PROCEDURE p1; + + +# -- +# -- Bug#12652769 - 61470: case operator in stored routine retains old +# -- value of input parameter +# --- +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +CREATE TABLE t1 (s1 CHAR(5) CHARACTER SET utf8); +INSERT INTO t1 VALUES ('a'); +CREATE PROCEDURE p1(dt DATETIME, i INT) +BEGIN +SELECT +CASE +WHEN i = 1 THEN 2 +ELSE dt +END AS x1; +SELECT +CASE _binary'a' + WHEN _utf8'a' THEN 'A' + END AS x2; +SELECT +CASE _utf8'a' + WHEN _binary'a' THEN _utf8'A' + END AS x3; +SELECT +CASE s1 +WHEN _binary'a' THEN _binary'b' + ELSE _binary'c' + END AS x4 +FROM t1; +END| + +CALL p1('2011-04-03 05:14:10', 1); +x1 +x2 +x3 +x4 +2 +A +A +b +CALL p1('2011-04-03 05:14:11', 2); +x1 +x2 +x3 +x4 +2011-04-03 05:14:11 +A +A +b +CALL p1('2011-04-03 05:14:12', 2); +x1 +x2 +x3 +x4 +2011-04-03 05:14:12 +A +A +b +CALL p1('2011-04-03 05:14:13', 2); +x1 +x2 +x3 +x4 +2011-04-03 05:14:13 +A +A +b + +DROP TABLE t1; +DROP PROCEDURE p1; + +# +# Bug#12621017 - Crash if a sp variable is used in the +# limit clause of a set statement +# +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +CREATE TABLE t1 (c1 INT); +INSERT INTO t1 VALUES (1); +CREATE PROCEDURE p1() +BEGIN +DECLARE foo, cnt INT UNSIGNED DEFAULT 1; +SET foo = (SELECT MIN(c1) FROM t1 LIMIT cnt); +END| +CREATE PROCEDURE p2() +BEGIN +DECLARE iLimit INT; +DECLARE iVal INT; +DECLARE cur1 CURSOR FOR +SELECT c1 FROM t1 +LIMIT iLimit; +SET iLimit=1; +OPEN cur1; +FETCH cur1 INTO iVal; +END| +CALL p1(); +CALL p2(); +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; + +# Bug#13805127: Stored program cache produces wrong result in same THD + +CREATE PROCEDURE p1(x INT UNSIGNED) +BEGIN +SELECT c1, t2.c2, count(c3) +FROM +( +SELECT 3 as c2 FROM dual WHERE x = 1 +UNION +SELECT 2 FROM dual WHERE x = 1 OR x = 2 +) AS t1, +( +SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual +UNION +SELECT '2012-03-01 02:00:00', 3, 2 FROM dual +UNION +SELECT '2012-03-01 01:00:00', 2, 1 FROM dual +) AS t2 +WHERE t2.c2 = t1.c2 +GROUP BY c1, t2.c2 +; +END| + +CALL p1(1); +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 +CALL p1(2); +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +CALL p1(1); +c1 c2 count(c3) +2012-03-01 01:00:00 2 1 +2012-03-01 01:00:00 3 1 +2012-03-01 02:00:00 3 1 +DROP PROCEDURE p1; +# End of 5.5 test +# +# Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS +# +DROP FUNCTION IF EXISTS f1; +CREATE FUNCTION f1() RETURNS INT +BEGIN +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; +BEGIN +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f1(); +BEGIN +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f1(); +RETURN f1(); +END; +END; +RETURN 1; +END $ +SELECT f1(); +f1() +1 +DROP FUNCTION f1; +# +# Bug#12577230 +# RERUN OF STORED FUNCTION CAUSES SEGFAULT IN MAKE_JOIN_SELECT +# +CREATE TABLE t1 (a INT) ENGINE=myisam; +Warnings: +Warning 1286 Unknown storage engine 'myisam' +INSERT INTO t1 VALUES (1); +CREATE VIEW v1 AS SELECT a FROM t1; +CREATE PROCEDURE p1() +SELECT 1 FROM v1 JOIN t1 ON v1.a +WHERE (SELECT 1 FROM t1 WHERE v1.a) +; +CALL p1(); +1 +1 +CALL p1(); +1 +1 +DROP PROCEDURE p1; +DROP TABLE t1; +DROP VIEW v1; +# +# WL#2111: Add non-reserved ROW_COUNT keyword. +# +DROP PROCEDURE IF EXISTS p1; +CREATE PROCEDURE p1() +BEGIN +DECLARE row_count INT DEFAULT 1; +SELECT row_count; +SELECT row_count(); +ROW_COUNT: WHILE row_count > 0 DO +SET row_count = row_count - 1; +END WHILE ROW_COUNT; +SELECT ROW_COUNT; +END| +CALL p1(); +row_count +row_count() +ROW_COUNT +1 +-1 +0 +DROP PROCEDURE p1; +# +# BUG #11748187 - 35410: STORED FUNCTION: CONFUSING 'ORDER CLAUSE' IN ERROR MESSAGE +# +DROP FUNCTION if exists f1; +CREATE FUNCTION f1 (p_value INT) RETURNS INT DETERMINISTIC RETURN x; +ERROR 42000: Undeclared variable: x +# +# BUG #12872824 (formerly known as 62125): testing stored function +# result for null incorrectly yields 1292 warning. +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +CREATE FUNCTION f1() RETURNS VARCHAR(1) +BEGIN RETURN 'X'; END;/ +CREATE FUNCTION f2() RETURNS CHAR(1) +BEGIN RETURN 'X'; END;/ +CREATE FUNCTION f3() RETURNS VARCHAR(1) +BEGIN RETURN NULL; END;/ +CREATE FUNCTION f4() RETURNS CHAR(1) +BEGIN RETURN NULL; END;/ +SELECT f1() IS NULL; +f1() IS NULL +0 +SELECT f2() IS NULL; +f2() IS NULL +0 +SELECT f3() IS NULL; +f3() IS NULL +1 +SELECT f4() IS NULL; +f4() IS NULL +1 +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; +# +# +# WL#6230: Remove 'SET = DEFAULT' +# +CREATE TABLE t1(a INT); +CREATE PROCEDURE p(p INT) +SET p = DEFAULT| +Warnings: +Warning 5002 Resolve error +drop procedure p| +CREATE PROCEDURE p() +BEGIN +DECLARE v INT; +SET v = DEFAULT; +END| +Warnings: +Warning 5002 Resolve error +drop procedure p| +CREATE PROCEDURE p() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = DEFAULT; +END| +Warnings: +Warning 5002 Resolve error +drop procedure p| +CREATE PROCEDURE p() +BEGIN +DECLARE v INT DEFAULT (SELECT * FROM t1); +SET v = DEFAULT; +END| +Warnings: +Warning 5002 Resolve error +drop procedure p| +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +BEGIN +SET NEW.a = DEFAULT; +END| +Warnings: +Warning 5002 Resolve error +Warning 5884 TRIGGER 'test.t1_bu' compile error + +# Check that setting system variables to DEFAULT still works in SP. + +CREATE PROCEDURE p1() +SET @@ob_bnl_join_cache_size = DEFAULT; +SET @ob_bnl_join_cache_size_saved = @@ob_bnl_join_cache_size; +SELECT @@ob_bnl_join_cache_size; +@@ob_bnl_join_cache_size +10485760 +SET @@ob_bnl_join_cache_size = 1; +SELECT @@ob_bnl_join_cache_size; +@@ob_bnl_join_cache_size +1 +CALL p1(); +SELECT @@ob_bnl_join_cache_size; +@@ob_bnl_join_cache_size +10485760 +SET @@ob_bnl_join_cache_size = @ob_bnl_join_cache_size_saved; +DROP PROCEDURE p1; +DROP TABLE t1; +# End of 5.6 tests +set @@sql_mode=STRICT_ALL_TABLES; diff --git a/tools/deploy/mysql_test/test_suite/pl/t/pl_basic_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/pl_basic_mysql.test new file mode 100644 index 000000000..ded74db41 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/pl_basic_mysql.test @@ -0,0 +1,2113 @@ +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log +#owner: linlin.xll +#owner group: sql1 +#tags: pl +#description: + +--result_format 4 +--enable_sorted_result + +--disable_query_log +--disable_result_log +--source mysql_test/include/index_quick_major.inc +--enable_query_log +--enable_result_log + +--disable_warnings +drop table if exists a,b,t,t1; +drop procedure if exists p; +drop procedure if exists f; +drop procedure if exists pp; +drop procedure if exists gather_table_stats; +--enable_warnings + +connect (obsys,$OBMYSQL_MS0,admin,$OBMYSQL_PWD,oceanbase,$OBMYSQL_PORT); +connection default; + +#case 1 +create table a(a1 int,a2 int,a3 int); +delimiter //; +create procedure f(inout x int) +begin +set x = x+1; +end// +sleep 3 // +create procedure p(x int) +begin +declare i int; +set i=i+1; +if(1=1) +then +begin +declare j int; +select 1 from a where a1=i into x; +end; +end if; +while i>1 do +set i=i-1; +end while; +call f(x); +end// +delimiter ;// +call p(1); +drop table a; +drop procedure f; +drop procedure p; + +#case 2 +create table a(a1 int,a2 int,a3 int); +--error 0,1305 +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +declare i bigint default 0; +set i=i+1; +if(i=1) +then +select 1 from dual; +end if; +end// +call pro1()// +delimiter ;// +select * from a; +drop table a; + +#case 3 +create table a(a1 int,a2 int,a3 int); +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +declare i bigint default 0; +set i=i+1; +if(i=1) +then +insert into a values(1,1,1); +end if; +end// +call pro1()// +delimiter ;// +select * from a; +drop table a; + +#case 4 +create table a(a1 int,a2 int,a3 int); +delimiter //; +create procedure p(x bigint) +begin +select x from dual; +end// +delimiter ;// +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 5 +create table a(a1 int,a2 int,a3 int); +delimiter //; +create procedure p(x bigint) +begin +insert into a values(x,1,1); +end// +delimiter ;// +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 6 +create table a(a1 int,a2 int,a3 int); +delimiter //; +create procedure p() +begin +declare i bigint default 0; +set i=i+1; +if(i=1) +then +insert into a values(1,1,1); +end if; +end// +delimiter ;// +call p(); +select * from a; +drop table a; +drop procedure p; + +#case 7 +create table a(a1 int,a2 int,a3 int); +delimiter //; +create procedure p(x bigint) +begin +declare i bigint default 0; +set i=i+1; +if(i>x) +then +insert into a values(0,0,0); +else +insert into a values(1,1,1); +end if; +end// +delimiter ;// +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 8 +create table a(a1 int,a2 int,a3 int); +delimiter //; +create procedure p(x bigint) +begin +declare i bigint default 1; +if(xi) +then +insert into a values(x,x,x); +else +insert into a values(i,i,i); +end if; +end// +delimiter ;// +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 11 +create table a(a1 char(5),a2 char(5),a3 char(5)); +delimiter //; +create procedure p(x char(5), y int) +begin +declare i bigint default 1; +if(y>i) +then +insert into a values(x,x,x); +else +insert into a values('i','i','i'); +end if; +end// +delimiter ;// +call p('x', 1); +select * from a; +drop table a; +drop procedure p; + +#case 12 +create table a(a1 int); +delimiter //; +create procedure p() +begin +select *,* from a; +end// +delimiter ;// +--error 5011 +call p; +select * from a; +drop table a; +drop procedure p; + +#case 13 +create table a(a1 bigint); +delimiter //; +create procedure p(x bigint) +begin +DECLARE cur Cursor FOR select * from a; +open cur; +fetch cur into x; +close cur; +end// +delimiter ;// +--error 1329 +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 14 +delimiter //; +CREATE PROCEDURE p(a bigint) +BEGIN +label1: LOOP +SET a = a + 1; +IF a < 10 THEN +LEAVE label1; +END IF; +END LOOP label1; +END// +delimiter ;// +call p(1); +drop procedure p; + +#case 15 +create table a(a1 bigint); +delimiter //; +CREATE PROCEDURE p(a bigint) +BEGIN +label1: LOOP +SET a = a + 1; +IF a < 10 THEN +insert into a values(a); +else +LEAVE label1; +END IF; +END LOOP label1; +END// +delimiter ;// +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 16 +create table a(a1 bigint); +delimiter //; +CREATE PROCEDURE p(a bigint) +BEGIN +label1: LOOP +SET a = a + 1; +IF a < 10 THEN +iterate label1; +elseif a< 20 then +insert into a values(a); +else +LEAVE label1; +END IF; +END LOOP label1; +END// +delimiter ;// +call p(1); +select * from a; +drop table a; +drop procedure p; + +#case 17 +delimiter //; +CREATE PROCEDURE p(a bigint, sum bigint) +BEGIN +label1: LOOP +begin +declare b bigint; +set b=a+1; +IF a+b > sum THEN +LEAVE label1; +else +set a=b; +END IF; +end; +END LOOP label1; +END// +delimiter ;// +#### TODO: 执行时间过长导致farm失败, 暂时改小循环次数 +## call p(1,1000000); +call p(1,10000); +drop procedure p; + +#case 18 +delimiter //; +CREATE PROCEDURE p(a bigint) +BEGIN +label1: Repeat +begin +declare b bigint; +SET b = a + 1; +end; +UNTIL a<10 +END repeat label1; +END// +delimiter ;// +call p(1); +drop procedure p; + +#case 19 +delimiter //; +CREATE PROCEDURE p(a bigint) +BEGIN +label1: Repeat +begin +declare b int; +SET b = a + 1; +end; +UNTIL a<10 +END repeat label1; +END// +delimiter ;// +call p(1); +drop procedure p; + +#case 20 +delimiter //; +--error 1327 +CREATE PROCEDURE p(a bigint) +BEGIN +label1: Repeat +begin +declare b bigint; +SET b = a + 1; +end; +UNTIL b<10 +END repeat label1; +END// +delimiter ;// + +#case 21 +set @a=1; +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +if(@a=1) +then +select @a; +end if; +end// +call pro1()// +delimiter ;// + +#case 22 +create table a(a1 int); +set @a=1; +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +if(@a=1) +then +insert into a values(1); +else +insert into a values(@a); +end if; +end// +call pro1()// +delimiter ;// +select * from a; +drop table a; + +#case 23 +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +set @a=1; +end// +call pro1()// +delimiter ;// + +#case 24 +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +set @b='b'; +end// +call pro1()// +delimiter ;// + +#case 25 +drop procedure pro1; +delimiter //; +--error 1327 +create procedure pro1() +begin +set @@session.a=1; +end// +--error 1305 +call pro1()// +delimiter ;// + +#case 26 +set @@session.ob_trx_timeout=100000000; +select @@session.ob_trx_timeout; +--error 1305 +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +set @@session.ob_trx_timeout=100000001; +end// +call pro1()// +delimiter ;// +select @@session.ob_trx_timeout; +set @@session.ob_trx_timeout=100000000; + +#case 27 +drop procedure pro1; +delimiter //; +--error 1327 +create procedure pro1() +begin +set @@global.a=1; +end// +--error 1305 +call pro1()// +delimiter ;// + +#case 28 +set @@global.ob_trx_timeout=100000000; +select @@global.ob_trx_timeout; +--error 1305 +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +set @@global.ob_trx_timeout=100000001; +end// +call pro1()// +delimiter ;// +select @@global.ob_trx_timeout; +set @@global.ob_trx_timeout=100000000; + +#case 29 +create table a(a1 int); +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +set @a=1+1; +if(@a=2) then +insert into a values(@a); +else +insert into a values(1); +end if; +end// +call pro1()// +delimiter ;// +select * from a; +drop table a; + +#case 30 +create table a(a1 varchar(100)); +delimiter //; +create procedure p(x varchar(100)) +begin +select * from a where a1=x; +end// +delimiter ;// +call p('fff'); +drop procedure p; +drop table a; + +#case 31 +create table a(a1 varchar(100)); +delimiter //; +create procedure p(x varchar(100)) +begin +declare a1 varchar(100) default 'fff'; +select * from a where a1=x; +end// +delimiter ;// +--error 1318 +call p(); +call p('a'); +drop procedure p; +drop table a; + +#case 32 +create table a(a1 varchar(100)); +delimiter //; +create procedure p(x varchar(100)) +begin +insert into a values(x); +end// +delimiter ;// +call p('fff'); +select * from a; +drop procedure p; +drop table a; + +#case 33 +create table a(a1 varchar(100)); +delimiter //; +create procedure p(inout x varchar(10)) +begin +set x='bbb'; +end// +create procedure pp() +begin +declare x varchar(10) default 'aaa'; +call p(x); +insert into a values(x); +end// +delimiter ;// +call pp(); +select * from a; +drop table a; +drop procedure p; +drop procedure pp; + +#case 34 +create table a(a1 varchar(100)); +create table b(b1 int); +delimiter //; +create procedure p(inout x varchar(10)) +begin +insert into a values(x); +insert into b values(x); +end// +create procedure pp(inout x int) +begin +insert into a values(x); +insert into b values(x); +end// +delimiter ;// +set @px = 1; +call p(@px); +set @py = 1; +call pp(@py); +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 35 +create table a(a1 varchar(100)); +delimiter //; +create procedure p(x varchar(4)) +begin +insert into a values(x); +end// +delimiter ;// +--error 1406 +call p('gggggggg'); +call p('gggg'); +select * from a; +drop table a; +drop procedure p; +drop procedure pp; + +#case 36 +create table a(a1 varchar(100)); +insert into a values('a'); +create table b(b1 varchar(100)); +drop procedure pro1; +delimiter //; +create procedure pro1() +BEGIN +DECLARE x varchar(100); +DECLARE c CURSOR FOR SELECT a1 FROM a; +OPEN c; +fetch c into x; +CLOSE c; +insert into b values(x); +END// +call pro1()// +delimiter ;// +select * from b; +drop table a; +drop table b; + +#case 37 +create table a(a1 varchar(10)); +delimiter //; +create procedure p(x varchar(100)) +begin +case x +when 1 then insert into a values('1'); +else insert into a values('0'); +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 38 +create table a(a1 varchar(10)); +delimiter //; +create procedure p(x varchar(100)) +begin +case x +when 1 then insert into a values('1'); +when 2 then insert into a values('2'); +else insert into a values('0'); +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 39 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +else insert into a values(0); +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 40 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +else insert into a values(0); +if x > 1 then insert into a values(100); +else insert into a values(-100); +end if; +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 41 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +else insert into a values(0); +end case; +if x > 1 then insert into a values(100); +else insert into a values(-100); +end if; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 42 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case +when x=1 then insert into a values(1); +when x=2 then insert into a values(2); +else insert into a values(0); +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 43 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case +when x=1 then insert into a values(1); +when x=2 then insert into a values(2); +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +--error ER_SP_CASE_NOT_FOUND +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 44 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +when 2 then insert into a values(2); +end case; +end// +delimiter ;// +call p(1); +select * from a; +call p(2); +select * from a; +--error ER_SP_CASE_NOT_FOUND +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 45 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +declare exit handler for 1339 +insert into a values(-1); +case x +when 1 then insert into a values(1); +end case; +end// +delimiter ;// +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 46 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +case x +when 1 then insert into a values(1); +end case; +end// +delimiter ;// +call p(1); +select * from a; +--error ER_SP_CASE_NOT_FOUND +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 47 +create table b(b1 char(6)); +delimiter //; +create procedure p() +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop procedure p; + +#case 48 +set @@sql_mode=PAD_CHAR_TO_FULL_LENGTH; +create table b(b1 char(6)); +delimiter //; +create procedure p() +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop procedure p; +set @@sql_mode=default; + +#case 49 +set @@sql_mode=PAD_CHAR_TO_FULL_LENGTH; +create table b(b1 char(6)); +delimiter //; +create procedure p() +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +delimiter ;// +set @@sql_mode=default; +call p(); +select * from b; +drop table b; +drop procedure p; + +#case 50 +create table a(a1 char(6)); +delimiter //; +create procedure p(a int) +begin +insert into a values(a); +end// +delimiter ;// +#connection obsys; +select route_sql from oceanbase.__all_routine where routine_name = 'p' and database_id = (select database_id from oceanbase.__all_database where database_name = database()); +#select route_sql from oceanbase.__all_virtual_routine where routine_name = 'p'; +#connection default; +drop procedure p; +drop table a; + +#case 51 +create table b(b1 char(6)); +delimiter //; +create procedure p(a int) +begin +declare x char(5) default 'a'; +declare y char(6) default concat(x, 1); +insert into b values(y); +end// +delimiter ;// +#connection obsys; +#connection obsys; +select route_sql from oceanbase.__all_routine where routine_name = 'p' and database_id = (select database_id from oceanbase.__all_database where database_name = database()); +#select route_sql from oceanbase.__all_virtual_routine where routine_name = 'p'; +#connection default; +drop procedure p; +drop table b; + +#case 52 +set @@sql_mode=PAD_CHAR_TO_FULL_LENGTH; +create table b(b1 char(6)); +create table a(a1 char(5)); +insert into a values('a'); +delimiter //; +create procedure p() +begin +declare x char(5); +declare y char(6); +select a1 from a into x; +set y = concat(x, 1); +insert into b values(y); +end// +delimiter ;// +call p(); +select * from b; +drop table a; +drop table b; +drop procedure p; +set @@sql_mode=default; + +#case 53 +create table b(b1 char(6)); +create table a(a1 char(5)); +insert into a values('a'); +delimiter //; +create procedure p() +begin +declare x char(5); +select a1 from a into x; +insert into b values(x); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop table a; +drop procedure p; + +#case 54 +set @xxx = 'asd'; +create table b(b1 char(6)); +create table a(a1 char(5)); +insert into a values('a'); +insert into b values(@xxx); +delimiter //; +create procedure p() +begin +select a1 from a into @xxx; +insert into b values(@xxx); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop table a; +drop procedure p; + +#case 55 +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +delimiter //; +create procedure p() +begin +select a1 from a into @xxx; +insert into b values(@xxx,@xxx); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop table a; +drop procedure p; + +#case 56 +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +delimiter //; +create procedure p() +begin +declare x char(6); +select a1,a2 from a into @xxx, x; +insert into b values(@xxx, x); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop table a; +drop procedure p; + +#case 57 +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +delimiter //; +create procedure p() +begin +declare x char(6); +select a1,a2 from a into x, x; +insert into b values(@xxx, x); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop table a; +drop procedure p; + +#case 58 +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +create table a(a1 char(5), a2 char(5)); +insert into a values('a', 'a'); +insert into b values(@xxx, 'asd'); +delimiter //; +create procedure p() +begin +declare x char(6); +declare y char(6); +select a1,a2 from a into @xxx, x; +set y = @xxx; +insert into b values(y, x); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop table a; +drop procedure p; + +#case 59 +set @xxx = 'asd'; +create table b(b1 char(6), b2 char(6)); +insert into b values(@xxx, 'asd'); +delimiter //; +create procedure p() +begin +declare x char(6); +set x='a'; +insert into b values(@xxx, x); +end// +delimiter ;// +call p(); +select * from b; +drop table b; +drop procedure p; + +#case 60 +create table a(a1 int, a2 varchar(10)); +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +declare x varchar(10) default 'x'; +declare y varchar(10) default 'y'; +declare xx int default 1; +declare yy int default 2; +set y = x; +set yy = xx; +set x = 'a'; +set xx = 9; +insert into a values(yy, y); +end// +call pro1()// +delimiter ;// +select * from a; +drop table a; + +#case 61 +delimiter //; +--error 1064 +create procedure p() +begin +declare if int default 0; +end// +delimiter ;// + +#case 62 +delimiter //; +create procedure p() +begin +declare if1 int default 0; +end// +delimiter ;// +drop procedure p; + +#case 63 +delimiter //; +create procedure p() +begin +declare count int default 0; +end// +delimiter ;// +drop procedure p; + +#case 64 +delimiter //; +create procedure p() +begin +declare count1 int default 0; +end// +delimiter ;// +drop procedure p; + +#case 65 +set autocommit=0; +create table a(a1 int); +drop procedure pro1; +delimiter //; +create procedure pro1() +BEGIN +insert into a values(1); +commit; +END// +call pro1()// +delimiter ;// +select * from a; +drop procedure pro1; +delimiter //; +create procedure pro1() +BEGIN +insert into a values(2); +rollback; +END// +call pro1()// +delimiter ;// +select * from a; +set autocommit=1; +drop table a; + +#case 66 +create table fib(id int, value bigint); +delimiter //; +create procedure p(x int, out y bigint) +begin +if x = 0 then set y = 0; +elseif x = 1 then set y = 1; +else +begin +declare a, b bigint default 0; +call p(x-1, a); +call p(x-2, b); +set y = a+b; +end; +end if; +end// +create procedure pp(x int) +begin +declare i int default 0; +declare result bigint default 0; +while i < x do +call p(i, result); +insert into fib values(i, result); +set i = i + 1; +end while; +end// +delimiter ;// +set @@max_sp_recursion_depth = 10; +call pp(10); +set @@max_sp_recursion_depth = 0; +select * from fib; +drop table fib; +drop procedure p; +drop procedure pp; + +#case 67 +delimiter //; +create procedure p() +begin +call p(); +end// +delimiter ;// +-- error ER_SP_RECURSION_LIMIT +call p(); +drop procedure p; + +#case 68 +create table a(a1 bigint, a2 timestamp); +delimiter //; +create procedure p() +begin +declare x bigint default 1; +update a set a2=CURRENT_TIMESTAMP where a1=x; +end // +delimiter ;// +call p(); +drop table a; +drop procedure p; + +#case 69 +create table a(a1 bigint, a2 timestamp); +delimiter //; +create procedure p() +begin +declare x bigint default 1; +declare y timestamp; +set y = CURRENT_TIMESTAMP; +update a set a2=y where a1=x; +end // +delimiter ;// +call p(); +drop table a; +drop procedure p; + +#case 70 +create table a(a1 timestamp); +create table b(b1 timestamp); +insert into a values('2018-01-02 10:10:32.000000'); +delimiter //; +create procedure p() +begin +declare x timestamp; +select a1 from a into x; +insert into b values(x); +end // +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 71 +create table a(a1 decimal(12,2),a2 timestamp); +create table b(b1 decimal(12,2),b2 timestamp); +insert into a values(1.1,'2018-01-02 10:10:32.000000'); +delimiter //; +create procedure p() +begin +declare x decimal(12,2); +declare y timestamp; +select a1,a2 from a into x,y; +insert into b values(x,y); +end // +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 72 +create table a(a1 decimal(12,2),a2 timestamp); +create table b(b1 decimal(12,2),b2 timestamp); +insert into a values(1.1,'2018-01-02 10:10:32.000000'); +delimiter //; +create procedure p() +begin +declare x decimal(12,2); +declare y timestamp; +declare c1 cursor for select a1,a2 from a; +open c1; +fetch c1 into x,y; +close c1; +insert into b values(x,y); +end // +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 73 +create table if not exists bmsql_customer ( + c_w_id INTEGER NOT NULL, + c_d_id INTEGER NOT NULL, + c_id INTEGER NOT NULL, + c_data VARCHAR(500), + PRIMARY KEY (c_w_id, c_d_id, c_id) +); +insert into bmsql_customer values(1,1,1,'a'); +delimiter //; +create procedure p(IN in_w_id int, + IN in_d_id int, + IN in_c_id int, + IN in_c_d_id int, + IN in_c_w_id int, + IN in_h_amount DECIMAL(6,2) + ) +begin + UPDATE bmsql_customer + SET c_data = SUBSTR(CONCAT('C_ID=', CAST(in_c_id AS CHAR), + ' C_D_ID=', CAST(in_c_d_id AS CHAR), + ' C_W_ID=', CAST(in_c_w_id AS CHAR), + ' D_ID=', CAST(in_d_id AS CHAR), + ' W_ID=', CAST(in_w_id AS CHAR), + ' H_AMOUNT=', ROUND(in_h_amount,2)), 1, 500) + WHERE c_w_id = in_c_w_id AND c_d_id = in_c_d_id AND c_id = in_c_id; +end// +delimiter ;// +call p(1,1,1,1,1,1.1); +drop table bmsql_customer; +drop procedure p; + +#case 74 +create table a(a1 varchar(20)); +delimiter //; +create procedure p(x int) +begin +update a set a1=cast(x as char) where a1=1; +end// +delimiter ;// +call p(1); +drop table a; +drop procedure p; + +#case 75 +drop procedure pro1; +delimiter //; +create procedure pro1() +begin +declare x int default 0; +set x=rand(); +end// +call pro1()// +delimiter ;// +drop procedure pro1; + +#case 76 +create table a(a1 int); +delimiter //; +create procedure p( +arg1 int, +arg2 int, +arg3 int, +arg4 int, +arg5 int, +arg6 int, +arg7 int, +arg8 int, +arg9 int, +arg10 int +) +begin +declare x int default 1; +set x = arg10; +insert into a values(x); +end // +delimiter ;// +call p(1,2,3,4,5,6,7,8,9,10); +select * from a; +drop table a; +drop procedure p; + +#case 77 +create table a(a1 int); +delimiter //; +create procedure p1( +INOUT arg1 int, +INOUT arg2 int, +INOUT arg3 int, +INOUT arg4 int, +INOUT arg5 int, +INOUT arg6 int, +INOUT arg7 int, +INOUT arg8 int, +INOUT arg9 int, +INOUT arg10 int) +begin +set arg10 = 99; +end // +create procedure p() +begin +declare arg1 int default 1; +declare arg2 int default 2; +declare arg3 int default 3; +declare arg4 int default 4; +declare arg5 int default 5; +declare arg6 int default 6; +declare arg7 int default 7; +declare arg8 int default 8; +declare arg9 int default 9; +declare arg10 int default 10; +call p1(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10); +insert into a values(arg10); +end // +delimiter ;// +call p(); +select * from a; +drop table a; +drop procedure p1; +drop procedure p; + +#case 78 +create table a(a1 int); +delimiter //; +create procedure p1( +INOUT arg1 int, +INOUT arg2 int, +INOUT arg3 int, +INOUT arg4 int, +INOUT arg5 int, +INOUT arg6 int, +INOUT arg7 int, +INOUT arg8 int, +INOUT arg9 int, +INOUT arg10 int, +INOUT arg11 int, +INOUT arg12 int, +INOUT arg13 int, +INOUT arg14 int, +INOUT arg15 int, +INOUT arg16 int, +INOUT arg17 int, +INOUT arg18 int, +INOUT arg19 int, +INOUT arg20 int) +begin +set arg20 = 99; +end // +create procedure p() +begin +declare arg1 int default 1; +declare arg2 int default 2; +declare arg3 int default 3; +declare arg4 int default 4; +declare arg5 int default 5; +declare arg6 int default 6; +declare arg7 int default 7; +declare arg8 int default 8; +declare arg9 int default 9; +declare arg10 int default 10; +declare arg11 int default 11; +declare arg12 int default 12; +declare arg13 int default 13; +declare arg14 int default 14; +declare arg15 int default 15; +declare arg16 int default 16; +declare arg17 int default 17; +declare arg18 int default 18; +declare arg19 int default 19; +declare arg20 int default 20; +call p1(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20); +insert into a values(arg20); +end // +delimiter ;// +call p(); +select * from a; +drop table a; +drop procedure p1; +drop procedure p; + +#case 79 +create table a(a1 timestamp); +delimiter //; +create procedure p() +begin +declare x int default 1; +while x <=10 do +insert into a values(CURRENT_TIMESTAMP); +set x = x+1; +end while; +end // +delimiter ;// +call p; +select count(*) from a; +drop table a; +drop procedure p; + +#case 80 +create table a(a1 timestamp); +delimiter //; +create procedure p() +begin +declare x int default 1; +declare y timestamp; +while x <=10 do +set y = CURRENT_TIMESTAMP; +insert into a values(y); +set x = x+1; +end while; +end // +delimiter ;// +call p; +select count(*) from a; +drop table a; +drop procedure p; + +#case 81 +create table a(a1 decimal(6,2)); +insert into a values(1.11); +create table b(b1 decimal(6,2)); +delimiter //; +create procedure p() +begin +declare x decimal(6,2); +declare c cursor for select a1 from a; +open c; +fetch c into x; +close c; +insert into b values(x); +end // +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 82 +create table a(a1 decimal(6,2)); +insert into a values(1.11); +create table b(b1 int); +delimiter //; +create procedure p() +begin +declare x int; +declare c cursor for select a1 from a; +open c; +fetch c into x; +close c; +insert into b values(x); +end // +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 83 +create table a(a1 decimal(6,2)); +delimiter //; +create procedure p(x int) +begin +insert into a values(x); +select * from a where a1=x; +end // +delimiter ;// +#connection obsys; +select route_sql from oceanbase.__all_routine where routine_name = 'p' and database_id = (select database_id from oceanbase.__all_database where database_name = database()); +#select route_sql from oceanbase.__all_virtual_routine where routine_name = 'p'; +#connection default; +drop table a; +drop procedure p; + +#case 84 +delimiter //; +create procedure p() +begin +insert into table_not_exist values(1); +end // +delimiter ;// +--error 1146 +call p(); +drop procedure p; + +#case 85 +delimiter //; +create procedure p() +label1: +begin +end label1// +delimiter ;// +call p(); +drop procedure p; + +#case 86 +delimiter //; +create procedure p() +begin +end// +delimiter ;// +call p(); +drop procedure p; + +#case 87 +delimiter //; +create procedure p() +begin +declare i int default 3; +label1: begin +if i > 0 then +set i = i-1; +else leave label1; +end if; +end; +end// +delimiter ;// +call p(); +drop procedure p; + +#case 88 +delimiter //; +--error 1313 +create procedure p() +return 42;// +delimiter ;// + +#case 89 +set @a=0; +select @a; +delimiter //; +create procedure p(out x int) +begin +set x=1; +end// +delimiter ;// +call p(@a); +select @a; +drop procedure p; + +#case 90 +delimiter //; +create procedure gather_table_stats(tenant_name varchar(128), db_name varchar(128), table_name varchar(128)) +begin +end// +delimiter ;// +drop procedure gather_table_stats; + +#case 91 +delimiter //; +create procedure gather_table_stats(tenant_name int, db_name int, table_name int) +begin +end// +delimiter ;// +drop procedure gather_table_stats; + +#case 92 +delimiter //; +create procedure gather_table_stats(tenant_name int, db_name int, t_name int) +begin +end// +delimiter ;// +call gather_table_stats(1,1,1); +drop procedure gather_table_stats; + +#case 93 +--error 0,1305 +drop function f; +delimiter //; +create function f(x int) returns int +begin + if x>1 then + return x; + else + signal SQLSTATE '01000'; + end if; +end// +delimiter ;// +select f(2); +--error 1321 +select f(1); +drop function f; + +#case 94 +delimiter //; +create function f(x int) returns int +begin + if x>1 then + return x; + else + signal SQLSTATE '02000'; + end if; +end// +delimiter ;// +select f(2); +--error 1643 +select f(1); +drop function f; + +#case 95 +delimiter //; +create function f(x int) returns int +begin + if x>1 then + return NULL; + else + signal SQLSTATE '02000'; + end if; +end// +delimiter ;// +select f(2); +--error 1643 +select f(1); +drop function f; + +### need has return in mysql function +### https://work.aone.alibaba-inc.com/issue/34977232 + +delimiter //; +DROP FUNCTION IF EXISTS `fun6`// + +--error 1320 +CREATE FUNCTION fun6 ( p1 INT) RETURNS VARCHAR(20) +BEGIN + SET p1 = p1 + 3; + SET p1 = p1 * 2; + SET @num = p1 * p1; +END// + +--error 1305 +SELECT fun6(5)// +SELECT @num// + +--error 1320 +CREATE FUNCTION fun6 ( p1 INT) RETURNS VARCHAR(20) +BEGIN + SET @num = p1 * p1; +END// + +--error 1305 +SELECT fun6(5)// +SELECT @num// + +DROP FUNCTION IF EXISTS `fun6`// +delimiter ;// + +### label dup +### https://work.aone.alibaba-inc.com/issue/34954831 +delimiter //; +--disable_warnings ONCE +DROP TABLE IF EXISTS result1// +CREATE TABLE result1( +id INT, +res1 VARCHAR(50), +res2 VARCHAR(50) +)// +DROP PROCEDURE IF EXISTS `pro_1`// + +CREATE PROCEDURE pro_1() +BEGIN + label1:BEGIN + INSERT INTO result1 VALUES(1,'结果表:','标签label1'); + label2:BEGIN + INSERT INTO result1 VALUES(2,'结果表:','标签label2'); + END label2; + END label1; +END// + +CALL pro_1()// + +CREATE PROCEDURE pro_2() +BEGIN + label1:BEGIN + INSERT INTO result1 VALUES(3,'结果表:','标签label1'); + END label1; + label1:BEGIN + INSERT INTO result1 VALUES(4,'结果表:','标签label1'); + END label1; +END// + +CALL pro_2()// + +--error 1309 +CREATE PROCEDURE pro_3() +BEGIN + label1:BEGIN + INSERT INTO result1 VALUES(5,'结果表:','标签label1'); + label1:BEGIN + INSERT INTO result1 VALUES(6,'结果表:','标签label1'); + END label1; + END label1; +END// + +--error 1305 +CALL pro_3()// + +SELECT * FROM result1// +--disable_warnings +DROP TABLE IF EXISTS result1// +DROP PROCEDURE IF EXISTS `pro_1`// +DROP PROCEDURE IF EXISTS `pro_2`// +DROP PROCEDURE IF EXISTS `pro_3`// +--enable_warnings +delimiter ;// + +delimiter //; +### ### varchar +### ### https://work.aone.alibaba-inc.com/issue/35400448 +### DROP TABLE IF EXISTS t2// +### --error 1074 +### CREATE TABLE t2 ( +### id INT, +### res1 VARCHAR(128), +### d1 VARCHAR(16384) +### )// +### DROP TABLE IF EXISTS t3// +### --error 1074 +### CREATE TABLE t3 ( +### id INT, +### res1 VARCHAR(128), +### d1 VARCHAR(262145) +### )// +### DROP FUNCTION IF EXISTS fun_l// +### --error 1074 +### CREATE FUNCTION fun_l() RETURNS VARCHAR(262144) +### BEGIN +### DECLARE d1 VARCHAR(262144123456); +### SET d1='123456789012345678901234567890'; +### RETURN '定义长度262144123456的VARCHAR(262144123456)类型的变量'; +### END// +### --error 1305 +### SELECT fun_l()// + +### char +### https://work.aone.alibaba-inc.com/issue/35399998 +--disable_warnings + DROP TABLE IF EXISTS t1// + DROP TABLE IF EXISTS t2// +--enable_warnings + CREATE TABLE t1 ( + id INT, + res1 VARCHAR(128), + d1 CHAR(255) + )// +### --error 1074 +### TODO: https://work.aone.alibaba-inc.com/issue/35400448 +### CREATE TABLE t2 ( +### id INT, +### res1 VARCHAR(128), +### d1 CHAR(256) +### )// +--disable_warnings ONCE + DROP TABLE IF EXISTS t3// + --error 1074 + CREATE TABLE t3 ( + id INT, + res1 VARCHAR(128), + d1 CHAR(257) + )// + DROP PROCEDURE IF EXISTS `pro_1`// + --error 1074 + CREATE PROCEDURE pro_1() + BEGIN + DECLARE d1 CHAR(257); + SET d1='CHAR[(M)] M表示以字符为单位的列长度, M范围是 0~255'; + INSERT INTO t1 VALUES(1,'变量形式插入CHAR(257)类型数据',d1); + END// + --error 1305 + CALL pro_1()// + SELECT * FROM t1// + + +### varbinary +### https://work.aone.alibaba-inc.com/issue/35614023 +--disable_warnings ONCE +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 ( + d1 VARBINARY(65536) +)// +--disable_warnings ONCE +DROP TABLE IF EXISTS t2// +--error 1074 +CREATE TABLE t2 ( + d1 VARBINARY(1048577) +)// + +DROP FUNCTION IF EXISTS `fun_l`// +--error 1074 +CREATE FUNCTION fun_l() RETURNS VARBINARY(65535) +BEGIN + DECLARE d1 VARBINARY(65536); + SET d1='123456789012345678901234567890'; + RETURN '定义长度65536的VARCHAR类型的变量'; +END// + +--error 1305 +SELECT fun_l()// + + +### number +### https://work.aone.alibaba-inc.com/issue/35302277 +DROP FUNCTION IF EXISTS `fun_l`// +--error 1426 +CREATE FUNCTION fun_l() RETURNS DEC(65,30) +BEGIN + DECLARE a DEC(66,30); + SET a=123450.1415; + RETURN a; +END// +--error 1305 +SELECT fun_l()// +DROP FUNCTION IF EXISTS `fun_2`// +--error 1425 +CREATE FUNCTION fun_2() RETURNS DEC(65,30) +BEGIN + DECLARE a DEC(65,31); + SET a=50.1; + RETURN a; +END// +--error 1305 +SELECT fun_2()// + +### datetime +### https://work.aone.alibaba-inc.com/issue/35346065 +--disable_warnings ONCE +DROP TABLE IF EXISTS t2// +--error 1426 +CREATE TABLE t2 ( + id INT, + res1 VARCHAR(128), + d1 DATETIME(7) +)// +DROP FUNCTION IF EXISTS `fun_l`// +--error 1426 +CREATE FUNCTION fun_l() RETURNS DATETIME(6) +BEGIN + DECLARE d2 DATETIME(7) DEFAULT '2021-07-02 23:59:59.999999'; + RETURN d2; +END// +--error 1305 +SELECT fun_l()// + +### datetime max value insert fail +### https://work.aone.alibaba-inc.com/issue/35345945 +--disable_warnings ONCE +DROP TABLE IF EXISTS t2// +CREATE TABLE t2 ( + id INT, + res1 VARCHAR(128), + d1 DATETIME, + d2 DATETIME(0), + d3 DATETIME(6) +)// +INSERT INTO t2 VALUES(1,'插入DATETIME类型数据','1000-01-01 00:00:00.123','2000-01-01 00:00:00.123','9999-12-31 23:59:59.999999')// +DROP PROCEDURE IF EXISTS `pro_1`// +CREATE PROCEDURE pro_1() +BEGIN + DECLARE d1 DATETIME DEFAULT '1000-01-01 00:00:00.000000'; + DECLARE d2 DATETIME(0) DEFAULT '2021-07-02 23:59:59.999999'; + DECLARE d3 DATETIME(6) DEFAULT '9999-12-31 23:59:59.999999'; + INSERT INTO t2 VALUES(2,'变量形式插入DATETIME类型数据',d1,d2,d3); + INSERT INTO t2 VALUES(3,'直接插入DATETIME类型数据','3000-01-01 00:00:00.123','4000-01-01 00:00:00.123','9999-12-31 23:59:59.999999'); +END// +CALL pro_1()// +SELECT * FROM t2// + +### int +### https://work.aone.alibaba-inc.com/issue/35302003 +--disable_warnings ONCE +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 ( + id INT, + res1 VARCHAR(128), + a INT(255) +)// +DROP PROCEDURE IF EXISTS `pro_1`// +--error 1439 +CREATE PROCEDURE pro_1() +BEGIN + DECLARE a INT(256); + SET a=4294967295; + INSERT INTO t1 VALUES(1,'插入INT类型数据',a); +END// +--error 1305 +CALL pro_1()// +SELECT * FROM t1// + +### commit +### rollback +### https://work.aone.alibaba-inc.com/issue/34756672 +--disable_warnings ONCE +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 +( a INT +)// +--disable_warnings ONCE +DROP TABLE IF EXISTS t2// +CREATE TABLE t2 +( a INT +)// + +INSERT INTO t1 VALUES (1),(2),(3)// + +DROP PROCEDURE IF EXISTS `pro`// +CREATE PROCEDURE pro() +BEGIN + INSERT INTO t1 VALUES (4); + COMMIT; +END// + +call pro()// + +select * from t1// + +DROP PROCEDURE IF EXISTS `pro`// +CREATE PROCEDURE pro() +BEGIN + INSERT INTO t1 VALUES (4); + ROLLBACK; +END// + +call pro()// + +select * from t1// + +DROP FUNCTION IF EXISTS `fun1`// +####mysql: ERROR 1422 (HY000): Explicit or implicit commit is not allowed in stored function or trigger. +--error 1422 +CREATE FUNCTION fun1() RETURNS VARCHAR(128) +BEGIN + INSERT INTO t1 VALUES (4); + COMMIT; + return '显示提交'; +END// + +DROP FUNCTION IF EXISTS `fun2`// +CREATE FUNCTION fun2() RETURNS VARCHAR(128) +BEGIN + INSERT INTO t1 VALUES (4); + return '隐式提交'; +END// + +select fun2()// + +select * from t1// + +DROP FUNCTION IF EXISTS `fun3`// +--error 1422 +CREATE FUNCTION fun3() RETURNS VARCHAR(128) +BEGIN + INSERT INTO t1 VALUES (4); + ROLLBACK; + return '回滚'; +END// + +### BIT +### https://work.aone.alibaba-inc.com/issue/35280082 +--disable_warnings ONCE +DROP TABLE IF EXISTS t1;// +DROP PROCEDURE IF EXISTS `pro_2`;// +--error 1439 +CREATE PROCEDURE pro_2() +BEGIN + CREATE TABLE t1 (id INT,a BIT(65)); + INSERT INTO t1 VALUES(1,b'0'); +END; +// + +### load data +### https://work.aone.alibaba-inc.com/issue/34756578 +--disable_warnings ONCE +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 (a INT)// +INSERT INTO t1 VALUES (1),(2),(3)// +DROP PROCEDURE IF EXISTS `pro_22`// + +--error 1314 +CREATE PROCEDURE pro_22() +BEGIN + LOAD DATA INFILE 'data.txt' INTO TABLE t1; +END// + +### lock +### https://work.aone.alibaba-inc.com/issue/34756555 +--disable_warnings ONCE +DROP TABLE IF EXISTS t1// +CREATE TABLE t1 (a INT)// +INSERT INTO t1 VALUES (1),(2),(3)// +DROP PROCEDURE IF EXISTS `pro_1`// +--error 1314 +CREATE PROCEDURE pro_1() +BEGIN + LOCK TABLES t1 READ; +END// + +delimiter ;// +--disable_warnings ONCE +DROP TABLE IF EXISTS t1; +--disable_warnings ONCE +DROP TABLE IF EXISTS t2; +--disable_warnings ONCE +DROP TABLE IF EXISTS t3; +DROP PROCEDURE IF EXISTS `pro_1`; +DROP FUNCTION IF EXISTS `fun_l`; +DROP PROCEDURE IF EXISTS `pro_22`; diff --git a/tools/deploy/mysql_test/test_suite/pl/t/pl_dbt2_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/pl_dbt2_mysql.test new file mode 100644 index 000000000..a7db46463 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/pl_dbt2_mysql.test @@ -0,0 +1,1436 @@ +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log +#owner: linlin.xll +#owner group: sql1 +#description: + +--result_format 4 + +--disable_query_log +--disable_result_log +--source mysql_test/include/index_quick_major.inc +--enable_query_log +--enable_result_log + +use test; + +set ob_query_timeout=100000000; + +--disable_warnings +DROP TABLE IF EXISTS customer; +DROP TABLE IF EXISTS district; +DROP TABLE IF EXISTS history; +DROP TABLE IF EXISTS item; +DROP TABLE IF EXISTS new_order; +DROP TABLE IF EXISTS order_line; +DROP TABLE IF EXISTS orders; +DROP TABLE IF EXISTS stock; +DROP TABLE IF EXISTS warehouse; +DROP PROCEDURE IF EXISTS delivery; +DROP PROCEDURE IF EXISTS new_order_2; +DROP PROCEDURE IF EXISTS new_order; +DROP PROCEDURE IF EXISTS order_status; +DROP PROCEDURE IF EXISTS payment; +DROP PROCEDURE IF EXISTS stock_level; +--enable_warnings + +CREATE TABLE customer ( + c_id int(11) NOT NULL default '0', + c_d_id int(11) NOT NULL default '0', + c_w_id int(11) NOT NULL default '0', + c_first varchar(16) default NULL, + c_middle char(2) default NULL, + c_last varchar(16) default NULL, + c_street_1 varchar(20) default NULL, + c_street_2 varchar(20) default NULL, + c_city varchar(20) default NULL, + c_state char(2) default NULL, + c_zip varchar(9) default NULL, + c_phone varchar(16) default NULL, + c_since timestamp NOT NULL, + c_credit char(2) default NULL, + c_credit_lim decimal(24,12) default NULL, + c_discount double default NULL, + c_balance decimal(24,12) default NULL, + c_ytd_payment decimal(24,12) default NULL, + c_payment_cnt double default NULL, + c_delivery_cnt double default NULL, + c_data varchar(500), + PRIMARY KEY (c_w_id,c_d_id,c_id), + KEY c_w_id (c_w_id,c_d_id,c_last,c_first) +); + +CREATE TABLE district ( + d_id int(11) NOT NULL default '0', + d_w_id int(11) NOT NULL default '0', + d_name varchar(10) default NULL, + d_street_1 varchar(20) default NULL, + d_street_2 varchar(20) default NULL, + d_city varchar(20) default NULL, + d_state char(2) default NULL, + d_zip varchar(9) default NULL, + d_tax double default NULL, + d_ytd decimal(24,12) default NULL, + d_next_o_id int(11) default NULL, + PRIMARY KEY (d_w_id,d_id) +); + +CREATE TABLE history ( + h_id bigint(20) auto_increment, + h_c_id int(11) default NULL, + h_c_d_id int(11) default NULL, + h_c_w_id int(11) default NULL, + h_d_id int(11) default NULL, + h_w_id int(11) NOT NULL default '0', + h_date timestamp NOT NULL, + h_amount double default NULL, + h_data varchar(24) default NULL, + PRIMARY KEY (h_id, h_w_id) +); + +CREATE TABLE item ( + i_id int(11) NOT NULL default '0', + i_im_id int(11) default NULL, + i_name varchar(24) default NULL, + i_price double default NULL, + i_data varchar(50) default NULL, + PRIMARY KEY (i_id) +); + +CREATE TABLE new_order ( + no_o_id int(11) NOT NULL default '0', + no_d_id int(11) NOT NULL default '0', + no_w_id int(11) NOT NULL default '0', + PRIMARY KEY (no_w_id,no_d_id,no_o_id) +); + +CREATE TABLE order_line ( + ol_o_id int(11) NOT NULL default '0', + ol_d_id int(11) NOT NULL default '0', + ol_w_id int(11) NOT NULL default '0', + ol_number int(11) NOT NULL default '0', + ol_i_id int(11) default NULL, + ol_supply_w_id int(11) default NULL, + ol_delivery_d timestamp NOT NULL, + ol_quantity double default NULL, + ol_amount double default NULL, + ol_dist_info varchar(24) default NULL, + PRIMARY KEY (ol_w_id,ol_d_id,ol_o_id,ol_number) +); + +CREATE TABLE orders ( + o_id int(11) NOT NULL default '0', + o_d_id int(11) NOT NULL default '0', + o_w_id int(11) NOT NULL default '0', + o_c_id int(11) default NULL, + o_entry_d timestamp NOT NULL, + o_carrier_id int(11) default NULL, + o_ol_cnt int(11) default NULL, + o_all_local double default NULL, + PRIMARY KEY (o_w_id,o_d_id,o_id), + KEY o_w_id (o_w_id,o_d_id,o_c_id,o_id) +); + +CREATE TABLE stock ( + s_i_id int(11) NOT NULL default '0', + s_w_id int(11) NOT NULL default '0', + s_quantity double NOT NULL default '0', + s_dist_01 varchar(24) default NULL, + s_dist_02 varchar(24) default NULL, + s_dist_03 varchar(24) default NULL, + s_dist_04 varchar(24) default NULL, + s_dist_05 varchar(24) default NULL, + s_dist_06 varchar(24) default NULL, + s_dist_07 varchar(24) default NULL, + s_dist_08 varchar(24) default NULL, + s_dist_09 varchar(24) default NULL, + s_dist_10 varchar(24) default NULL, + s_ytd decimal(16,8) default NULL, + s_order_cnt double default NULL, + s_remote_cnt double default NULL, + s_data varchar(50) default NULL, + PRIMARY KEY (s_w_id,s_i_id), + KEY (s_w_id,s_i_id,s_quantity) +); + +CREATE TABLE warehouse ( + w_id int(11) NOT NULL default '0', + w_name varchar(10) default NULL, + w_street_1 varchar(20) default NULL, + w_street_2 varchar(20) default NULL, + w_city varchar(20) default NULL, + w_state char(2) default NULL, + w_zip varchar(9) default NULL, + w_tax double default NULL, + w_ytd decimal(24,12) default NULL, + PRIMARY KEY (w_id) +); + +delimiter //; + +CREATE PROCEDURE delivery(in_w_id INT, in_o_carrier_id INT) +BEGIN + DECLARE out_c_id INT; + DECLARE out_ol_amount INT; + DECLARE tmp_d_id INT; + DECLARE tmp_o_id INT default 0; + + SET tmp_d_id = 1; + + while tmp_d_id <= 10 DO + BEGIN + + SET tmp_o_id= 0; + + SELECT no_o_id + FROM new_order + WHERE no_w_id = in_w_id AND no_d_id = tmp_d_id + ORDER BY no_o_id ASC + LIMIT 1 + FOR UPDATE INTO tmp_o_id; + + IF tmp_o_id > 0 + THEN + DELETE FROM new_order + WHERE no_o_id = tmp_o_id + AND no_w_id = in_w_id + AND no_d_id = tmp_d_id; + + SELECT o_c_id + FROM orders + WHERE o_id = tmp_o_id + AND o_w_id = in_w_id + AND o_d_id = tmp_d_id + FOR UPDATE INTO out_c_id; + + UPDATE orders + SET o_carrier_id = in_o_carrier_id + WHERE o_id = tmp_o_id + AND o_w_id = in_w_id + AND o_d_id = tmp_d_id; + + UPDATE order_line force index (primary) + SET ol_delivery_d = current_timestamp + WHERE ol_o_id = tmp_o_id + AND ol_w_id = in_w_id + AND ol_d_id = tmp_d_id; + + SELECT SUM(ol_amount * ol_quantity) + FROM order_line force index (primary) + WHERE ol_o_id = tmp_o_id + AND ol_w_id = in_w_id + AND ol_d_id = tmp_d_id INTO out_ol_amount; + + UPDATE customer + SET c_delivery_cnt = c_delivery_cnt + 1, + c_balance = c_balance + out_ol_amount + WHERE c_id = out_c_id + AND c_w_id = in_w_id + AND c_d_id = tmp_d_id; + + END IF; + + SET tmp_d_id = tmp_d_id + 1; + + END; + END WHILE; +END// + +CREATE PROCEDURE new_order_2 (in_w_id INT, + in_d_id INT, + in_ol_i_id INT, + in_ol_quantity INT, + in_i_price NUMERIC, + in_i_name VARCHAR(24), + in_i_data VARCHAR(50), + in_ol_o_id INT, + in_ol_amount NUMERIC, + in_ol_supply_w_id INT, + in_ol_number INT, + out out_s_quantity INT) +BEGIN + + DECLARE tmp_s_dist VARCHAR(255); + DECLARE tmp_s_data VARCHAR(255); + + SET out_s_quantity = 0; + + IF in_d_id = 1 THEN + SELECT s_quantity, s_dist_01, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 2 THEN + SELECT s_quantity, s_dist_02, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 3 THEN + SELECT s_quantity, s_dist_03, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 4 THEN + SELECT s_quantity, s_dist_04, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 5 THEN + SELECT s_quantity, s_dist_05, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 6 THEN + SELECT s_quantity, s_dist_06, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 7 THEN + SELECT s_quantity, s_dist_07, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 8 THEN + SELECT s_quantity, s_dist_08, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 9 THEN + SELECT s_quantity, s_dist_09, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + + ELSEIF in_d_id = 10 THEN + SELECT s_quantity, s_dist_10, s_data + FROM stock + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id + FOR UPDATE + INTO out_s_quantity, tmp_s_dist, tmp_s_data; + END IF; + + IF out_s_quantity > in_ol_quantity + 10 THEN + UPDATE stock + SET s_quantity = out_s_quantity - in_ol_quantity + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id; + ELSE + UPDATE stock + SET s_quantity = out_s_quantity - in_ol_quantity + 91 + WHERE s_i_id = in_ol_i_id + AND s_w_id = in_w_id; + END IF; + + INSERT INTO order_line (ol_o_id, ol_d_id, ol_w_id, ol_number, ol_i_id, + ol_supply_w_id, ol_delivery_d, ol_quantity, + ol_amount, ol_dist_info) + VALUES (in_ol_o_id, in_d_id, in_w_id, in_ol_number, in_ol_i_id, + in_ol_supply_w_id, NULL, in_ol_quantity, in_ol_amount, + tmp_s_dist); +END// + +CREATE PROCEDURE new_order(tmp_w_id INT, + tmp_d_id INT, + tmp_c_id INT, + tmp_o_all_local INT, + tmp_o_ol_cnt INT, + ol_i_id1 INT, + ol_supply_w_id1 INT, + ol_quantity1 INT, + ol_i_id2 INT, + ol_supply_w_id2 INT, + ol_quantity2 INT, + ol_i_id3 INT, + ol_supply_w_id3 INT, + ol_quantity3 INT, + ol_i_id4 INT, + ol_supply_w_id4 INT, + ol_quantity4 INT, + ol_i_id5 INT, + ol_supply_w_id5 INT, + ol_quantity5 INT, + ol_i_id6 INT, + ol_supply_w_id6 INT, + ol_quantity6 INT, + ol_i_id7 INT, + ol_supply_w_id7 INT, + ol_quantity7 INT, + ol_i_id8 INT, + ol_supply_w_id8 INT, + ol_quantity8 INT, + ol_i_id9 INT, + ol_supply_w_id9 INT, + ol_quantity9 INT, + ol_i_id10 INT, + ol_supply_w_id10 INT, + ol_quantity10 INT, + ol_i_id11 INT, + ol_supply_w_id11 INT, + ol_quantity11 INT, + ol_i_id12 INT, + ol_supply_w_id12 INT, + ol_quantity12 INT, + ol_i_id13 INT, + ol_supply_w_id13 INT, + ol_quantity13 INT, + ol_i_id14 INT, + ol_supply_w_id14 INT, + ol_quantity14 INT, + ol_i_id15 INT, + ol_supply_w_id15 INT, + ol_quantity15 INT, + out rc int) +BEGIN + DECLARE out_c_credit VARCHAR(255); + DECLARE tmp_i_name VARCHAR(255); + DECLARE tmp_i_data VARCHAR(255); + DECLARE out_c_last VARCHAR(255); + + DECLARE tmp_ol_supply_w_id INT; + DECLARE tmp_ol_quantity INT; + DECLARE out_d_next_o_id INT; + DECLARE tmp_i_id INT; + + DECLARE tmp_s_quantity INT; + + DECLARE out_w_tax REAL; + DECLARE out_d_tax REAL; + DECLARE out_c_discount REAL; + DECLARE tmp_i_price REAL; + DECLARE tmp_ol_amount REAL; + DECLARE tmp_total_amount REAL; + + DECLARE o_id INT; + + declare exit handler for sqlstate '02000' set rc = 1; + + SET rc=0; + + SET o_id = 0; + + SELECT w_tax + FROM warehouse + WHERE w_id = tmp_w_id + INTO out_w_tax; + + SELECT d_tax, d_next_o_id + FROM district + WHERE d_w_id = tmp_w_id + AND d_id = tmp_d_id FOR UPDATE + INTO out_d_tax, out_d_next_o_id; + + SET o_id=out_d_next_o_id; + + UPDATE district + SET d_next_o_id = out_d_next_o_id + 1 + WHERE d_w_id = tmp_w_id + AND d_id = tmp_d_id; + + SELECT c_discount , c_last, c_credit + FROM customer + WHERE c_w_id = tmp_w_id + AND c_d_id = tmp_d_id + AND c_id = tmp_c_id + INTO out_c_discount, out_c_last, out_c_credit; + + INSERT INTO new_order (no_o_id, no_d_id, no_w_id) + VALUES (out_d_next_o_id, tmp_d_id, tmp_w_id); + + INSERT INTO orders (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, + o_carrier_id, o_ol_cnt, o_all_local) + VALUES (out_d_next_o_id, tmp_d_id, tmp_w_id, tmp_c_id, + current_timestamp, NULL, tmp_o_ol_cnt, tmp_o_all_local); + + SET tmp_total_amount = 0; + + IF tmp_o_ol_cnt > 0 + THEN + + SET tmp_i_id = ol_i_id1; + SET tmp_ol_supply_w_id = ol_supply_w_id1; + SET tmp_ol_quantity = ol_quantity1; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 1, tmp_s_quantity); + + SET tmp_total_amount = tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 1 + THEN + SET tmp_i_id = ol_i_id2; + SET tmp_ol_supply_w_id = ol_supply_w_id2; + SET tmp_ol_quantity = ol_quantity2; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 2, tmp_s_quantity); + + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + IF tmp_o_ol_cnt > 2 + THEN + SET tmp_i_id = ol_i_id3; + SET tmp_ol_supply_w_id = ol_supply_w_id3; + SET tmp_ol_quantity = ol_quantity3; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 3, tmp_s_quantity); + + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 3 + THEN + SET tmp_i_id = ol_i_id4; + SET tmp_ol_supply_w_id = ol_supply_w_id4; + SET tmp_ol_quantity = ol_quantity4; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 4, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 4 + THEN + SET tmp_i_id = ol_i_id5; + SET tmp_ol_supply_w_id = ol_supply_w_id5; + SET tmp_ol_quantity = ol_quantity5; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 5, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 5 + THEN + SET tmp_i_id = ol_i_id6; + SET tmp_ol_supply_w_id = ol_supply_w_id6; + SET tmp_ol_quantity = ol_quantity6; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 6, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 6 + THEN + SET tmp_i_id = ol_i_id7; + SET tmp_ol_supply_w_id = ol_supply_w_id7; + SET tmp_ol_quantity = ol_quantity7; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 7, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 7 + THEN + SET tmp_i_id = ol_i_id8; + SET tmp_ol_supply_w_id = ol_supply_w_id8; + SET tmp_ol_quantity = ol_quantity8; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 8, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 8 + THEN + SET tmp_i_id = ol_i_id9; + SET tmp_ol_supply_w_id = ol_supply_w_id9; + SET tmp_ol_quantity = ol_quantity9; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 9, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 9 + THEN + SET tmp_i_id = ol_i_id10; + SET tmp_ol_supply_w_id = ol_supply_w_id10; + SET tmp_ol_quantity = ol_quantity10; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 10, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 10 + THEN + SET tmp_i_id = ol_i_id11; + SET tmp_ol_supply_w_id = ol_supply_w_id11; + SET tmp_ol_quantity = ol_quantity11; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 11, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 11 + THEN + SET tmp_i_id = ol_i_id12; + SET tmp_ol_supply_w_id = ol_supply_w_id12; + SET tmp_ol_quantity = ol_quantity12; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 12, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 12 + THEN + SET tmp_i_id = ol_i_id13; + SET tmp_ol_supply_w_id = ol_supply_w_id13; + SET tmp_ol_quantity = ol_quantity13; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 13, tmp_s_quantity); + + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 13 + THEN + SET tmp_i_id = ol_i_id14; + SET tmp_ol_supply_w_id = ol_supply_w_id14; + SET tmp_ol_quantity = ol_quantity14; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 14, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; + + IF tmp_o_ol_cnt > 14 + THEN + SET tmp_i_id = ol_i_id15; + SET tmp_ol_supply_w_id = ol_supply_w_id15; + SET tmp_ol_quantity = ol_quantity15; + + SELECT i_price, i_name, i_data + FROM item + WHERE i_id = tmp_i_id + INTO tmp_i_price, tmp_i_name, tmp_i_data; + + IF tmp_i_price > 0 + THEN + SET tmp_ol_amount = tmp_i_price * tmp_ol_quantity; + call new_order_2(tmp_w_id, tmp_d_id, tmp_i_id, + tmp_ol_quantity, tmp_i_price, + tmp_i_name, tmp_i_data, + out_d_next_o_id, tmp_ol_amount, + tmp_ol_supply_w_id, 15, tmp_s_quantity); + SET tmp_total_amount = tmp_total_amount + tmp_ol_amount; + END IF; + END IF; +END// + +CREATE PROCEDURE order_status (in_c_id INT, + in_c_w_id INT, + in_c_d_id INT, + in_c_last VARCHAR(16)) +BEGIN + DECLARE out_c_first VARCHAR(255); + DECLARE out_c_middle char(2); + DECLARE out_c_balance NUMERIC; + DECLARE out_o_id INT; + DECLARE out_o_carrier_id INT; + DECLARE out_o_entry_d VARCHAR(28); + DECLARE out_o_ol_cnt INT; + DECLARE out_ol_supply_w_id1 INT; + DECLARE out_ol_i_id1 INT; + DECLARE out_ol_quantity1 INT; + DECLARE out_ol_amount1 NUMERIC; + DECLARE out_ol_delivery_d1 VARCHAR(28); + DECLARE out_ol_supply_w_id2 INT; + DECLARE out_ol_i_id2 INT; + DECLARE out_ol_quantity2 INT; + DECLARE out_ol_amount2 NUMERIC; + DECLARE out_ol_delivery_d2 VARCHAR(28); + DECLARE out_ol_supply_w_id3 INT; + DECLARE out_ol_i_id3 INT; + DECLARE out_ol_quantity3 INT; + DECLARE out_ol_amount3 NUMERIC; + DECLARE out_ol_delivery_d3 VARCHAR(28); + DECLARE out_ol_supply_w_id4 INT; + DECLARE out_ol_i_id4 INT; + DECLARE out_ol_quantity4 INT; + DECLARE out_ol_amount4 NUMERIC; + DECLARE out_ol_delivery_d4 VARCHAR(28); + DECLARE out_ol_supply_w_id5 INT; + DECLARE out_ol_i_id5 INT; + DECLARE out_ol_quantity5 INT; + DECLARE out_ol_amount5 NUMERIC; + DECLARE out_ol_delivery_d5 VARCHAR(28); + DECLARE out_ol_supply_w_id6 INT; + DECLARE out_ol_i_id6 INT; + DECLARE out_ol_quantity6 INT; + DECLARE out_ol_amount6 NUMERIC; + DECLARE out_ol_delivery_d6 VARCHAR(28); + DECLARE out_ol_supply_w_id7 INT; + DECLARE out_ol_i_id7 INT; + DECLARE out_ol_quantity7 INT; + DECLARE out_ol_amount7 NUMERIC; + DECLARE out_ol_delivery_d7 VARCHAR(28); + DECLARE out_ol_supply_w_id8 INT; + DECLARE out_ol_i_id8 INT; + DECLARE out_ol_quantity8 INT; + DECLARE out_ol_amount8 NUMERIC; + DECLARE out_ol_delivery_d8 VARCHAR(28); + DECLARE out_ol_supply_w_id9 INT; + DECLARE out_ol_i_id9 INT; + DECLARE out_ol_quantity9 INT; + DECLARE out_ol_amount9 NUMERIC; + DECLARE out_ol_delivery_d9 VARCHAR(28); + DECLARE out_ol_supply_w_id10 INT; + DECLARE out_ol_i_id10 INT; + DECLARE out_ol_quantity10 INT; + DECLARE out_ol_amount10 NUMERIC; + DECLARE out_ol_delivery_d10 VARCHAR(28); + DECLARE out_ol_supply_w_id11 INT; + DECLARE out_ol_i_id11 INT; + DECLARE out_ol_quantity11 INT; + DECLARE out_ol_amount11 NUMERIC; + DECLARE out_ol_delivery_d11 VARCHAR(28); + DECLARE out_ol_supply_w_id12 INT; + DECLARE out_ol_i_id12 INT; + DECLARE out_ol_quantity12 INT; + DECLARE out_ol_amount12 NUMERIC; + DECLARE out_ol_delivery_d12 VARCHAR(28); + DECLARE out_ol_supply_w_id13 INT; + DECLARE out_ol_i_id13 INT; + DECLARE out_ol_quantity13 INT; + DECLARE out_ol_amount13 NUMERIC; + DECLARE out_ol_delivery_d13 VARCHAR(28); + DECLARE out_ol_supply_w_id14 INT; + DECLARE out_ol_i_id14 INT; + DECLARE out_ol_quantity14 INT; + DECLARE out_ol_amount14 NUMERIC; + DECLARE out_ol_delivery_d14 VARCHAR(28); + DECLARE out_ol_supply_w_id15 INT; + DECLARE out_ol_i_id15 INT; + DECLARE out_ol_quantity15 INT; + DECLARE out_ol_amount15 NUMERIC; + DECLARE out_ol_delivery_d15 VARCHAR(28); + DECLARE out_c_id INT; + DECLARE out_c_last VARCHAR(255); + DECLARE rc int default 0; + + declare c cursor for SELECT ol_i_id, ol_supply_w_id, ol_quantity, ol_amount, ol_delivery_d + FROM order_line force index (primary) + WHERE ol_w_id = in_c_w_id + AND ol_d_id = in_c_d_id + AND ol_o_id = out_o_id; + declare continue handler for sqlstate '02000' set rc = 1; + # /* + # * Pick a customer by searching for c_last, should pick the one in the + # * middle, not the first one. + # */ + IF in_c_id = 0 + THEN + SELECT c_id + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_last = in_c_last + ORDER BY c_first ASC LIMIT 1 + INTO out_c_id; + ELSE + set out_c_id = in_c_id; + END IF; + + SELECT c_first, c_middle, c_last, c_balance + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_id = out_c_id + INTO out_c_first, out_c_middle, out_c_last, out_c_balance; + + SELECT o_id, o_carrier_id, o_entry_d, o_ol_cnt + FROM orders + WHERE o_w_id = in_c_w_id + AND o_d_id = in_c_d_id + AND o_c_id = out_c_id + ORDER BY o_id DESC LIMIT 1 + INTO out_o_id, out_o_carrier_id, out_o_entry_d, out_o_ol_cnt; + + open c; + fetch_block: + BEGIN + fetch c into out_ol_i_id1, out_ol_supply_w_id1, out_ol_quantity1, + out_ol_amount1, out_ol_delivery_d1; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id2, out_ol_supply_w_id2, out_ol_quantity2, + out_ol_amount2, out_ol_delivery_d2; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id3, out_ol_supply_w_id3, out_ol_quantity3, + out_ol_amount3, out_ol_delivery_d3; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id4, out_ol_supply_w_id4, out_ol_quantity4, + out_ol_amount4, out_ol_delivery_d4; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id5, out_ol_supply_w_id5, out_ol_quantity5, + out_ol_amount5, out_ol_delivery_d5; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id6, out_ol_supply_w_id6, out_ol_quantity6, + out_ol_amount6, out_ol_delivery_d6; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id7, out_ol_supply_w_id7, out_ol_quantity7, + out_ol_amount7, out_ol_delivery_d7; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id8, out_ol_supply_w_id8, out_ol_quantity8, + out_ol_amount8, out_ol_delivery_d8; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id9, out_ol_supply_w_id9, out_ol_quantity9, + out_ol_amount9, out_ol_delivery_d9; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id10, out_ol_supply_w_id10, out_ol_quantity10, + out_ol_amount10, out_ol_delivery_d10; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id11, out_ol_supply_w_id11, out_ol_quantity11, + out_ol_amount11, out_ol_delivery_d11; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id12, out_ol_supply_w_id12, out_ol_quantity12, + out_ol_amount12, out_ol_delivery_d12; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id13, out_ol_supply_w_id13, out_ol_quantity13, + out_ol_amount13, out_ol_delivery_d13; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id14, out_ol_supply_w_id14, out_ol_quantity14, + out_ol_amount14, out_ol_delivery_d14; + if rc then + leave fetch_block; + end if; + fetch c into out_ol_i_id15, out_ol_supply_w_id15, out_ol_quantity15, + out_ol_amount15, out_ol_delivery_d15; + end fetch_block; + close c; +END// + + +CREATE PROCEDURE payment(in_w_id INT, in_d_id INT, in_c_id INT, in_c_w_id INT, in_c_d_id INT, + in_c_last VARCHAR(16), in_h_amount INT) +BEGIN + DECLARE out_w_name VARCHAR(10); + DECLARE out_w_street_1 VARCHAR(20); + DECLARE out_w_street_2 VARCHAR(20); + DECLARE out_w_city VARCHAR(20); + DECLARE out_w_state VARCHAR(2); + DECLARE out_w_zip VARCHAR(9); + DECLARE out_w_ytd INTEGER; + + DECLARE out_d_name VARCHAR(10); + DECLARE out_d_street_1 VARCHAR(20); + DECLARE out_d_street_2 VARCHAR(20); + DECLARE out_d_city VARCHAR(20); + DECLARE out_d_state VARCHAR(2); + DECLARE out_d_zip VARCHAR(9); + DECLARE out_d_ytd INTEGER; + + DECLARE out_c_id INTEGER; + DECLARE out_c_first VARCHAR(16); + DECLARE out_c_middle VARCHAR(2); + DECLARE out_c_last VARCHAR(20); + DECLARE out_c_street_1 VARCHAR(20); + DECLARE out_c_street_2 VARCHAR(20); + DECLARE out_c_city VARCHAR(20); + DECLARE out_c_state VARCHAR(2); + DECLARE out_c_zip VARCHAR(9); + DECLARE out_c_phone VARCHAR(16); + DECLARE out_c_since VARCHAR(28); + DECLARE out_c_credit VARCHAR(2); + DECLARE out_c_credit_lim DECIMAL(24, 12); + DECLARE out_c_discount REAL; + DECLARE out_c_balance NUMERIC; + DECLARE out_c_data VARCHAR(500); + DECLARE out_c_ytd_payment INTEGER; + + # /* Goofy temporaty variables. */ + DECLARE tmp_c_id VARCHAR(30); + DECLARE tmp_c_d_id VARCHAR(30); + DECLARE tmp_c_w_id VARCHAR(30); + DECLARE tmp_d_id VARCHAR(30); + DECLARE tmp_w_id VARCHAR(30); + DECLARE tmp_h_amount VARCHAR(30); + + # /* This one is not goofy. */ + DECLARE tmp_h_data VARCHAR(30); + + SELECT w_name, w_street_1, w_street_2, w_city, w_state, w_zip, w_ytd + FROM warehouse + WHERE w_id = in_w_id + FOR UPDATE + INTO out_w_name, out_w_street_1, out_w_street_2, out_w_city, + out_w_state, out_w_zip, out_w_ytd; + + UPDATE warehouse + SET w_ytd = out_w_ytd + in_h_amount + WHERE w_id = in_w_id; + + SELECT d_name, d_street_1, d_street_2, d_city, d_state, d_zip, d_ytd + FROM district + WHERE d_id = in_d_id + AND d_w_id = in_w_id + FOR UPDATE + INTO out_d_name, out_d_street_1, out_d_street_2, out_d_city, + out_d_state, out_d_zip, out_d_ytd; + + UPDATE district + SET d_ytd = out_d_ytd + in_h_amount + WHERE d_id = in_d_id + AND d_w_id = in_w_id; + + #/* + # * Pick a customer by searching for c_last, should pick the one in the + # * middle, not the first one. + # */ + IF in_c_id = 0 THEN + SELECT c_id + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_last = in_c_last + ORDER BY c_first ASC LIMIT 1 + FOR UPDATE + INTO out_c_id; + ELSE + SET out_c_id = in_c_id; + END IF; + + SELECT c_first, c_middle, c_last, c_street_1, c_street_2, c_city, + c_state, c_zip, c_phone, c_since, c_credit, + c_credit_lim, c_discount, c_balance, c_data, + c_ytd_payment + FROM customer + WHERE c_w_id = in_c_w_id + AND c_d_id = in_c_d_id + AND c_id = out_c_id + FOR UPDATE + INTO out_c_first, out_c_middle, out_c_last, out_c_street_1, + out_c_street_2, out_c_city, out_c_state, out_c_zip, out_c_phone, + out_c_since, out_c_credit, out_c_credit_lim, out_c_discount, + out_c_balance, out_c_data, out_c_ytd_payment; + + # /* Check credit rating. */ + IF out_c_credit = 'BC' + THEN + SELECT out_c_id + INTO tmp_c_id; + SELECT in_c_d_id + INTO tmp_c_d_id; + SELECT in_c_w_id + INTO tmp_c_w_id; + SELECT in_d_id + INTO tmp_d_id; + SELECT in_w_id + INTO tmp_w_id; + + SET out_c_data = concat(tmp_c_id,' ',tmp_c_d_id,' ',tmp_c_w_id,' ',tmp_d_id,' ',tmp_w_id); + + UPDATE customer + SET c_balance = out_c_balance - in_h_amount, + c_ytd_payment = out_c_ytd_payment + 1, + c_data = out_c_data + WHERE c_id = out_c_id + AND c_w_id = in_c_w_id + AND c_d_id = in_c_d_id; + ELSE + UPDATE customer + SET c_balance = out_c_balance - in_h_amount, + c_ytd_payment = out_c_ytd_payment + 1 + WHERE c_id = out_c_id + AND c_w_id = in_c_w_id + AND c_d_id = in_c_d_id; + END IF; + + SET tmp_h_data = concat(out_w_name,' ', out_d_name); + INSERT INTO history (h_c_id, h_c_d_id, h_c_w_id, h_d_id, h_w_id, + h_date, h_amount, h_data) + VALUES (out_c_id, in_c_d_id, in_c_w_id, in_d_id, in_w_id, + current_timestamp, in_h_amount, tmp_h_data); + + # RETURN out_c_id; +END // + +CREATE PROCEDURE stock_level(in_w_id INT, + in_d_id INT, + in_threshold INT, + OUT low_stock INT) +BEGIN + DECLARE tmp_d_next_o_id INT; + + SELECT d_next_o_id + FROM district + WHERE d_w_id = in_w_id + AND d_id = in_d_id + INTO tmp_d_next_o_id; + + SELECT count(*) + FROM order_line, stock, district + WHERE d_id = in_d_id + AND d_w_id = in_w_id + AND d_id = ol_d_id + AND d_w_id = ol_w_id + AND ol_i_id = s_i_id + AND ol_w_id = s_w_id + AND s_quantity < in_threshold + AND ol_o_id BETWEEN (tmp_d_next_o_id - 20) + AND (tmp_d_next_o_id - 1) + INTO low_stock; +END// + +delimiter ;// + +## LOAD DATA +## ./src/datagen -w 1 -m 1 -c 1 -i 1 -o 1 -n 1 -d /home/linlin.xll/work/dbt2-0.37.50.15/data/ --mysql +## sh mysql_load_db.sh --mysql-path /usr/bin/mysql --host 10.244.4.65 --local --path /home/linlin.xll/data/ +## sh mysql_load_sp.sh --client-path /usr/bin/ --host 10.244.4.65 +## sh run_mysql.sh --connections 1 --time 10 --warehouses 1 --host 10.244.4.65 --lib-client-path /usr/bin/mysql --verbose --terminals 1 + +insert into customer values(1,1,1,"4W+?M?/aG","OE","BARBARBAR","?VJ;t+P??m5v2?.=?T","%N#RO?|??;[_??~!Y?HP","?[S!JV58?#;+$cP?=d","tw",547411111,3078688431492068,"2018-09-13 15:23:42","GC",50000.00,0.0012,-10.00,10.00,1,0,"?&s?Jf4\\>?oCj'n?HR`i]c?uDH&-w?4??}{39?mL?2mC712Tao??1?oJ)kLvP^_:91BO??qs?F*t#[???m?7sX7|p*Nne?d|\\X}T'?tC?t??-???Ox'?&4zt4?9v?rQ?'#q.?CF??1???x?@G?5K???&?*sk{??x?N{~f?_P%7]z?G?O:0EM<+??*X[W??Y)???V2pfk??Dm=??L/4v@=X?=?[rpD(w??eM?+?\\??}O?|GB?P??kC??%FMs_SAV4??$?fVoB1?8?8WXfCC&c6?_Q-'?]FBg??a?\\?Vt!H?z"); +insert into customer values(1,3,1,"?0?WH??\\|L??", "OE", "BARBARBAR", "n9m?}j|H@TZ??gFp\\kFAi(7?]W?(?_<`o]SE?fk???}?_?]?ax/?v;?1ol0a?A?n{G?^?QOxA?e}??lOmpMA?6HNxM?wk?CD%(w?P$Un#?B???>HQ`_0s?\\I&F?o$6??5]?b_7.Y$EH?%c$U?aZi;???8??2?q0?-?aa?d???5m?up5k/e3HV?dcqFsV?xU?X?VMNC;*V???T?b`Xr}?`@E&c?[Mc?:?wmD??T!18?'aug?*/r?l?/pH?(kZ??IaEbY'?Q/?14Y|pN?|?fF?j??Y?i?tI03kpaiZ?mY?v?oD3J?/?9?N????MkSkq[5??sv~>$r???3?^%?B4?m!_G???*RWd\\k[-70H9?/??7?H:?gC_)D?N??+?)`]\\??f5??D"); +insert into customer values(1,4,1,"?:Y??~5|CN9", "OE", "BARBARBAR", "g)fX?oQ?%?B", "p~7aXX/>g]9f:D8RgFr", "M6a+z??}i)?7}", "yL", 361011111, 7420033904334245, "2018-09-13 15:23:42", "GC", 50000.00, 0.3738, -10.00, 10.00, 1, 0, "N*f7vnUE?9G<_`????b2?\\Fp^:?H??9$?t9]8lx???17S??R{XYz?|@E?3kj?yd?Dr4Y1;Z???L3Up]z~lb?r?~dM?^p?eIqp??v?=e?&??YMN1(?q?XPb?{FVI$?gkVGN)0`e?dJ??t$?s?hV???7^1b}3PB||_??l^>Y?]8?02?x?E#.0?:d?y?&?^?p?}Rd9e?/?(?%0y{??t(?a@ZU?vY?37Q!?xe?iXjqw&?O??S??-AQ?0?7TzR]`??HPc\\???]]?P??=3{?=?"); +insert into customer values(1,5,1,"2?'>Pxn?.d", "OE", "BARBARBAR", "T?(?~?~2Qs_1[r", "+oS!?[??vL_B-j?r?lxv", "dJO????LT1", "wr", 609111111, 1509496824653474, "2018-09-13 15:23:42", "GC", 50000.00, 0.2251, -10.00, 10.00, 1, 0, "}n40ejZEZ???H?p?a%.%??70Igi]??`kHqx?1'?h??[!y??0??+??8?(|b[r;?;X_?8n?2+h?]`[TIiN5rA??:?aqL(?;98o?F3?M=G8o?h?#/L6vb(Sr??A;??S%&??B(xl;?y?w@}pD&??_?A/p(E??<2?@'?_&O??Ax???o[&l5?(?45b:WA?pP??NZ:R?9f??X?i%9moK`u=q?t?4?z?8\\]c?u?g?Oag|?%?VpD~.??tsZR?B*]X\\??=b??;%8w?Uz]?AvTLk;?4rF??FAHw/6?f?h??vLe($?~Ck0d4@X>?t?x?A?]E(D???]xV?;\\?00?y5[?S??A[??@+?zN??+h|_70?fvk?R??", "??a???L*G??Yp`??#", "Ek", 848911111, 3707196301486666, "2018-09-13 15:23:42", "GC", 50000.00, 0.4027, -10.00, 10.00, 1, 0, "ttO?>:?!?eL??.?A??QI?Gh(=$@3??^am?K??Cyt?![j%S??<0F!L?(f~>nj8)(z?IYyj0CE0t?4?k(6xL6?%5]?P(Je'H6?ol^/yvQ~H4?Z\\?yJD?=M^??$?^jG1k=E??!D8?jKw??eQk){Zg^??3p?~6?8?nJ?=4?zOR??E?VkX]D??wo??5_cHHp1???%?nuF?m79Rk??%?e?o){M=9?bVThHATC8??S?Yg*?0?f+y(&>1whK?L?B}I_?r?(hkYR!?Z?#9M-?T(#Z~iza?Z?ex5WI?]?S?7S?f:?u]?Z??[>^????EkF?~z:"); +insert into customer values(1,8,1,"-???)8tfGL9?%pe?", "OE", "BARBARBAR", "x:?k-q?u?wId??gy", "[y?%=!GS?B?E???4?T6", "8?H?'?p?G@Q", "dH", 317811111, 5312129264696994, "2018-09-13 15:23:42", "GC", 50000.00, 0.2249, -10.00, 10.00, 1, 0, "v??C????$o>~sb{q|ax???5/}?>mBpn~=9?n?HbiOmB?<~H}iR?A?A\\<6GWM?#)'2?s?=*PivoP?Cn[??=?y[S?fwG?Z@?`G?(.')[f}??Z@X??S-?)]G???/?LLt?iW?tT?$?a?y??/?5X?(W?M?6>K?gldF*?+|B?~'Ou~F??$$1?*]#My7h?&.dhIlOR?f@?kdfH?N??H/^HiWrAc88g;y$bDQ?`??PV`?{E7y?\\}P?E?Q[E_p?w@{/a!????tl%?Fj?6c?h%?9%d0?U[iYco?>ZeSM???{?3De>|R??:??t?k&X)^?oE+&?]J^O?7)GPlc)??#j??K%Y7&?i23mX?z[3?5X?u~>w.????S??s?9???G?#???bw?O?F?\\?Z)%I??1;z??U'i4????m7w-?eQk?m?y??t;?mI?E8}x=We._?dhL", "GU", 886611111, 8211838608073655, "2018-09-13 15:23:42", "GC", 50000.00, 0.0409, -10.00, 10.00, 1, 0, "2MouAk0(+&JaDUpM?h?XV\\?Q[X?$%fH-???&V?%W?M?#w[NZ???Lps{?)Z!$?A'{#??O_???%n@z&c)?w??=h??DI?P<%B5o`(vg-M?W!?????}h?|?*?^E6ErHI?Z?GaY?k?q?{\\?jP?=?r?lr|???Bd-hKeKg??I\\Z?Q+I7sn??Z]r?-D??)8Y+vzf?7_~]?6B@?`L?-/d\\a+UkNKXMX?V+_?(kO??>?>S$|t?~?<8?Ej?h?6?@?GJO"); + +insert into district values(1,1,"4W+?M?/aG","?VJ;t+P??m5v2?.=?T","%N#RO?|??;[_??~!Y?HP","?[S!JV58?#;+$cP?=d","tw", 547411111, 0.0364, 30000.00, 3001); +insert into district values(2,1,"[VIK?yC..","C?WS?Q?2?&s?J","4\\>?oCj'n?HR`i]c?u","H&-w?4??}{39","FT", 948111111, 0.1732, 30000.00, 3001); +insert into district values(3,1,"Tao??1?oJ)","LvP^_:91BO??qs??"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 7, 1, 7, 1, "2018-09-13 15:23:42", 10.00,"Cj'n?HR`i]c?uDH&-w?4"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 8, 1, 8, 1, "2018-09-13 15:23:42", 10.00,"?}{39?mL?2mC71"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 9, 1, 9, 1, "2018-09-13 15:23:42", 10.00,"Tao??1?oJ)kLvP^"); +insert into history(h_c_id,h_c_d_id,h_c_w_id,h_d_id,h_w_id,h_date,h_amount,h_data) values(1, 10,1, 10,1, "2018-09-13 15:23:42", 10.00,":91BO??qs?0) +then +signal sqlstate '03001'; +else +signal sqlstate '03002'; +end if; +end// +create procedure pp(x bigint) +begin +call p(x); +end// +delimiter ;// +--error 1644 +call pp(0); +select * from a; +call pp(1); +select * from a; +drop table a; +drop procedure p; +drop procedure pp; + +#case 56 +create table a(a1 int); +delimiter //; +create procedure p(x bigint) +begin +DECLARE Exit HANDLER FOR sqlstate '03001' +BEGIN +insert into a values(1); +END; +if(x>0) +then +signal sqlstate '03001'; +else +signal sqlstate '03002'; +end if; +end// +create procedure pp(x bigint) +begin +call p(x); +end// +delimiter ;// +--error 1644 +call pp(0); +select * from a; +call pp(1); +select * from a; +drop table a; +drop procedure p; +drop procedure pp; + +#case 57 +create table a(a1 int); +delimiter //; +create procedure p() +begin +DECLARE CONTINUE HANDLER FOR SQLEXCEPTION insert into a values(3); +select *,* from a; +end// +delimiter ;// +call p; +select * from a; +drop table a; +drop procedure p; + +#case 58 +create table a(a1 int); +delimiter //; +create procedure p() +begin +DECLARE Exit HANDLER FOR SQLEXCEPTION insert into a values(3); +select *,* from a; +end// +delimiter ;// +call p; +select * from a; +drop table a; +drop procedure p; + +#case 59 +delimiter //; +--error 1308 +CREATE PROCEDURE p() +BEGIN +label1: LOOP +begin +DECLARE Exit HANDLER FOR SQLEXCEPTION +begin +leave label1; +end; +signal sqlstate '04001'; +end; +END LOOP label1; +END// +delimiter ;// + +#case 60 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +declare exit handler for SQLSTATE '20000' +insert into a values(-1); +case x +when 1 then insert into a values(1); +end case; +end// +delimiter ;// +call p(3); +select * from a; +drop table a; +drop procedure p; + +#case 61 +create table a(a1 int); +delimiter //; +--error 1646 +create procedure p() +begin +DECLARE no_such_table CONDITION FOR 1051; +DECLARE Exit HANDLER FOR 1052 +BEGIN +insert into a values(1052); +END; +signal no_such_table; +end// +create procedure pp(x bigint) +begin +DECLARE Exit HANDLER FOR 1051 +BEGIN +insert into a values(1051); +END; +call p; +end// +delimiter ;// +--error 1305 +call pp(1); +select * from a; +drop table a; +drop procedure pp; + +#case 62 +create table a(a1 int); +delimiter //; +create procedure p() +begin +DECLARE no_such_table CONDITION FOR SQLSTATE '10510'; +DECLARE Exit HANDLER FOR SQLSTATE '10520' +BEGIN +insert into a values(1052); +END; +signal no_such_table; +end// +create procedure pp(x bigint) +begin +DECLARE Exit HANDLER FOR SQLSTATE '10510' +BEGIN +insert into a values(1051); +END; +call p; +end// +delimiter ;// +call pp(1); +select * from a; +drop table a; +drop procedure p; +drop procedure pp; + +#case 63 +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +declare exit handler for SQLSTATE '20000' +insert into a values(-1); +case x +when 1 then insert into a values(x); +end case; +delete from a; +end// +delimiter ;// +#connection obsys; + +select route_sql from oceanbase.__all_routine, oceanbase.__all_database where routine_name = 'p' and database_name = 'test'; +call p(1); +drop procedure p; +drop table a; + +#case 64 +create table a(a1 int); +create table b(b1 int); +delimiter //; +create procedure p() +begin +declare x int; +declare exit handler for not found insert into b values(-1); +select a1 from a into x ; +insert into b values(1); +end// +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; + +#case 65 +create table a(a1 int); +insert into a values(0); +create table b(b1 int); +delimiter //; +create procedure p() +begin +declare x int; +declare exit handler for not found insert into b values(-1); +select a1 from a into x; +insert into b values(1); +end// +delimiter ;// +call p; +select * from a; +select * from b; +drop table a; +drop table b; +drop procedure p; diff --git a/tools/deploy/mysql_test/test_suite/pl/t/pl_exception_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/pl_exception_mysql.test new file mode 100644 index 000000000..23a4057bf --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/pl_exception_mysql.test @@ -0,0 +1,378 @@ +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log +#owner: linlin.xll +#owner group: sql1 +#tags: pl +#description: + +--disable_query_log +--disable_result_log +--source mysql_test/include/index_quick_major.inc +--enable_query_log +--enable_result_log + +--disable_warnings +drop table if exists a,t; +drop procedure if exists p; +--enable_warnings + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE CONTINUE HANDLER FOR sqlexception insert into a values(0); +DECLARE EXIT HANDLER FOR SQLSTATE '23000' insert into a values(1); +insert into t values(1); +insert into a values(2); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE CONTINUE HANDLER FOR sqlexception insert into a values(0); +begin +DECLARE EXIT HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE CONTINUE HANDLER FOR sqlwarning insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE EXIT HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE CONTINUE HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR sqlwarning insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE CONTINUE HANDLER FOR sqlwarning insert into a values(5); +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end; +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE CONTINUE HANDLER FOR sqlexception insert into a values(5); +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE CONTINUE HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end; +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +signal SQLSTATE '01000'; +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR aaa insert into a values(0); +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end// +delimiter ;// +--error 1062 +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE EXIT HANDLER FOR sqlexception insert into a values(0); +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end; +insert into a values(5); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE continue HANDLER FOR sqlexception insert into a values(-1); +begin +DECLARE aaa CONDITION FOR SQLSTATE '42S02'; +DECLARE continue HANDLER FOR sqlexception +begin +insert into a values(0); +insert into t values(1); +insert into a values(6); +end; +begin +DECLARE exit HANDLER FOR aaa insert into a values(4); +insert into t values(1); +insert into a values(2); +end; +insert into a values(3); +end; +insert into a values(5); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE EXIT HANDLER FOR sqlexception insert into a values(0); +DECLARE EXIT HANDLER FOR SQLSTATE '23000' insert into a values(1); +insert into t values(1); +insert into a values(2); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(a int primary key); +insert into t values(1); +create table a(a1 int); +delimiter //; +create procedure p(x int) +begin +DECLARE EXIT HANDLER FOR SQLSTATE '23000' insert into a values(1); +DECLARE EXIT HANDLER FOR sqlexception insert into a values(0); +insert into t values(1); +insert into a values(2); +end// +delimiter ;// +call p(0); +select * from a; +drop table a; +drop table t; +drop procedure p; + +create table t(col int primary key); +insert into t values(1); + +delimiter //; +create procedure p() +begin + declare x condition for sqlstate '23000'; + declare exit handler for x + begin + rollback; + resignal; + end; + insert into t values(1); +end; +// +--error 1062 +call p(); +// +delimiter ;// +drop procedure p; +drop table t; diff --git a/tools/deploy/mysql_test/test_suite/pl/t/sp-bugs_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/sp-bugs_mysql.test new file mode 100644 index 000000000..f7a43ffe6 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/sp-bugs_mysql.test @@ -0,0 +1,252 @@ +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log +# Test file for stored procedure bugfixes + +#owner: linlin.xll +#owner group: sql1 +#description: test pl transformed +#tags: pl, funcs + +--result_format 4 + +--echo # +--echo # Bug #47412: Valgrind warnings / user can read uninitalized memory +--echo # using SP variables +--echo # + +--disable_warnings +DROP SCHEMA IF EXISTS testdb; +--enable_warnings + +CREATE SCHEMA testdb; +USE testdb; +DELIMITER |; + +CREATE FUNCTION f2 () RETURNS INTEGER +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1; + RETURN f_not_exists () ; +END| +CREATE PROCEDURE p3 ( arg1 VARCHAR(32) ) +BEGIN + CALL p_not_exists(); +END| +DELIMITER ;| +--echo # should not return valgrind warnings +### TODO : --error 1305 +--error 1321 +CALL p3(f2()); + +DROP SCHEMA testdb; + +CREATE SCHEMA testdb; +USE testdb; +DELIMITER |; + +CREATE FUNCTION f2() RETURNS INTEGER +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1; + RETURN f_not_exists(); +END| +CREATE PROCEDURE p3(arg2 INTEGER) +BEGIN + CALL p_not_exists(); +END| +DELIMITER ;| +--echo # should not return valgrind warnings +### TODO : --error 1305 +--error 1321 +CALL p3(f2()); + +DROP SCHEMA testdb; + +CREATE SCHEMA testdb; +USE testdb; +DELIMITER |; + +CREATE FUNCTION f2 () RETURNS INTEGER +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42000' SET @aux = 1; + RETURN f_not_exists () ; +END| +DELIMITER ;| +--echo # should not return valgrind warnings +### TODO : --error 1305 +--error 1321 +SELECT f2(); + +DROP SCHEMA testdb; + +USE test; + +--echo # +--echo # Bug#50423: Crash on second call of a procedure dropping a trigger +--echo # + +--disable_warnings +## coeanbase not support trigger yet ! +## +## DROP TABLE IF EXISTS t1; +## DROP TRIGGER IF EXISTS tr1; +## DROP PROCEDURE IF EXISTS p1; +## --enable_warnings +## +## CREATE TABLE t1 (f1 INTEGER); +## CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1; +## CREATE PROCEDURE p1 () DROP TRIGGER tr1; +## +## CALL p1 (); +## --error ER_TRG_DOES_NOT_EXIST +## CALL p1 (); +## +## DROP TABLE t1; +## DROP PROCEDURE p1; +## +## --echo # +## --echo # Bug#50423: Crash on second call of a procedure dropping a trigger +## --echo # +## +## --disable_warnings +## DROP TABLE IF EXISTS t1; +## DROP TRIGGER IF EXISTS tr1; +## DROP PROCEDURE IF EXISTS p1; +## --enable_warnings +## +## CREATE TABLE t1 (f1 INTEGER); +## CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1; +## CREATE PROCEDURE p1 () DROP TRIGGER tr1; +## +## CALL p1 (); +## --error ER_TRG_DOES_NOT_EXIST +## CALL p1 (); +## +## DROP TABLE t1; +## DROP PROCEDURE p1; + +--echo # +--echo # Bug#54375: Error in stored procedure leaves connection +--echo # in different default schema +--echo # + +--disable_warnings +SET @SQL_MODE_SAVE = @@SQL_MODE; +SET @@SQL_MODE = 'STRICT_ALL_TABLES'; +DROP DATABASE IF EXISTS db1; +CREATE DATABASE db1; +USE db1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (c1 int NOT NULL PRIMARY KEY); +INSERT INTO t1 VALUES (1); +DELIMITER $$; +CREATE FUNCTION f1 ( + some_value int +) +RETURNS smallint +DETERMINISTIC +BEGIN + INSERT INTO t1 SET c1 = some_value; + RETURN(LAST_INSERT_ID()); +END$$ +DELIMITER ;$$ +DROP DATABASE IF EXISTS db2; +CREATE DATABASE db2; +--enable_warnings +USE db2; +SELECT DATABASE(); +--error ER_DUP_ENTRY,1235 +SELECT db1.f1(1); +SELECT DATABASE(); +USE test; +DROP FUNCTION db1.f1; +DROP TABLE db1.t1; +DROP DATABASE db1; +DROP DATABASE db2; + +--echo # +--echo # Bug#13105873:valgrind warning:possible crash in foreign +--echo # key handling on subsequent create table if not exists +--echo # + +## oceanbase not support foreign key yet! +## --disable_warnings +## DROP DATABASE IF EXISTS testdb; +## --enable_warnings +## CREATE DATABASE testdb; +## USE testdb; +## CREATE TABLE t1 (id1 INT PRIMARY KEY); +## DELIMITER $; +## CREATE PROCEDURE `p1`() +## BEGIN +## CREATE TABLE IF NOT EXISTS t2(id INT PRIMARY KEY, +## CONSTRAINT FK FOREIGN KEY (id) REFERENCES t1( id1 )); +## END$ +## DELIMITER ;$ +## CALL p1(); +## --echo # below stmt should not return valgrind warnings +## CALL p1(); +## DROP DATABASE testdb; +## USE test; + +--echo End of 5.1 tests + +--echo # +--echo # BUG#13489996 valgrind:conditional jump or move depends on +--echo # uninitialised values-field_blob +--echo # + +## oceanbase not support BLOB yet! +## CREATE FUNCTION sf() RETURNS BLOB RETURN ""; +## SELECT sf(); +## DROP FUNCTION sf; + +--echo # +--echo # Bug#11763507 - 56224: FUNCTION NAME IS CASE-SENSITIVE +--echo # +SET @@SQL_MODE = ''; +DELIMITER $; +CREATE FUNCTION testf_bug11763507() RETURNS INT +BEGIN + RETURN 0; +END +$ + +CREATE PROCEDURE testp_bug11763507() +BEGIN + SELECT "PROCEDURE testp_bug11763507"; +END +$ + +DELIMITER ;$ + +# STORED FUNCTIONS +SELECT testf_bug11763507(); +SELECT TESTF_bug11763507(); + +#SHOW FUNCTION STATUS WHERE NAME='TESTF_bug11763507'; + +#SHOW CREATE FUNCTION testf_bug11763507; +#SHOW CREATE FUNCTION TESTF_bug11763507; + +# STORED PROCEDURE +CALL testp_bug11763507(); +CALL TESTP_bug11763507(); + +#SHOW PROCEDURE STATUS WHERE NAME='TESTP_bug11763507'; + +#SHOW CREATE PROCEDURE testp_bug11763507; +#SHOW CREATE PROCEDURE TESTP_bug11763507; + +# INFORMATION SCHEMA +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'testf_bug11763507'; +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name LIKE 'TESTF_bug11763507'; + +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='testf_bug11763507'; +SELECT specific_name FROM INFORMATION_SCHEMA.ROUTINES WHERE specific_name='TESTF_bug11763507'; + +DROP PROCEDURE testp_bug11763507; +DROP FUNCTION testf_bug11763507; + +SET @@SQL_MODE = @SQL_MODE_SAVE; + +--echo #END OF BUG#11763507 test. diff --git a/tools/deploy/mysql_test/test_suite/pl/t/sp-fib_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/sp-fib_mysql.test new file mode 100644 index 000000000..fa39b9540 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/sp-fib_mysql.test @@ -0,0 +1,63 @@ +# owner: linlin.xll +# owner group: SQL1 +# description: + +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log + +# Fibonacci, for recursion test. (Yet Another Numerical series :) +# Split from main.sp due to problems reported in Bug#15866 + +--result_format 4 + +--disable_warnings +drop table if exists t3; +--enable_warnings +create table t3 ( f bigint unsigned not null ); + +# We deliberately do it the awkward way, fetching the last two +# values from the table, in order to exercise various statements +# and table accesses at each turn. +--disable_warnings +drop procedure if exists fib; +--enable_warnings + +# Now for multiple statements... +delimiter |; + +create procedure fib(n int unsigned) +begin + if n > 1 then + begin + declare x, y bigint unsigned; + declare c cursor for select f from t3 order by f desc limit 2; + open c; + fetch c into y; + fetch c into x; + insert into t3 values (x+y); + call fib(n-1); + ## Close the cursor AFTER the recursion to ensure that the stack + ## frame is somewhat intact. + close c; + end; + end if; +end| + +# Enable recursion +set @@max_sp_recursion_depth= 20| + +insert into t3 values (0), (1)| + +# The small number of recursion levels is intentional. +# We need to avoid +# Bug#15866 main.sp fails (thread stack limit +# insufficient for recursive call "fib(20)") +# which affects some platforms. +call fib(4)| + +select * from t3 order by f asc| + +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| diff --git a/tools/deploy/mysql_test/test_suite/pl/t/sp-vars_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/sp-vars_mysql.test new file mode 100644 index 000000000..a68e8ee42 --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/sp-vars_mysql.test @@ -0,0 +1,1518 @@ +--disable_query_log +set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log + +#owner: linlin.xll +#owner group: sql1 +#description: test pl variables +#tags: pl + +--result_format 4 + +set ob_query_timeout=100000000; + +########################################################################### +# +# Cleanup. +# +########################################################################### + +--disable_warnings + +# Drop stored routines (if any) for general SP-vars test cases. These routines +# are created in include/sp-vars.inc file. + +DROP PROCEDURE IF EXISTS sp_vars_check_dflt; +DROP PROCEDURE IF EXISTS sp_vars_check_assignment; +DROP FUNCTION IF EXISTS sp_vars_check_ret1; +DROP FUNCTION IF EXISTS sp_vars_check_ret2; +DROP FUNCTION IF EXISTS sp_vars_check_ret3; +DROP FUNCTION IF EXISTS sp_vars_check_ret4; +DROP FUNCTION IF EXISTS sp_vars_div_zero; + +--enable_warnings + +########################################################################### +# +# Some general tests for SP-vars functionality. +# +########################################################################### + +# Create the procedure in ANSI mode. Check that all necessary warnings are +# emitted properly. + +## SET @@sql_mode = 'ansi'; +## REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI +## for ansi, oceanbase only support PIPES_AS_CONCAT and ONLY_FULL_GROUP_BY +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +--source mysql_test/include/sp-vars.inc + +--echo +--echo --------------------------------------------------------------- +--echo Calling the routines, created in ANSI mode. +--echo --------------------------------------------------------------- +--echo + +CALL sp_vars_check_dflt(); + +CALL sp_vars_check_assignment(); + +SELECT sp_vars_check_ret1(); + +SELECT sp_vars_check_ret2(); + +SELECT sp_vars_check_ret3(); + +SELECT sp_vars_check_ret4(); + +SELECT sp_vars_div_zero(); + +# Check that changing sql_mode after creating a store procedure does not +# matter. + +## SET @@sql_mode = 'traditional'; +## STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION +## for traditional oceanbase only support STRICT_TRANS_TABLES, STRICT_ALL_TABLES +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; +--echo +--echo --------------------------------------------------------------- +--echo Calling in TRADITIONAL mode the routines, created in ANSI mode. +--echo --------------------------------------------------------------- +--echo + +CALL sp_vars_check_dflt(); + +CALL sp_vars_check_assignment(); + +SELECT sp_vars_check_ret1(); + +SELECT sp_vars_check_ret2(); + +SELECT sp_vars_check_ret3(); + +SELECT sp_vars_check_ret4(); + +SELECT sp_vars_div_zero(); + +# Create the procedure in TRADITIONAL mode. Check that error will be thrown on +# execution. + +DROP PROCEDURE sp_vars_check_dflt; +DROP PROCEDURE sp_vars_check_assignment; +DROP FUNCTION sp_vars_check_ret1; +DROP FUNCTION sp_vars_check_ret2; +DROP FUNCTION sp_vars_check_ret3; +DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; + +--source mysql_test/include/sp-vars.inc + +--echo +--echo --------------------------------------------------------------- +--echo Calling the routines, created in TRADITIONAL mode. +--echo --------------------------------------------------------------- +--echo + +--error ER_WARN_DATA_OUT_OF_RANGE +CALL sp_vars_check_dflt(); + +--error ER_WARN_DATA_OUT_OF_RANGE +CALL sp_vars_check_assignment(); + +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT sp_vars_check_ret1(); + +--error ER_WARN_DATA_OUT_OF_RANGE +SELECT sp_vars_check_ret2(); + +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +SELECT sp_vars_check_ret3(); + +# TODO: Is it an error, that only a warning is emitted here? Check the same +# behaviour with tables. + +SELECT sp_vars_check_ret4(); + +## --error ER_DIVISION_BY_ZERO +SELECT sp_vars_div_zero(); + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +# +# Cleanup. +# + +DROP PROCEDURE sp_vars_check_dflt; +DROP PROCEDURE sp_vars_check_assignment; +DROP FUNCTION sp_vars_check_ret1; +DROP FUNCTION sp_vars_check_ret2; +DROP FUNCTION sp_vars_check_ret3; +DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; + +########################################################################### +# +# Tests for BIT data type. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BIT data type tests +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + DECLARE v1 BIT; + DECLARE v2 BIT(1); + DECLARE v3 BIT(3) DEFAULT b'101'; + DECLARE v4 BIT(64) DEFAULT 0x5555555555555555; + DECLARE v5 BIT(3); + DECLARE v6 BIT(64); + DECLARE v7 BIT(8) DEFAULT 128; + DECLARE v8 BIT(8) DEFAULT '128'; + DECLARE v9 BIT(8) DEFAULT ' 128'; + DECLARE v10 BIT(8) DEFAULT 'x 128'; + + SET v1 = v4; + SET v2 = 0; + SET v5 = v4; # check overflow + SET v6 = v3; # check padding + + SELECT HEX(v1); + SELECT HEX(v2); + SELECT HEX(v3); + SELECT HEX(v4); + SELECT HEX(v5); + SELECT HEX(v6); + SELECT HEX(v7); + SELECT HEX(v8); + SELECT HEX(v9); + SELECT HEX(v10); +END| +delimiter ;| + +CALL p1(); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Tests for CASE statements functionality: +# - test for general functionality (scopes, nested cases, CASE in loops); +# - test that if type of the CASE expression is changed on each iteration, +# the execution will be correct. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo CASE expression tests. +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# +## use create time to make the order of log_msg stable +CREATE TABLE t1(ctime int auto_increment, log_msg VARCHAR(1024)); + +delimiter |; + +CREATE PROCEDURE p1(arg VARCHAR(255)) +BEGIN + INSERT INTO t1(log_msg) VALUES('p1: step1'); + CASE arg * 10 + WHEN 10 * 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: on 10'); + WHEN 10 * 10 + 10 * 10 THEN + BEGIN + CASE arg / 10 + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: on 1'); + WHEN 2 THEN + BEGIN + DECLARE i TINYINT DEFAULT 10; + + WHILE i > 0 DO + INSERT INTO t1(log_msg) VALUES(CONCAT('p1: case1: case2: loop: i: ', i)); + + CASE MOD(i, 2) + WHEN 0 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: loop: i is even'); + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: loop: i is odd'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: loop: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: case2: ERROR'); + END CASE; + + CASE arg + WHEN 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case3: on 10'); + WHEN 20 THEN + INSERT INTO t1(log_msg) VALUES('p1: case1: case3: on 20'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: case3: ERROR'); + END CASE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case1: ERROR'); + END CASE; + + CASE arg * 10 + WHEN 10 * 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: on 10'); + WHEN 10 * 10 + 10 * 10 THEN + BEGIN + CASE arg / 10 + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: on 1'); + WHEN 2 THEN + BEGIN + DECLARE i TINYINT DEFAULT 10; + + WHILE i > 0 DO + INSERT INTO t1(log_msg) VALUES(CONCAT('p1: case4: case5: loop: i: ', i)); + + CASE MOD(i, 2) + WHEN 0 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: loop: i is even'); + WHEN 1 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: loop: i is odd'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: loop: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: case5: ERROR'); + END CASE; + + CASE arg + WHEN 10 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case6: on 10'); + WHEN 20 THEN + INSERT INTO t1(log_msg) VALUES('p1: case4: case6: on 20'); + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: case6: ERROR'); + END CASE; + END; + ELSE + INSERT INTO t1(log_msg) VALUES('p1: case4: ERROR'); + END CASE; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE i TINYINT DEFAULT 3; + + WHILE i > 0 DO + IF MOD(i, 2) = 0 THEN + SET @_test_session_var = 10; + ELSE + SET @_test_session_var = 'test'; + END IF; + + CASE @_test_session_var + WHEN 10 THEN + INSERT INTO t1(log_msg) VALUES('p2: case: numerical type'); + WHEN 'test' THEN + INSERT INTO t1(log_msg) VALUES('p2: case: string type'); + ELSE + INSERT INTO t1(log_msg) VALUES('p2: case: ERROR'); + END CASE; + + SET i = i - 1; + END WHILE; +END| + +delimiter ;| + +CALL p1(10); +CALL p1(20); + +CALL p2(); + +SELECT ctime, log_msg FROM t1 order by ctime, log_msg; + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#14161: Stored procedure cannot retrieve bigint unsigned. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#14161 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(col BIGINT UNSIGNED); + +INSERT INTO t1 VALUE(18446744073709551614); + +delimiter |; +CREATE PROCEDURE p1(IN arg BIGINT UNSIGNED) +BEGIN + SELECT arg; + SELECT * FROM t1; + SELECT * FROM t1 WHERE col = arg; +END| +delimiter ;| + +CALL p1(18446744073709551614); + +# +# Cleanup. +# + +DROP TABLE t1; +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#13705: parameters to stored procedures are not verified. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13705 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1(x VARCHAR(10), y CHAR(3)) READS SQL DATA +BEGIN + SELECT x, y; +END| +delimiter ;| + +CALL p1('alpha', 'abc'); +CALL p1('alpha', 'abcdef'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#13675: DATETIME/DATE type in store proc param seems to be +# converted as varbinary. +# +# TODO: test case failed. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13675 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +## --disable_warnings +## DROP PROCEDURE IF EXISTS p1; +## DROP TABLE IF EXISTS t1; +## --enable_warnings + +# +# Test case. +# +## TODO: DDL not support select x with variables +## delimiter |; +## CREATE PROCEDURE p1(x DATETIME) +## BEGIN +## CREATE TABLE t1 AS SELECT x; +## SHOW CREATE TABLE t1; +## DROP TABLE t1; +## END| +## delimiter ;| +## +## CALL p1(NOW()); +## CALL p1('test'); + +# +# Cleanup. +# + +## DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#12976: Boolean values reversed in stored procedures? +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#12976 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(b BIT(1)); + +INSERT INTO t1(b) VALUES(b'0'), (b'1'); + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + SELECT HEX(b), + b = 0, + b = FALSE, + b IS FALSE, + b = 1, + b = TRUE, + b IS TRUE + FROM t1; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE vb BIT(1); + SELECT b FROM t1 WHERE b = 0 INTO vb; + + SELECT HEX(vb), + vb = 0, + vb = FALSE, + vb IS FALSE, + vb = 1, + vb = TRUE, + vb IS TRUE; + + SELECT b FROM t1 WHERE b = 1 INTO vb; + + SELECT HEX(vb), + vb = 0, + vb = FALSE, + vb IS FALSE, + vb = 1, + vb = TRUE, + vb IS TRUE; +END| +delimiter ;| + +call p1(); +call p2(); + +# +# Cleanup. +# + +DROP TABLE t1; +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +# Additional tests for Bug#12976 + +--disable_warnings +DROP TABLE IF EXISTS table_12976_a; +DROP TABLE IF EXISTS table_12976_b; +DROP PROCEDURE IF EXISTS proc_12976_a; +DROP PROCEDURE IF EXISTS proc_12976_b; +--enable_warnings + +CREATE TABLE table_12976_a (val bit(1)); + +CREATE TABLE table_12976_b( + appname varchar(15), + emailperm bit not null default 1, + phoneperm bit not null default 0); + +insert into table_12976_b values ('A', b'1', b'1'), ('B', b'0', b'0'); + +delimiter ||; +CREATE PROCEDURE proc_12976_a() +BEGIN + declare localvar bit(1); + SELECT val FROM table_12976_a INTO localvar; + SELECT coalesce(localvar, 1)+1, coalesce(val, 1)+1 FROM table_12976_a; +END|| + +CREATE PROCEDURE proc_12976_b( + name varchar(15), + out ep bit, + out msg varchar(10)) +BEGIN + SELECT emailperm FROM table_12976_b where (appname = name) INTO ep; + IF ep is true THEN + SET msg = 'True'; + ELSE + SET msg = 'False'; + END IF; +END|| + +delimiter ;|| + +INSERT table_12976_a VALUES (0); +--disable_warnings +call proc_12976_a(); +--enable_warnings +UPDATE table_12976_a set val=1; +--disable_warnings +call proc_12976_a(); +--enable_warnings + +call proc_12976_b('A', @ep, @msg); +select HEX(@ep), @msg; + +call proc_12976_b('B', @ep, @msg); +select HEX(@ep), @msg; + +DROP TABLE table_12976_a; +DROP TABLE table_12976_b; +DROP PROCEDURE proc_12976_a; +DROP PROCEDURE proc_12976_b; + + +########################################################################### +# +# Test case for BUG#9572: Stored procedures: variable type declarations +# ignored. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#9572 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; + +DROP PROCEDURE IF EXISTS p4; +DROP PROCEDURE IF EXISTS p5; +DROP PROCEDURE IF EXISTS p6; +--enable_warnings + +# +# Test case. +# + +## SET @@sql_mode = 'traditional'; +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + +delimiter |; + +CREATE PROCEDURE p1() +BEGIN + DECLARE v TINYINT DEFAULT 1e200; + SELECT v; +END| + +CREATE PROCEDURE p2() +BEGIN + DECLARE v DECIMAL(5) DEFAULT 1e200; + SELECT v; +END| + +CREATE PROCEDURE p3() +BEGIN + DECLARE v CHAR(5) DEFAULT 'abcdef'; + SELECT v LIKE 'abc___'; +END| + +CREATE PROCEDURE p4(arg VARCHAR(2)) +BEGIN + DECLARE var VARCHAR(1); + SET var := arg; + SELECT arg, var; +END| + +CREATE PROCEDURE p5(arg CHAR(2)) +BEGIN + DECLARE var CHAR(1); + SET var := arg; + SELECT arg, var; +END| + +CREATE PROCEDURE p6(arg DECIMAL(2)) +BEGIN + DECLARE var DECIMAL(1); + SET var := arg; + SELECT arg, var; +END| + +delimiter ;| + +--error ER_WARN_DATA_OUT_OF_RANGE +CALL p1(); +--error ER_WARN_DATA_OUT_OF_RANGE +CALL p2(); +--error ER_DATA_TOO_LONG +CALL p3(); + +--error ER_DATA_TOO_LONG +CALL p4('aaa'); +--error ER_DATA_TOO_LONG +CALL p5('aa'); +--error ER_WARN_DATA_OUT_OF_RANGE +CALL p6(10); + +# +# Cleanup. +# + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP PROCEDURE p3; + +DROP PROCEDURE p4; +DROP PROCEDURE p5; +DROP PROCEDURE p6; + +########################################################################### +# +# Test case for BUG#9078: STORED PROCDURE: Decimal digits are not displayed +# when we use DECIMAL datatype. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#9078 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1 (arg DECIMAL(64,2)) +BEGIN + DECLARE var DECIMAL(64,2); + + SET var = arg; + SELECT var; +END| +delimiter ;| + +CALL p1(1929); +CALL p1(1929.00); +CALL p1(1929.003); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#8768: Functions: For any unsigned data type, -ve values can +# be passed and returned. +# +# TODO: there is a bug here -- the function created in ANSI mode should not +# throw errors instead of warnings if called in TRADITIONAL mode. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#8768 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +# Create a function in ANSI mode. + +delimiter |; +CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT +BEGIN + RETURN arg; +END| +delimiter ;| + +SELECT f1(-2500); + +# Call in TRADITIONAL mode the function created in ANSI mode. + +## SET @@sql_mode = 'traditional'; +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + +# TODO: a warning should be emitted here. +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(-2500); + +# Recreate the function in TRADITIONAL mode. + +DROP FUNCTION f1; + +delimiter |; +CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT +BEGIN + RETURN arg; +END| +delimiter ;| + +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(-2500); + +# +# Cleanup. +# + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#8769: Functions: For Int datatypes, out of range values can +# be passed and returned. +# +# TODO: there is a bug here -- the function created in ANSI mode should not +# throw errors instead of warnings if called in TRADITIONAL mode. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#8769 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +# Create a function in ANSI mode. + +delimiter |; +CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT +BEGIN + RETURN arg; +END| +delimiter ;| + +SELECT f1(8388699); + +# Call in TRADITIONAL mode the function created in ANSI mode. + +## SET @@sql_mode = 'traditional'; +SET @@sql_mode = 'STRICT_TRANS_TABLES,STRICT_ALL_TABLES'; + +# TODO: a warning should be emitted here. +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(8388699); + +# Recreate the function in TRADITIONAL mode. + +DROP FUNCTION f1; + +delimiter |; +CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT +BEGIN + RETURN arg; +END| +delimiter ;| + +## --error ER_WARN_DATA_OUT_OF_RANGE +SELECT f1(8388699); + +# +# Cleanup. +# + +## SET @@sql_mode = 'ansi'; +set @@sql_mode = "PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"; + +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#8702: Stored Procedures: No Error/Warning shown for +# inappropriate data type matching. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#8702 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(col VARCHAR(255)); + +INSERT INTO t1(col) VALUES('Hello, world!'); + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + DECLARE sp_var INTEGER; + + SELECT col FROM t1 LIMIT 1 INTO sp_var; + SET @user_var = sp_var; + + SELECT sp_var; + SELECT @user_var; +END| +delimiter ;| + +CALL p1(); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#12903: upper function does not work inside a function. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#12903 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(txt VARCHAR(255)); + +delimiter |; +CREATE FUNCTION f1(arg VARCHAR(255)) RETURNS VARCHAR(255) +BEGIN + DECLARE v1 VARCHAR(255); + DECLARE v2 VARCHAR(255); + + SET v1 = CONCAT(LOWER(arg), UPPER(arg)); + SET v2 = CONCAT(LOWER(v1), UPPER(v1)); + + INSERT INTO t1 VALUES(v1), (v2); + + RETURN CONCAT(LOWER(arg), UPPER(arg)); +END| +delimiter ;| + +SELECT f1('_aBcDe_'); + +SELECT * FROM t1; + +# +# Cleanup. +# + +DROP FUNCTION f1; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#13808: ENUM type stored procedure parameter accepts +# non-enumerated data. +# +########################################################################### + +## --echo +## --echo --------------------------------------------------------------- +## --echo BUG#13808 +## --echo --------------------------------------------------------------- +## --echo + +# +# Prepare. +# + +## --disable_warnings +## DROP PROCEDURE IF EXISTS p1; +## DROP PROCEDURE IF EXISTS p2; +## DROP FUNCTION IF EXISTS f1; +## --enable_warnings + +# +# Test case. +# +## delimiter |; +## +## CREATE PROCEDURE p1(arg ENUM('a', 'b')) +## BEGIN +## SELECT arg; +## END| +## +## CREATE PROCEDURE p2(arg ENUM('a', 'b')) +## BEGIN +## DECLARE var ENUM('c', 'd') DEFAULT arg; +## +## SELECT arg, var; +## END| +## +## CREATE FUNCTION f1(arg ENUM('a', 'b')) RETURNS ENUM('c', 'd') +## BEGIN +## RETURN arg; +## END| +## +## delimiter ;| +## +## CALL p1('c'); +## +## CALL p2('a'); +## +## SELECT f1('a'); + +# +# Cleanup. +# + +## DROP PROCEDURE p1; +## DROP PROCEDURE p2; +## DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#13909: Varchar Stored Procedure Parameter always BINARY +# string (ignores CHARACTER SET). +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13909 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +# +# Test case. +# + +delimiter |; + +CREATE PROCEDURE p1(arg VARCHAR(255)) +BEGIN + SELECT CHARSET(arg); +END| + +CREATE PROCEDURE p2(arg VARCHAR(255) CHARACTER SET UTF8) +BEGIN + SELECT CHARSET(arg); +END| + +delimiter ;| + +CALL p1('t'); +CALL p1(_UTF8 't'); + + +CALL p2('t'); +## CALL p2(_LATIN1 't'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +########################################################################### +# +# Test case for BUG#14188: BINARY variables have no 0x00 padding. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#14188 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE PROCEDURE p1(arg1 BINARY(2), arg2 VARBINARY(2)) +BEGIN + DECLARE var1 BINARY(2) DEFAULT 0x41; + DECLARE var2 VARBINARY(2) DEFAULT 0x42; + + SELECT HEX(arg1), HEX(arg2); + SELECT HEX(var1), HEX(var2); +END| +delimiter ;| + +CALL p1(0x41, 0x42); + +# +# Cleanup. +# + +DROP PROCEDURE p1; + +########################################################################### +# +# Test case for BUG#15148: Stored procedure variables accept non-scalar values. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#15148 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Test case. +# + +CREATE TABLE t1(col1 TINYINT, col2 TINYINT); + +INSERT INTO t1 VALUES(1, 2), (11, 12); + +delimiter |; +CREATE PROCEDURE p1(arg TINYINT) +BEGIN + SELECT arg; +END| +delimiter ;| + +--error ER_OPERAND_COLUMNS +CALL p1((1, 2)); + +## --error ER_OPERAND_COLUMNS +## oceanbase not support yet +## CALL p1((SELECT * FROM t1 LIMIT 1)); + +## --error ER_OPERAND_COLUMNS +## oceanbase not support yet +## CALL p1((SELECT col1, col2 FROM t1 LIMIT 1)); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP TABLE t1; + +########################################################################### +# +# Test case for BUG#13613: substring function in stored procedure. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13613 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +delimiter |; + +CREATE PROCEDURE p1(x VARCHAR(50)) +BEGIN + SET x = SUBSTRING(x, 1, 3); + SELECT x; +END| + +CREATE FUNCTION f1(x VARCHAR(50)) RETURNS VARCHAR(50) +BEGIN + RETURN SUBSTRING(x, 1, 3); +END| + +delimiter ;| + +CALL p1('abcdef'); + +SELECT f1('ABCDEF'); + +# +# Cleanup. +# + +DROP PROCEDURE p1; +DROP FUNCTION f1; + +########################################################################### +# +# Test case for BUG#13665: concat with '' produce incorrect results in SP. +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#13665 +--echo --------------------------------------------------------------- +--echo + +# +# Prepare. +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +# +# Test case. +# + +delimiter |; +CREATE FUNCTION f1() RETURNS VARCHAR(20000) +BEGIN + DECLARE var VARCHAR(2000); + + SET var = ''; + SET var = CONCAT(var, 'abc'); + SET var = CONCAT(var, ''); + + RETURN var; +END| +delimiter ;| + +SELECT f1(); + +# +# Cleanup. +# + +DROP FUNCTION f1; + + +# +# Bug#17226: Variable set in cursor on first iteration is assigned +# second iterations value +# +# The problem was in incorrect handling of local variables of type +# TEXT (BLOB). +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +delimiter |; +CREATE PROCEDURE p1() +BEGIN + DECLARE v_char VARCHAR(255); + DECLARE v_text VARCHAR(255) DEFAULT ''; + + SET v_char = 'abc'; + + SET v_text = v_char; + + SET v_char = 'def'; + + SET v_text = concat(v_text, '|', v_char); + + SELECT v_text; +END| +delimiter ;| + +CALL p1(); + +DROP PROCEDURE p1; + +# +# Bug #27415 Text Variables in stored procedures +# If the SP varible was also referenced on the right side +# the result was corrupted. +# +DELIMITER |; + +--disable_warnings +DROP PROCEDURE IF EXISTS bug27415_text_test| +DROP PROCEDURE IF EXISTS bug27415_text_test2| +--enable_warnings + +CREATE PROCEDURE bug27415_text_test(entity_id_str_in VARCHAR(255)) +BEGIN + DECLARE str_remainder VARCHAR(255); + + SET str_remainder = entity_id_str_in; + + select 'before substr', str_remainder; + SET str_remainder = SUBSTRING(str_remainder, 3); + select 'after substr', str_remainder; +END| + +CREATE PROCEDURE bug27415_text_test2(entity_id_str_in VARCHAR(255)) +BEGIN + DECLARE str_remainder VARCHAR(255); + DECLARE str_remainder2 VARCHAR(255); + + SET str_remainder2 = entity_id_str_in; + select 'before substr', str_remainder2; + SET str_remainder = SUBSTRING(str_remainder2, 3); + select 'after substr', str_remainder; +END| + +CALL bug27415_text_test('a,b,c')| +CALL bug27415_text_test('a,b,c')| +CALL bug27415_text_test2('a,b,c')| +CALL bug27415_text_test('a,b,c')| + +DROP PROCEDURE bug27415_text_test| +DROP PROCEDURE bug27415_text_test2| + +DELIMITER ;| + +# End of 5.0 tests. + +# +# Bug #26277 User variable returns one type in SELECT @v and other for CREATE as SELECT @v +# +--disable_warnings +drop function if exists f1; +drop table if exists t1; +--enable_warnings + +delimiter |; +create function f1() returns int +begin + if @a=1 then set @b='abc'; + else set @b=1; + end if; + set @a=1; + return 0; +end| + +create table t1 (a int)| +insert into t1 (a) values (1), (2)| + +set @b:='test'| +set @a=0| +select f1(), @b from t1| + +set @b=1| +set @a=0| +select f1(), @b from t1| + +delimiter ;| + +drop function f1; +drop table t1; +# End of 5.1 tests. + + +########################################################################### +# +# Test case for BUG#28299: To-number conversion warnings work +# differenly with CHAR and VARCHAR sp variables +# +########################################################################### + +--echo +--echo --------------------------------------------------------------- +--echo BUG#28299 +--echo --------------------------------------------------------------- +--echo + +DELIMITER |; +CREATE PROCEDURE ctest() +BEGIN + DECLARE i CHAR(16); + DECLARE j INT; + SET i= 'string'; + SET j= 1 + i; +END| +DELIMITER ;| + +CALL ctest(); +DROP PROCEDURE ctest; + +DELIMITER |; +CREATE PROCEDURE vctest() +BEGIN + DECLARE i VARCHAR(16); + DECLARE j INT; + SET i= 'string'; + SET j= 1 + i; +END| +DELIMITER ;| + +CALL vctest(); +DROP PROCEDURE vctest; diff --git a/tools/deploy/mysql_test/test_suite/pl/t/sp_mysql.test b/tools/deploy/mysql_test/test_suite/pl/t/sp_mysql.test new file mode 100644 index 000000000..4987b527b --- /dev/null +++ b/tools/deploy/mysql_test/test_suite/pl/t/sp_mysql.test @@ -0,0 +1,9231 @@ +--disable_query_log +#set @@session.explicit_defaults_for_timestamp=off; +--enable_query_log + +#owner: linlin.xll +#owner group: SQL1 +#description: transfrom from mysql +#tags: pl, optimizer + +# +# Basic stored PROCEDURE tests +# +# Test cases for bugs are added at the end. See template there. +# +# Some tests that require --error go into sp-error.test +# Tests that require inndb go into sp_trans.test +# Tests that check privilege and security issues go to sp-security.test. +# Tests that require multiple connections, except security/privilege tests, +# go to sp-thread. +# Tests that uses 'goto' to into sp-goto.test (currently disabled) +# Tests that destroys system tables (e.g. mysql.proc) for error testing +# go to sp-destruct. +# Tests that require --with-geometry go into sp_gis.test +# Tests that require multibyte character sets, which are not always available, +# go into separate files (e.g. sp-ucs2.test) + +use test; +set sql_mode=default; +# Test tables +# +# t1 and t2 are reused throughout the file, and dropped at the end. +# t3 and up are created and dropped when needed. +# +--disable_warnings +drop table if exists t1,t2,t3,t4; +drop view if exists t1,t2,t3,t4; +drop view if exists v1; +drop procedure if exists p1; +drop procedure if exists p2; +drop function if exists f1; +drop function if exists f2; +--enable_warnings +create table t1 ( + id char(16) not null default '', + data int not null +); +create table t2 ( + s char(16), + i int, + d double +); + + +# Single statement, no params. +--disable_warnings ONCE +drop procedure if exists foo42; +create procedure foo42() + insert into test.t1 values ("foo", 42); + +call foo42(); +select * from t1; +delete from t1; +drop procedure foo42; + + +# Single statement, two IN params. +--disable_warnings ONCE +drop procedure if exists bar; +create procedure bar(x char(16), y int) + insert into test.t1 values (x, y); + +call bar("bar", 666); +select * from t1; +delete from t1; +# Don't drop procedure yet... + + +# Now for multiple statements... +delimiter |; + +# Empty statement +--disable_warnings ONCE +drop procedure if exists empty| +create procedure empty() +begin +end| + +call empty()| +drop procedure empty| + +# Scope test. This is legal (warnings might be possible in the future, +# but for the time being, we just accept it). +--disable_warnings ONCE +drop procedure if exists scope| +create procedure scope(a int, b float) +begin + declare b int; + declare c float; + + begin + declare c int; + end; +end| + +drop procedure scope| + +# Two statements. +--disable_warnings ONCE +drop procedure if exists two| +create procedure two(x1 char(16), x2 char(16), y int) +begin + insert into test.t1 values (x1, y); + insert into test.t1 values (x2, y); +end| + +call two("one", "two", 3)| +select * from t1| +delete from t1| +drop procedure two| + + +# Simple test of local variables and SET. +--disable_warnings ONCE +drop procedure if exists locset| +create procedure locset(x char(16), y int) +begin + declare z1, z2 int; + set z1 = y; + set z2 = z1+2; + insert into test.t1 values (x, z2); +end| + +call locset("locset", 19)| +select * from t1| +delete from t1| +drop procedure locset| + + +# In some contexts local variables are not recognized +# (and in some, you have to qualify the identifier). +--disable_warnings ONCE +drop procedure if exists setcontext| +create procedure setcontext() +begin + declare data1 int default 2; + + insert into t1 (id, data) values ("foo", 1); + replace t1 set data = data1, id = "bar"; + update t1 set id = "kaka", data = 3 where t1.data = data1; +end| + +call setcontext()| +select * from t1 order by data| +delete from t1| +drop procedure setcontext| + + +# Set things to null +create table t3 ( d date, i int, f double, s varchar(32) )| + +--disable_warnings ONCE +drop procedure if exists nullset| +create procedure nullset() +begin + declare ld date; + declare li int; + declare lf double; + declare ls varchar(32); + + set ld = null, li = null, lf = null, ls = null; + insert into t3 values (ld, li, lf, ls); + + insert into t3 (i, f, s) values ((ld is null), 1, "ld is null"), + ((li is null), 1, "li is null"), + ((li = 0), null, "li = 0"), + ((lf is null), 1, "lf is null"), + ((lf = 0), null, "lf = 0"), + ((ls is null), 1, "ls is null"); +end| + +call nullset()| +select * from t3| +drop table t3| +drop procedure nullset| + + +# The peculiar (non-standard) mixture of variables types in SET. +--disable_warnings ONCE +drop procedure if exists mixset| +create procedure mixset(x char(16), y int) +begin + declare z int; + + set @z = y, z = 666, @max_sp_recursion_depth = 100; + insert into test.t1 values (x, z); +end| + +call mixset("mixset", 19)| +show variables like 'max_sp_recursion_depth'| +select id,data,@z from t1| +delete from t1| +set max_sp_recursion_depth = default; +drop procedure mixset| + + +# Multiple CALL statements, one with OUT parameter. +--disable_warnings ONCE +drop procedure if exists zip| +create procedure zip(x char(16), y int) +begin + declare z int; + call zap(y, z); + call bar(x, z); +end| + +# SET local variables and OUT parameter. +--disable_warnings ONCE +drop procedure if exists zap| +create procedure zap(x int, out y int) +begin + declare z int; + set z = x+1, y = z; +end| + +call zip("zip", 99)| +select * from t1| +delete from t1| +drop procedure zip| +drop procedure bar| + +# Top-level OUT parameter +call zap(7, @zap)| +select @zap| + +drop procedure zap| + + +# "Deep" calls... +--disable_warnings ONCE +drop procedure if exists c1| +create procedure c1(x int) + call c2("c", x)| +--disable_warnings ONCE +drop procedure if exists c2| +create procedure c2(s char(16), x int) + call c3(x, s)| +--disable_warnings ONCE +drop procedure if exists c3| +create procedure c3(x int, s char(16)) + call c4("level", x, s)| +--disable_warnings ONCE +drop procedure if exists c4| +create procedure c4(l char(8), x int, s char(16)) + insert into t1 values (concat(l,s), x)| + +call c1(42)| +select * from t1| +delete from t1| +drop procedure c1| +drop procedure c2| +drop procedure c3| +drop procedure c4| + +# INOUT test +--disable_warnings ONCE +drop procedure if exists iotest| +create procedure iotest(x1 char(16), x2 char(16), y int) +begin + call inc2(x2, y); + insert into test.t1 values (x1, y); +end| + +--disable_warnings ONCE +drop procedure if exists inc2| +create procedure inc2(x char(16), y int) +begin + call inc(y); + insert into test.t1 values (x, y); +end| + +--disable_warnings ONCE +drop procedure if exists inc| +create procedure inc(inout io int) + set io = io + 1| + +call iotest("io1", "io2", 1)| +select * from t1 order by data desc| +delete from t1| +drop procedure iotest| +drop procedure inc2| + +# Propagating top-level @-vars +--disable_warnings ONCE +drop procedure if exists incr| +create procedure incr(inout x int) + call inc(x)| + +# Before +select @zap| +call incr(@zap)| +# After +select @zap| + +drop procedure inc| +drop procedure incr| + +# Call-by-value test +# The expected result is: +# ("cbv2", 4) +# ("cbv1", 4711) +--disable_warnings ONCE +drop procedure if exists cbv1| +create procedure cbv1() +begin + declare y int default 3; + + call cbv2(y+1, y); + insert into test.t1 values ("cbv1", y); +end| + +--disable_warnings ONCE +drop procedure if exists cbv2| +create procedure cbv2(y1 int, inout y2 int) +begin + set y2 = 4711; + insert into test.t1 values ("cbv2", y1); +end| + +call cbv1()| +select * from t1 order by data| +delete from t1| +drop procedure cbv1| +drop procedure cbv2| + + +# Subselect arguments + +insert into t2 values ("a", 1, 1.1), ("b", 2, 1.2), ("c", 3, 1.3)| + +--disable_warnings ONCE +drop procedure if exists sub1| +create procedure sub1(id char(16), x int) + insert into test.t1 values (id, x)| + +--disable_warnings ONCE +drop procedure if exists sub2| +create procedure sub2(id char(16)) +begin + declare x int; + set x = (select sum(t.i) from test.t2 t); + insert into test.t1 values (id, x); +end| + +--disable_warnings ONCE +drop function if exists sub3| +create function sub3(i int) returns int deterministic + return i+1| + +call sub1("sub1a", (select 7))| +call sub1("sub1b", (select max(i) from t2))| +--error 1241 +call sub1("sub1c", (select i,d from t2 limit 1))| +call sub1("sub1d", (select 1 from (select 1) a))| +call sub2("sub2")| +select * from t1 order by id| +select sub3((select max(i) from t2))| +drop procedure sub1| +drop procedure sub2| +drop function sub3| +delete from t1| +delete from t2| + +# Basic tests of the flow control constructs + +# Just test on 'x'... +--disable_warnings ONCE +drop procedure if exists a0| +create procedure a0(x int) +while x do + set x = x-1; + insert into test.t1 values ("a0", x); +end while| + +call a0(3)| +select * from t1 order by data desc| +delete from t1| +drop procedure a0| + + +# The same, but with a more traditional test. +--disable_warnings ONCE +drop procedure if exists a| +create procedure a(x int) +while x > 0 do + set x = x-1; + insert into test.t1 values ("a", x); +end while| + +call a(3)| +select * from t1 order by data desc| +delete from t1| +drop procedure a| + + +# REPEAT +--disable_warnings ONCE +drop procedure if exists b| +create procedure b(x int) +repeat + insert into test.t1 values (repeat("b",3), x); + set x = x-1; +until x = 0 end repeat| + +call b(3)| +select * from t1 order by data desc| +delete from t1| +drop procedure b| + + +# Check that repeat isn't parsed the wrong way +--disable_warnings ONCE +drop procedure if exists b2| +create procedure b2(x int) +repeat select 1 into outfile 'b2'; + insert into test.t1 values (repeat("b2",3), x); + set x = x-1; +until x = 0 end repeat| + +# We don't actually want to call it. +drop procedure b2| + + +# Labelled WHILE with ITERATE (pointless really) +--disable_warnings ONCE +drop procedure if exists c| +create procedure c(x int) +hmm: while x > 0 do + insert into test.t1 values ("c", x); + set x = x-1; + iterate hmm; + insert into test.t1 values ("x", x); +end while hmm| + +call c(3)| +select * from t1 order by data desc| +delete from t1| +drop procedure c| + + +# Labelled WHILE with LEAVE +--disable_warnings ONCE +drop procedure if exists d| +create procedure d(x int) +hmm: while x > 0 do + insert into test.t1 values ("d", x); + set x = x-1; + leave hmm; + insert into test.t1 values ("x", x); +end while| + +call d(3)| +select * from t1| +delete from t1| +drop procedure d| + + +# LOOP, with simple IF statement +--disable_warnings ONCE +drop procedure if exists e| +create procedure e(x int) +foo: loop + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("e", x); + set x = x-1; +end loop foo| + +call e(3)| +select * from t1 order by data desc| +delete from t1| +drop procedure e| + + +# A full IF statement +--disable_warnings ONCE +drop procedure if exists f| +create procedure f(x int) +if x < 0 then + insert into test.t1 values ("f", 0); +elseif x = 0 then + insert into test.t1 values ("f", 1); +else + insert into test.t1 values ("f", 2); +end if| + +call f(-2)| +call f(0)| +call f(4)| +select * from t1 order by data| +delete from t1| +drop procedure f| + + +# This form of CASE is really just syntactic sugar for IF-ELSEIF-... +--disable_warnings ONCE +drop procedure if exists g| +create procedure g(x int) +case +when x < 0 then + insert into test.t1 values ("g", 0); +when x = 0 then + insert into test.t1 values ("g", 1); +else + insert into test.t1 values ("g", 2); +end case| + +call g(-42)| +call g(0)| +call g(1)| +select * from t1 order by data| +delete from t1| +drop procedure g| + + +# The "simple CASE" +--disable_warnings ONCE +drop procedure if exists h| +create procedure h(x int) +case x +when 0 then + insert into test.t1 values ("h0", x); +when 1 then + insert into test.t1 values ("h1", x); +else + insert into test.t1 values ("h?", x); +end case| + +call h(0)| +call h(1)| +call h(17)| +select * from t1 order by data| +delete from t1| +drop procedure h| + + +# It's actually possible to LEAVE a BEGIN-END block +--disable_warnings ONCE +drop procedure if exists i| +create procedure i(x int) +foo: +begin + if x = 0 then + leave foo; + end if; + insert into test.t1 values ("i", x); +end foo| + +call i(0)| +call i(3)| +select * from t1| +delete from t1| +drop procedure i| + + +# SELECT with one of more result set sent back to the clinet +insert into t1 values ("foo", 3), ("bar", 19)| +insert into t2 values ("x", 9, 4.1), ("y", -1, 19.2), ("z", 3, 2.2)| + +--disable_warnings ONCE +drop procedure if exists sel1| +create procedure sel1() +begin + select * from t1 order by data; +end| + +call sel1()| +drop procedure sel1| + +--disable_warnings ONCE +drop procedure if exists sel2| +create procedure sel2() +begin + select * from t1 order by data; + select * from t2 order by s; +end| + +call sel2()| +drop procedure sel2| +delete from t1| +delete from t2| + +# SELECT INTO local variables +--disable_warnings ONCE +drop procedure if exists into_test| +create procedure into_test(x char(16), y int) +begin + insert into test.t1 values (x, y); + select id,data from test.t1 limit 1 into x,y; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +call into_test("into", 100)| +select * from t1 order by data| +delete from t1| +drop procedure into_test| + + +# SELECT INTO with a mix of local and global variables +--disable_warnings ONCE +drop procedure if exists into_tes2| +create procedure into_test2(x char(16), y int) +begin + insert into test.t1 values (x, y); + select id,data from test.t1 limit 1 into x,@z; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +call into_test2("into", 100)| +select id,data,@z from t1 order by data| +delete from t1| +drop procedure into_test2| + + +# SELECT * INTO ... (bug test) +--disable_warnings ONCE +drop procedure if exists into_test3| +create procedure into_test3() +begin + declare x char(16); + declare y int; + + select * from test.t1 limit 1 into x,y; + insert into test.t2 values (x, y, 0.0); +end| + +insert into t1 values ("into3", 19)| +# Two call needed for bug test +call into_test3()| +call into_test3()| +select * from t2| +delete from t1| +delete from t2| +drop procedure into_test3| + + +# SELECT INTO with no data is a warning ("no data", which we will +# not see normally). When not caught, execution proceeds. +--disable_warnings ONCE +drop procedure if exists into_test4| +create procedure into_test4() +begin + declare x int; + + select data from test.t1 limit 1 into x; + insert into test.t3 values ("into4", x); +end| + +delete from t1| +create table t3 ( s char(16), d int)| +call into_test4()| +select * from t3| +insert into t1 values ("i4", 77)| +call into_test4()| +select * from t3| +delete from t1| +drop table t3| +drop procedure into_test4| + + +# These two (and the two procedures above) caused an assert() to fail in +# sql_base.cc:lock_tables() at some point. +--disable_warnings ONCE +drop procedure if exists into_outfile| +eval create procedure into_outfile(x char(16), y int) +begin + insert into test.t1 values (x, y); + select * from test.t1 into outfile "spout"; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +# Check that file does not exists +#--error 1 +#--file_exists /home/linlin.xll/spout/spout +#call into_outfile("ofile", 1)| +#--remove_file /home/linlin.xll/spout/spout +delete from t1| +drop procedure into_outfile| + +--disable_warnings ONCE +drop procedure if exists into_dumpfile| +eval create procedure into_dumpfile(x char(16), y int) +begin + insert into test.t1 values (x, y); + select * into dumpfile "spdump" from test.t1 limit 1; + insert into test.t1 values (concat(x, "2"), y+2); +end| + +# Check that file does not exists +#--error 1 +#--file_exists /home/linlin.xll/spout/spdump +#call into_dumpfile("dfile", 1)| +#--remove_file /home/linlin.xll/spout/spdump +delete from t1| +drop procedure into_dumpfile| + +--disable_warnings ONCE +drop procedure if exists create_select| + +create procedure create_select(x char(16), y int) +begin + insert into test.t1 values (x, y); + create temporary table test.t3 select * from test.t1; + insert into test.t3 values (concat(x, "2"), y+2); +end| + +call create_select("cs", 90)| +select * from t1, t3| +drop table t3| +delete from t1| + +drop procedure create_select| + + +# A minimal, constant FUNCTION. +--disable_warnings ONCE +drop function if exists e| +create function e() returns double + return 2.7182818284590452354| + +set @e = e()| +select e(), @e| + +# A minimal function with one argument +--disable_warnings ONCE +drop function if exists inc| +create function inc(i int) returns int + return i+1| + +select inc(1), inc(99), inc(-71)| + +# A minimal function with two arguments +--disable_warnings ONCE +drop function if exists mul| +create function mul(x int, y int) returns int + return x*y| + +select mul(1,1), mul(3,5), mul(4711, 666)| + +# A minimal string function +--disable_warnings ONCE +drop function if exists append| +create function append(s1 char(8), s2 char(8)) returns char(16) + return concat(s1, s2)| + +select append("foo", "bar")| + +# A function with flow control +--disable_warnings ONCE +drop function if exists fac| +create function fac(n int unsigned) returns bigint unsigned +begin + declare f bigint unsigned default 1; + + while n > 1 do + set f = f * n; + set n = n - 1; + end while; + return f; +end| + +select fac(1), fac(2), fac(5), fac(10)| + +# Nested calls +--disable_warnings ONCE +drop function if exists fun| +create function fun(d double, i int, u int unsigned) returns double + return mul(inc(i), fac(u)) / e()| + +select fun(2.3, 3, 5)| + + +# Various function calls in differen statements + +insert into t2 values (append("xxx", "yyy"), mul(4,3), e())| +insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))| + +# Disable PS because double's give a bit different values +--disable_ps_protocol +select * from t2 where s = append("a", "b")| +select * from t2 where i = mul(4,3) or i = mul(mul(3,4),2) order by i| +select * from t2 where d = e()| +select * from t2 order by i| +--enable_ps_protocol +delete from t2| + +drop function e| +drop function inc| +drop function mul| +drop function append| +drop function fun| + + +# +# CONDITIONs and HANDLERs +# + +--disable_warnings ONCE +drop procedure if exists hndlr1| +create procedure hndlr1(val int) +begin + declare x int default 0; + declare foo condition for 1136; + declare bar condition for sqlstate '42S98'; # Just for testing syntax + declare zip condition for sqlstate value '42S99'; # Just for testing syntax + declare continue handler for foo set x = 1; + + insert into test.t1 values ("hndlr1", val, 2); # Too many values + if (x) then + insert into test.t1 values ("hndlr1", val); # This instead then + end if; +end| + +call hndlr1(42)| +select * from t1| +delete from t1| +drop procedure hndlr1| + +--disable_warnings ONCE +drop procedure if exists hndlr2| +create procedure hndlr2(val int) +begin + declare x int default 0; + + begin + declare exit handler for sqlstate '21S01' set x = 1; + + insert into test.t1 values ("hndlr2", val, 2); # Too many values + end; + + insert into test.t1 values ("hndlr2", x); +end| + +call hndlr2(42)| +select * from t1| +delete from t1| +drop procedure hndlr2| + + +--disable_warnings ONCE +drop procedure if exists hndlr3| +create procedure hndlr3(val int) +begin + declare x int default 0; + declare continue handler for sqlexception # Any error + begin + declare z int; + + set z = 2 * val; + set x = 1; + end; + + if val < 10 then + begin + declare y int; + + set y = val + 10; + insert into test.t1 values ("hndlr3", y, 2); # Too many values + if x then + insert into test.t1 values ("hndlr3", y); + end if; + end; + end if; +end| + +call hndlr3(3)| +select * from t1| +delete from t1| +drop procedure hndlr3| + + +# Variables might be uninitialized when using handlers +# (Otherwise the compiler can detect if a variable is not set, but +# not in this case.) +create table t3 ( id char(16), data int )| + +--disable_warnings ONCE +drop procedure if exists hndlr4| +create procedure hndlr4() +begin + declare x int default 0; + declare val int; # No default + declare continue handler for sqlstate '02000' set x=1; + + select data from test.t3 where id='z' limit 1 into val; # No hits + + insert into test.t3 values ('z', val); +end| + +call hndlr4()| +select * from t3| +drop table t3| +drop procedure hndlr4| + + +# +# Cursors +# +--disable_warnings ONCE +drop procedure if exists cur1| +create procedure cur1() +begin + declare a char(16); + declare b int; + declare c double; + declare done int default 0; + declare c cursor for select * from test.t2; + declare continue handler for sqlstate '02000' set done = 1; + + open c; + repeat + fetch c into a, b, c; + if not done then + insert into test.t1 values (a, b+c); + end if; + until done end repeat; + close c; +end| + +insert into t2 values ("foo", 42, -1.9), ("bar", 3, 12.1), ("zap", 666, -3.14)| +call cur1()| +select * from t1| +drop procedure cur1| + +create table t3 ( s char(16), i int )| + +--disable_warnings ONCE +drop procedure if exists cur2| +create procedure cur2() +begin + declare done int default 0; + declare c1 cursor for select id,data from test.t1 order by id,data; + declare c2 cursor for select i from test.t2 order by i; + declare continue handler for sqlstate '02000' set done = 1; + + open c1; + open c2; + repeat + begin + declare a char(16); + declare b,c int; + + fetch from c1 into a, b; + fetch next from c2 into c; + if not done then + if b < c then + insert into test.t3 values (a, b); + else + insert into test.t3 values (a, c); + end if; + end if; + end; + until done end repeat; + close c1; + close c2; +end| + +call cur2()| +select * from t3 order by i,s| +delete from t1| +delete from t2| +drop table t3| +drop procedure cur2| + + +# The few characteristics we parse +--disable_warnings ONCE +set @old_mode=@@sql_mode| +set @@sql_mode=STRICT_ALL_TABLES| +drop procedure if exists chistics| +create procedure chistics() + language sql + modifies sql data + not deterministic + sql security definer + comment 'Characteristics procedure test' + insert into t1 values ("chistics", 1)| + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure chistics| +# Call it, just to make sure. +call chistics()| +select * from t1| +delete from t1| +alter procedure chistics sql security invoker| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure chistics| +drop procedure chistics| + +--disable_warnings ONCE +drop function if exists chistics| +create function chistics() returns int + language sql + deterministic + sql security invoker + comment 'Characteristics procedure test' + return 42| + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create function chistics| +# Call it, just to make sure. +select chistics()| +alter function chistics + no sql + comment 'Characteristics function test'| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create function chistics| +drop function chistics| +set @@sql_mode=@old_mode| + +# Check mode settings +insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| + +--error 1235 +set @@sql_mode = 'ANSI'| +delimiter $| +--disable_warnings ONCE +drop procedure if exists modes$ +create procedure modes(out c1 int, out c2 int) +begin + declare done int default 0; + declare x int; + declare c cursor for select data from t1; + declare continue handler for sqlstate '02000' set done = 1; + + select 1 || 2 into c1; + set c2 = 0; + open c; + repeat + fetch c into x; + if not done then + set c2 = c2 + 1; + end if; + until done end repeat; + close c; +end$ +delimiter |$ +set @@sql_mode = ''| + +set sql_select_limit = 1| +call modes(@c1, @c2)| +set sql_select_limit = default| + +select @c1, @c2| +delete from t1| +drop procedure modes| + + +# Check that dropping a database without routines works. +# (Dropping with routines is tested in sp-security.test) +# First an empty db. +create database sp_db1| +drop database sp_db1| + +# Again, with a table. +create database sp_db2| +use sp_db2| +# Just put something in here... +create table t3 ( s char(4), t int )| +insert into t3 values ("abcd", 42), ("dcba", 666)| +use test| +drop database sp_db2| + +# And yet again, with just a procedure. +create database sp_db3| +use sp_db3| +--disable_warnings ONCE +drop procedure if exists dummy| +create procedure dummy(out x int) + set x = 42| +use test| +drop database sp_db3| +# Check that it's gone +select type,db,name from mysql.proc where db = 'sp_db3'| + + +# ROW_COUNT() function after a CALL +# We test the other cases here too, although it's not strictly SP specific +--disable_warnings ONCE +drop procedure if exists rc| +create procedure rc() +begin + delete from t1; + insert into t1 values ("a", 1), ("b", 2), ("c", 3); +end| + +call rc()| +select row_count()| +--disable_ps_protocol +update t1 set data=42 where id = "b"; +select row_count()| +--enable_ps_protocol +delete from t1| +select row_count()| +delete from t1| +select row_count()| +select * from t1| +select row_count()| +drop procedure rc| + + +# +# Let us test how well new locking scheme works. +# + +# Let us prepare playground +--disable_warnings +drop function if exists f0| +drop function if exists f1| +drop function if exists f2| +drop function if exists f3| +drop function if exists f4| +drop function if exists f5| +drop function if exists f6| +drop function if exists f7| +drop function if exists f8| +drop function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| +drop view if exists v0| +drop view if exists v1| +drop view if exists v2| +--enable_warnings +delete from t1| +delete from t2| +insert into t1 values ("a", 1), ("b", 2) | +insert into t2 values ("a", 1, 1.0), ("b", 2, 2.0), ("c", 3, 3.0) | + +# Test the simplest function using tables +create function f1() returns int + return (select sum(data) from t1)| + +select f1()| +# This should work too (and give 2 rows as result) + +select id, f1() from t1 order by id| + +# Function which uses two instances of table simultaneously +create function f2() returns int + return (select data from t1 where data <= (select sum(data) from t1) order by data limit 1)| + +select f2()| +select id, f2() from t1 order by id| + +# Function which uses the same table twice in different queries +create function f3() returns int +begin + declare n int; + declare m int; + set n:= (select min(data) from t1); + set m:= (select max(data) from t1); + return n < m; +end| + +select f3()| +select id, f3() from t1 order by id| + +# Calling two functions using same table + +select f1(), f3()| +select id, f1(), f3() from t1 order by id| + +# Function which uses two different tables +create function f4() returns double + return (select d from t1, t2 where t1.data = t2.i and t1.id= "b")| + +select f4()| +select s, f4() from t2 order by s| + +# Recursive functions which due to this recursion require simultaneous +# access to several instance of the same table won't work +create function f5(i int) returns int +begin + if i <= 0 then + return 0; + elseif i = 1 then + return (select count(*) from t1 where data = i); + else + return (select count(*) + f5( i - 1) from t1 where data = i); + end if; +end| + +select f5(1)| +--error 1424 +select f5(2)| +--error 1424 +select f5(3)| + +# OTOH this should work +create function f6() returns int +begin + declare n int; + set n:= f1(); + return (select count(*) from t1 where data <= f7() and data <= n); +end| +create function f7() returns int + return (select sum(data) from t1 where data <= f1())| + +select f6()| +select id, f6() from t1 order by id| + +# +# Let us test how new locking work with views +# +# The most trivial view +create view v1 (a) as select f1()| + +select * from v1| +select id, a from t1, v1 order by id| + +select * from v1, v1 as v| +# A bit more complex construction +create view v2 (a) as select a*10 from v1| + +select * from v2| +select id, a from t1, v2 order by id| + +select * from v1, v2| + +# Nice example where the same view is used on +# on different expression levels +create function f8 () returns int + return (select count(*) from v2)| + +select *, f8() from v1| + +# Let us test what will happen if function is missing +drop function f1| +--error 1305 +select * from v1| + +# And what will happen if we have recursion which involves +# views and functions ? +create function f1() returns int + return (select sum(data) from t1) + (select sum(data) from v1)| +--error 1054 +select f1()| +--error 1054 +select * from v1| +--error 1054 +select * from v2| +# Back to the normal cases +drop function f1| +create function f1() returns int + return (select sum(data) from t1)| + +# Let us also test some weird cases where no real tables is used +create function f0() returns int + return (select * from (select 100) as r)| + +select f0()| +select *, f0() from (select 1) as t| +create view v0 as select f0()| + +select * from v0| +select *, f0() from v0| + +# +# Let us test how well prelocking works with explicit LOCK TABLES. +# +lock tables t1 read, t1 as t11 read| +# These should work well +select f3()| + +select id, f3() from t1 as t11 order by id| +# Degenerate cases work too :) +select f0()| +# But these should not (particularly views should be locked explicitly). + +select * from v0| +select *, f0() from v0, (select 123) as d1| + +select id, f3() from t1| + +select f4()| +unlock tables| + +# Let us test how LOCK TABLES which implicitly depends on functions +# works +lock tables v2 read, mysql.proc read| + +select * from v2| +select * from v1| +# These should not work as we have too little instances of tables locked +#--error ER_TABLE_NOT_LOCKED,1241 +#select * from v1, t1| + +select f4()| +unlock tables| + +# Tests for handling of temporary tables in functions. +# +# Unlike for permanent tables we should be able to create, use +# and drop such tables in functions. +# +# Simplest function using temporary table. It is also test case for bug +# #12198 "Temporary table aliasing does not work inside stored functions" +--error 1422 +create function f9() returns int +begin + declare a, b int; + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + set a:= (select count(*) from t3); + set b:= (select count(*) from t3 t3_alias); + return a + b; +end| +# This will emit warning as t3 was not existing before. +--error 1305 +select f9()| +--error 1305 +select f9() from t1 limit 1| + +# Function which uses both temporary and permanent tables. +--error 1422 +create function f10() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 select id from t4; + return (select count(*) from t3); +end| +# Check that we don't ignore completely tables used in function +--error 1305 +select f10()| +create table t4 as select 1 as id| +--error 1305 +select f10()| + +# Practical cases which we don't handle well (yet) +# +# Function which does not work because of well-known and documented +# limitation of MySQL. We can't use the several instances of the +# same temporary table in statement. +--error 1422 +create function f11() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return (select count(*) from t3 as a, t3 as b); +end| +--error 1305 +select f11()| +--error 1305 +select f11() from t1| +# Test that using a single table instance at a time works +--error 1422 +create function f12_1() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return f12_2(); +end| +create function f12_2() returns int + return (select count(*) from t3)| + +--error 1051 +drop temporary table t3| +--error 1305 +select f12_1()| +--error 1305 +select f12_1() from t1 limit 1| + +# Cleanup +drop function f0| +drop function f1| +drop function f2| +drop function f3| +drop function f4| +drop function f5| +drop function f6| +drop function f7| +drop function f8| +--error 1305 +drop function f9| +--error 1305 +drop function f10| +--error 1305 +drop function f11| +--error 1305 +drop function f12_1| +drop function f12_2| +drop view v0| +drop view v1| +drop view v2| +truncate table t1 | +truncate table t2 | +drop table t4| + +# End of non-bug tests + + +# +# Some "real" examples +# + +# fac + +--disable_warnings ONCE +drop table if exists t3| +create table t3 (n int unsigned not null primary key, f bigint unsigned)| + +--disable_warnings ONCE +drop procedure if exists ifac| +create procedure ifac(n int unsigned) +begin + declare i int unsigned default 1; + + if n > 20 then + set n = 20; # bigint overflow otherwise + end if; + while i <= n do + begin + insert into test.t3 values (i, fac(i)); + set i = i + 1; + end; + end while; +end| + +call ifac(20)| +select * from t3| +drop table t3| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like '%f%'| +drop procedure ifac| +drop function fac| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show function status like '%f%'| + + +# primes + +--disable_warnings ONCE +drop table if exists t3| + +create table t3 ( + i int unsigned not null primary key, + p bigint unsigned not null +)| + +insert into t3 values + ( 0, 3), ( 1, 5), ( 2, 7), ( 3, 11), ( 4, 13), + ( 5, 17), ( 6, 19), ( 7, 23), ( 8, 29), ( 9, 31), + (10, 37), (11, 41), (12, 43), (13, 47), (14, 53), + (15, 59), (16, 61), (17, 67), (18, 71), (19, 73), + (20, 79), (21, 83), (22, 89), (23, 97), (24, 101), + (25, 103), (26, 107), (27, 109), (28, 113), (29, 127), + (30, 131), (31, 137), (32, 139), (33, 149), (34, 151), + (35, 157), (36, 163), (37, 167), (38, 173), (39, 179), + (40, 181), (41, 191), (42, 193), (43, 197), (44, 199)| + +--disable_warnings ONCE +drop procedure if exists opp| +create procedure opp(n bigint unsigned, out pp bool) +begin + declare r double; + declare b, s bigint unsigned default 0; + + set r = sqrt(n); + + again: + loop + if s = 45 then + set b = b+200, s = 0; + else + begin + declare p bigint unsigned; + + select t.p from test.t3 t where t.i = s into p; + if b+p > r then + set pp = 1; + leave again; + end if; + if mod(n, b+p) = 0 then + set pp = 0; + leave again; + end if; + set s = s+1; + end; + end if; + end loop; +end| + +--disable_warnings ONCE +drop procedure if exists ip| +create procedure ip(m int unsigned) +begin + declare p bigint unsigned; + declare i int unsigned; + + set i=45, p=201; + + while i < m do + begin + declare pp bool default 0; + + call opp(p, pp); + if pp then + insert into test.t3 values (i, p); + set i = i+1; + end if; + set p = p+2; + end; + end while; +end| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure opp| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status where (name = 'opp' or name = 'ip') and db='test'| + +# This isn't the fastest way in the world to compute prime numbers, so +# don't be too ambitious. ;-) +call ip(200)| +# We don't want to select the entire table here, just pick a few +# examples. +# The expected result is: +# i p +# --- ---- +# 45 211 +# 100 557 +# 199 1229 +select * from t3 where i=45 or i=100 or i=199| +drop table t3| +drop procedure opp| +drop procedure ip| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status where (name = 'opp' or name = 'ip') and db='test'| + + +# +# Comment & suid +# + +--disable_warnings ONCE +drop procedure if exists bar| +create procedure bar(x char(16), y int) + comment "111111111111" sql security invoker + insert into test.t1 values (x, y)| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bar'| +alter procedure bar comment "2222222222" sql security definer| +alter procedure bar comment "3333333333"| +alter procedure bar| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure bar| +--replace_column 4 'root@localhost' 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +show procedure status like 'bar'| +drop procedure bar| + +# +# rexecution +# +--disable_warnings ONCE +drop procedure if exists p1| +create procedure p1 () + select (select s1 from t3) from t3| + +create table t3 (s1 int)| + +call p1()| +insert into t3 values (1)| +call p1()| +drop procedure p1| +drop table t3| + +# +# backticks +# +--disable_warnings ONCE +drop function if exists foo| +create function `foo` () returns int + return 5| +select `foo` ()| +drop function `foo`| + +# +# Implicit LOCK/UNLOCK TABLES for table access in functions +# + +--disable_warnings ONCE +drop function if exists t1max| +create function t1max() returns int +begin + declare x int; + select max(data) from t1 into x; + return x; +end| + +insert into t1 values ("foo", 3), ("bar", 2), ("zip", 5), ("zap", 1)| +select t1max()| +drop function t1max| + +create table t3 ( + v char(16) not null primary key, + c int unsigned not null +)| + +--disable_warnings ONCE +drop function if exists getcount;| +create function getcount(s char(16)) returns int +begin + declare x int; + + select count(*) from t3 where v = s into x; + if x = 0 then + insert into t3 values (s, 1); + else + update t3 set c = c+1 where v = s; + end if; + return x; +end| +select * from t1 where data = getcount("bar")| +select * from t3| +select getcount("zip")| +select getcount("zip")| +select * from t3| +select getcount(id) from t1 where data = 3| +select getcount(id) from t1 where data = 5| +select * from t3| +drop table t3| +drop function getcount| + + +# Test cases for different combinations of condition handlers in nested +# begin-end blocks in stored procedures. +# +# The SQL standard document says: +# "8) If there is a general and a specific +# for the same in the same scope, then +# only the specific is associated with that +# ." + +# A general handler declaration has SQLWARNING + SQLEXCEPTION + NOT FOUND. +# A specific handler declaration has SQLSTATE, condition name, or (for MySQL) +# an errno. +# +# So when there are multiple handlers in the same scope, they're all +# applicable, but the most specific handler should be activated. Notice the +# standard's exact words: "in the same scope". A specific handler declaration +# in an outer scope must not be activated instead of a general handler +# declaration in the inner scope. Previously that was not the case in MySQL. +# +# Note also that '02000' is more specific than NOT FOUND; there might be +# other '02xxx' states, even if we currently do not issue them in any +# situation (e.g. '02001'). +# +# Thus, in all combinations below an inner handler should be activated. + +--disable_warnings +drop table if exists t3| +drop procedure if exists h_ee| +drop procedure if exists h_es| +drop procedure if exists h_en| +drop procedure if exists h_ew| +drop procedure if exists h_ex| +drop procedure if exists h_se| +drop procedure if exists h_ss| +drop procedure if exists h_sn| +drop procedure if exists h_sw| +drop procedure if exists h_sx| +drop procedure if exists h_ne| +drop procedure if exists h_ns| +drop procedure if exists h_nn| +drop procedure if exists h_we| +drop procedure if exists h_ws| +drop procedure if exists h_ww| +drop procedure if exists h_xe| +drop procedure if exists h_xs| +drop procedure if exists h_xx| +--enable_warnings + +# smallint - to get out of range warnings +# primary key - to get constraint errors +create table t3 (a smallint primary key)| + +insert into t3 (a) values (1)| + +create procedure h_ee() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (bad)' as 'h_ee'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_ee'; + + insert into t3 values (1); + end; +end| + +create procedure h_es() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (bad)' as 'h_es'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_es'; + + insert into t3 values (1); + end; +end| + +create procedure h_en() + deterministic +begin + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Outer (bad)' as 'h_en'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (good)' as 'h_en'; + + select a from t3 where a = 42 into x; + end; +end| + +create procedure h_ew() + deterministic +begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Outer (bad)' as 'h_ew'; + + begin + declare continue handler for sqlwarning + select 'Inner (good)' as 'h_ew'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ex() + deterministic +begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Outer (bad)' as 'h_ex'; + + begin + declare continue handler for sqlexception + select 'Inner (good)' as 'h_ex'; + + insert into t3 values (1); + end; +end| + +create procedure h_se() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_se'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_se'; + + insert into t3 values (1); + end; +end| + +create procedure h_ss() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_ss'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_ss'; + + insert into t3 values (1); + end; +end| + +create procedure h_sn() + deterministic +begin + -- Note: '02000' is more specific than NOT FOUND ; + -- there might be other not found states + declare continue handler for sqlstate '02000' -- no data + select 'Outer (bad)' as 'h_sn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (good)' as 'h_sn'; + + select a from t3 where a = 42 into x; + end; +end| + +create procedure h_sw() + deterministic +begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Outer (bad)' as 'h_sw'; + + begin + declare continue handler for sqlwarning + select 'Inner (good)' as 'h_sw'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_sx() + deterministic +begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Outer (bad)' as 'h_sx'; + + begin + declare continue handler for sqlexception + select 'Inner (good)' as 'h_sx'; + + insert into t3 values (1); + end; +end| + +create procedure h_ne() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ne'; + + begin + declare x int; + declare continue handler for 1329 -- ER_SP_FETCH_NO_DATA + select 'Inner (good)' as 'h_ne'; + + select a from t3 where a = 42 into x; + end; +end| + +create procedure h_ns() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_ns'; + + begin + declare x int; + declare continue handler for sqlstate '02000' -- no data + select 'Inner (good)' as 'h_ns'; + + select a from t3 where a = 42 into x; + end; +end| + +create procedure h_nn() + deterministic +begin + declare continue handler for not found + select 'Outer (bad)' as 'h_nn'; + + begin + declare x int; + declare continue handler for not found + select 'Inner (good)' as 'h_nn'; + + select a from t3 where a = 42 into x; + end; +end| + +create procedure h_we() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_we'; + + begin + declare continue handler for 1264 -- ER_WARN_DATA_OUT_OF_RANGE + select 'Inner (good)' as 'h_we'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ws() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ws'; + + begin + -- data exception - numeric value out of range + declare continue handler for sqlstate '22003' + select 'Inner (good)' as 'h_ws'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_ww() + deterministic +begin + declare continue handler for sqlwarning + select 'Outer (bad)' as 'h_ww'; + + begin + declare continue handler for sqlwarning + select 'Inner (good)' as 'h_ww'; + + insert into t3 values (123456789012); + end; + delete from t3; + insert into t3 values (1); +end| + +create procedure h_xe() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xe'; + + begin + declare continue handler for 1062 -- ER_DUP_ENTRY + select 'Inner (good)' as 'h_xe'; + + insert into t3 values (1); + end; +end| + +create procedure h_xs() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xs'; + + begin + -- integrity constraint violation + declare continue handler for sqlstate '23000' + select 'Inner (good)' as 'h_xs'; + + insert into t3 values (1); + end; +end| + +create procedure h_xx() + deterministic +begin + declare continue handler for sqlexception + select 'Outer (bad)' as 'h_xx'; + + begin + declare continue handler for sqlexception + select 'Inner (good)' as 'h_xx'; + + insert into t3 values (1); + end; +end| + +call h_ee()| +call h_es()| +call h_en()| +call h_ew()| +call h_ex()| +call h_se()| +call h_ss()| +call h_sn()| +call h_sw()| +call h_sx()| +call h_ne()| +call h_ns()| +call h_nn()| +call h_we()| +call h_ws()| +call h_ww()| +call h_xe()| +call h_xs()| +call h_xx()| + +drop table t3| +drop procedure h_ee| +drop procedure h_es| +drop procedure h_en| +drop procedure h_ew| +drop procedure h_ex| +drop procedure h_se| +drop procedure h_ss| +drop procedure h_sn| +drop procedure h_sw| +drop procedure h_sx| +drop procedure h_ne| +drop procedure h_ns| +drop procedure h_nn| +drop procedure h_we| +drop procedure h_ws| +drop procedure h_ww| +drop procedure h_xe| +drop procedure h_xs| +drop procedure h_xx| + + +# +# Test cases for old bugs +# + +# +# BUG#822 +# +--disable_warnings ONCE +drop procedure if exists bug822| +create procedure bug822(a_id char(16), a_data int) +begin + declare n int; + select count(*) from t1 where id = a_id and data = a_data into n; + if n = 0 then + insert into t1 (id, data) values (a_id, a_data); + end if; +end| + +delete from t1| +call bug822('foo', 42)| +call bug822('foo', 42)| +call bug822('bar', 666)| +select * from t1 order by data| +delete from t1| +drop procedure bug822| + +# +# BUG#1495 +# +--disable_warnings ONCE +drop procedure if exists bug1495| +create procedure bug1495() +begin + declare x int; + + select data from t1 order by id limit 1 into x; + if x > 10 then + insert into t1 values ("less", x-10); + else + insert into t1 values ("more", x+10); + end if; +end| + +insert into t1 values ('foo', 12)| +call bug1495()| +delete from t1 where id='foo'| +insert into t1 values ('bar', 7)| +call bug1495()| +delete from t1 where id='bar'| +select * from t1 order by data| +delete from t1| +drop procedure bug1495| + +# +# BUG#1547 +# +--disable_warnings ONCE +drop procedure if exists bug1547| +create procedure bug1547(s char(16)) +begin + declare x int; + + select data from t1 where s = id limit 1 into x; + if x > 10 then + insert into t1 values ("less", x-10); + else + insert into t1 values ("more", x+10); + end if; +end| + +insert into t1 values ("foo", 12), ("bar", 7)| +call bug1547("foo")| +call bug1547("bar")| +select * from t1 order by id| +delete from t1| +drop procedure bug1547| + +# +# BUG#1656 +# +--disable_warnings ONCE +drop table if exists t70| +create table t70 (s1 int,s2 int)| +insert into t70 values (1,2)| + +--disable_warnings ONCE +drop procedure if exists bug1656| +create procedure bug1656(out p1 int, out p2 int) + select * from t70 into p1, p1| + +call bug1656(@1, @2)| +select @1, @2| +drop table t70| +drop procedure bug1656| + +# +# BUG#1862 +# +create table t3(a int)| + +--disable_warnings ONCE +drop procedure if exists bug1862| +--error 1064 +create procedure bug1862() +begin + insert into t3 values(2); + flush tables; +end| + +--error 1305 +call bug1862()| +# the second call caused a segmentation +--error 1305 +call bug1862()| +select * from t3| +drop table t3| +--error 1305 +drop procedure bug1862| + +# +# BUG#1874 +# +--disable_warnings ONCE +drop procedure if exists bug1874| +create procedure bug1874() +begin + declare x int; + declare y double; + select max(data) from t1 into x; + insert into t2 values ("max", x, 0); + select min(data) from t1 into x; + insert into t2 values ("min", x, 0); + select sum(data) from t1 into x; + insert into t2 values ("sum", x, 0); + select avg(data) from t1 into y; + insert into t2 values ("avg", 0, y); +end| + +insert into t1 (data) values (3), (1), (5), (9), (4)| +call bug1874()| +select * from t2 order by i| +delete from t1| +delete from t2| +drop procedure bug1874| + +# +# BUG#2260 +# +--disable_warnings ONCE +drop procedure if exists bug2260| +create procedure bug2260() +begin + declare v1 int; + declare c1 cursor for select data from t1; + declare continue handler for not found set @x2 = 1; + + open c1; + fetch c1 into v1; + set @x2 = 2; + close c1; +end| + +call bug2260()| +select @x2| +drop procedure bug2260| + +# +# BUG#2267 "Lost connect if stored procedure has SHOW FUNCTION STATUS" +# +--disable_warnings ONCE +drop procedure if exists bug2267_1| +create procedure bug2267_1() +begin + show procedure status where db='test'; +end| + +--disable_warnings ONCE +drop procedure if exists bug2267_2| +create procedure bug2267_2() +begin + show function status where db='test'; +end| + +--disable_warnings ONCE +drop procedure if exists bug2267_3| +create procedure bug2267_3() +begin + show create procedure bug2267_1; +end| + +--disable_warnings +drop procedure if exists bug2267_4| +drop function if exists bug2267_4| +--enable_warnings +create procedure bug2267_4() +begin + show create function bug2267_4; +end| +create function bug2267_4() returns int return 100| + +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +call bug2267_1()| +--replace_column 5 '0000-00-00 00:00:00' 6 '0000-00-00 00:00:00' +call bug2267_2()| +call bug2267_3()| +call bug2267_4()| + +drop procedure bug2267_1| +drop procedure bug2267_2| +drop procedure bug2267_3| +drop procedure bug2267_4| +drop function bug2267_4| + +# +# BUG#2227 +# +--disable_warnings ONCE +drop procedure if exists bug2227| +create procedure bug2227(x int) +begin + declare y float default 2.6; + declare z char(16) default "zzz"; + + select 1.3, x, y, 42, z; +end| + +call bug2227(9)| +drop procedure bug2227| + +# +# BUG#2614 "Stored procedure with INSERT ... SELECT that does not +# contain any tables crashes server" +# +--disable_warnings ONCE +drop procedure if exists bug2614| +create procedure bug2614() +begin + drop table if exists t3; + create table t3 (id int default '0' not null); + insert into t3 select 12; + insert into t3 select * from t3; +end| + +--disable_warnings ONCE +call bug2614()| +call bug2614()| +drop table t3| +drop procedure bug2614| + +# +# BUG#2674 +# +--disable_warnings ONCE +drop function if exists bug2674| +create function bug2674() returns int + return @@ob_bnl_join_cache_size| + +set @osbs = @@ob_bnl_join_cache_size| +set @@ob_bnl_join_cache_size = 262000| +select bug2674()| +drop function bug2674| +set @@ob_bnl_join_cache_size = @osbs| + +# +# BUG#3259 +# +--disable_warnings ONCE +drop procedure if exists bug3259_1 | +create procedure bug3259_1 () begin end| +--disable_warnings ONCE +drop procedure if exists BUG3259_2 | +create procedure BUG3259_2 () begin end| +--disable_warnings ONCE +drop procedure if exists Bug3259_3 | +create procedure Bug3259_3 () begin end| + +call BUG3259_1()| +call BUG3259_1()| +call bug3259_2()| +call Bug3259_2()| +call bug3259_3()| +call bUG3259_3()| + +drop procedure bUg3259_1| +drop procedure BuG3259_2| +drop procedure BUG3259_3| + +# +# BUG#2772 +# +--disable_warnings ONCE +drop function if exists bug2772| +--error 1115 +create function bug2772() returns char(10) character set latin2 + return 'a'| + +--error 1305 +select bug2772()| +--error 1305 +drop function bug2772| + +# +# BUG#2780 +# +create table t3 (s1 smallint)| + +insert into t3 values (123456789012)| + +--disable_warnings ONCE +drop procedure if exists bug2780| +create procedure bug2780() +begin + declare exit handler for sqlwarning set @x = 1; + + set @x = 0; + insert into t3 values (123456789012); + insert into t3 values (0); +end| + +call bug2780()| +select @x| +select * from t3| + +drop procedure bug2780| +drop table t3| + +# +# BUG#1863 +# +create table t3 (content varchar(10) )| +insert into t3 values ("test1")| +insert into t3 values ("test2")| +create table t4 (f1 int, rc int, t3 int)| + +--disable_warnings ONCE +drop procedure if exists bug1863| + +create procedure bug1863(in1 int) +begin + + declare ind int default 0; + declare t1 int; + declare t2 int; + declare t3 int; + + declare rc int default 0; + declare continue handler for 1065 set rc = 1; + + drop temporary table if exists temp_t1; + create temporary table temp_t1 ( + f1 int auto_increment, f2 varchar(20), primary key (f1) + ); + + insert into temp_t1 (f2) select content from t3; + + select f2 into t3 from temp_t1 where f1 = 10; + + if (rc) then + insert into t4 values (1, rc, t3); + end if; + + insert into t4 values (2, rc, t3); + +end| + +call bug1863(10)| +select * from t4| + +drop procedure bug1863| +drop temporary table temp_t1| +drop table t3, t4| + +# +# BUG#2656 +# + +create table t3 ( + OrderID int not null, + MarketID int, + primary key (OrderID) +)| + +create table t4 ( + MarketID int not null, + Market varchar(60), + Status char(1), + primary key (MarketID) +)| + +insert t3 (OrderID,MarketID) values (1,1)| +insert t3 (OrderID,MarketID) values (2,2)| +insert t4 (MarketID,Market,Status) values (1,"MarketID One","A")| +insert t4 (MarketID,Market,Status) values (2,"MarketID Two","A")| + +--disable_warnings ONCE +drop procedure if exists bug2656_1| +create procedure bug2656_1() +begin + select + m.Market + from t4 m JOIN t3 o + ON o.MarketID != 1 and o.MarketID = m.MarketID; +end | + +--disable_warnings ONCE +drop procedure if exists bug2656_2| +create procedure bug2656_2() +begin + select + m.Market + from + t4 m, t3 o + where + m.MarketID != 1 and m.MarketID = o.MarketID; + +end | + +call bug2656_1()| +call bug2656_1()| +call bug2656_2()| +call bug2656_2()| +drop procedure bug2656_1| +drop procedure bug2656_2| +drop table t3, t4| + + +# +# BUG#3426 +# +--disable_warnings ONCE +drop procedure if exists bug3426| +create procedure bug3426(in_time int unsigned, out x int) +begin + if in_time is null then + set @stamped_time=10; + set x=1; + else + set @stamped_time=in_time; + set x=2; + end if; +end| + +# so that from_unixtime() has a deterministic result +set time_zone='+03:00'; + +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +# Clear SP cache +alter procedure bug3426 sql security invoker| +call bug3426(NULL, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| +call bug3426(1000, @i)| +select @i, from_unixtime(@stamped_time, '%d-%m-%Y %h:%i:%s') as time| + +drop procedure bug3426| + +# +# BUG#3734 +# +#create table t3 ( +# id int unsigned auto_increment not null primary key, +# title VARCHAR(200), +# body varchar(1024), +# fulltext (title,body) +#)| + +#insert into t3 (title,body) values +# ('MySQL Tutorial','DBMS stands for DataBase ...'), +# ('How To Use MySQL Well','After you went through a ...'), +# ('Optimizing MySQL','In this tutorial we will show ...'), +# ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'), +# ('MySQL vs. YourSQL','In the following database comparison ...'), +# ('MySQL Security','When configured properly, MySQL ...')| + +#--disable_warnings ONCE +#drop procedure if exists bug3734 | +#--error 1064 +#create procedure bug3734 (param1 varchar(100)) +# select * from t3 where match (title,body) against (param1)| + +#--error 1305 +#call bug3734('database')| +#--error 1305 +#call bug3734('Security')| + +#--error 1305 +#drop procedure bug3734| +#drop table t3| + +# +# BUG#3863 +# +--disable_warnings ONCE +drop procedure if exists bug3863| +create procedure bug3863() +begin + set @a = 0; + while @a < 5 do + set @a = @a + 1; + end while; +end| + +call bug3863()| +select @a| +call bug3863()| +select @a| + +drop procedure bug3863| + +# +# BUG#2460 +# + +create table t3 ( + id int(10) unsigned not null default 0, + rid int(10) unsigned not null default 0, + msg varchar(1024) not null, + primary key (id), + unique key rid (rid, id) +)| + +--disable_warnings ONCE +drop procedure if exists bug2460_1| +create procedure bug2460_1(in v int) +begin + ( select n0.id from t3 as n0 where n0.id = v ) + union + ( select n0.id from t3 as n0, t3 as n1 + where n0.id = n1.rid and n1.id = v ) + union + ( select n0.id from t3 as n0, t3 as n1, t3 as n2 + where n0.id = n1.rid and n1.id = n2.rid and n2.id = v ) order by id; +end| + +call bug2460_1(2)| +call bug2460_1(2)| +insert into t3 values (1, 1, 'foo'), (2, 1, 'bar'), (3, 1, 'zip zap')| +call bug2460_1(2)| +call bug2460_1(2)| + +--disable_warnings ONCE +drop procedure if exists bug2460_2| + +create procedure bug2460_2() +begin + drop table if exists t3; + create temporary table t3 (s1 int); + insert into t3 select 1 union select 1; +end| + +call bug2460_2()| +select * from t3| + +drop procedure bug2460_1| +drop procedure bug2460_2| +drop table t3| + + +# +# BUG#2564 +# +set @@sql_mode = ''| +--disable_warnings ONCE +drop procedure if exists bug2564_1| +create procedure bug2564_1() + comment 'Joe''s procedure' + insert into `t1` values ("foo", 1)| + +set @@sql_mode = 'ANSI_QUOTES'| +--disable_warnings ONCE +drop procedure if exists bug2564_2| +--error 1064 +create procedure bug2564_2() + insert into "t1" values ('foo', 1)| + +delimiter $| +set @@sql_mode = ''$ +--disable_warnings ONCE +drop function if exists bug2564_3$ +create function bug2564_3(x int, y int) returns int + return x || y$ + +--error 1235 +set @@sql_mode = 'ANSI'$ +--disable_warnings ONCE +drop function if exists bug2564_4$ +create function bug2564_4(x int, y int) returns int + return x || y$ +delimiter |$ + +set @@sql_mode = ''| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure bug2564_1| +--error 1305 +show create procedure bug2564_2| +show create function bug2564_3| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create function bug2564_4| + +drop procedure bug2564_1| +--error 1305 +drop procedure bug2564_2| +drop function bug2564_3| +drop function bug2564_4| + +# +# BUG#3132 +# +--disable_warnings ONCE +drop function if exists bug3132| +create function bug3132(s char(20)) returns char(50) + return concat('Hello, ', s, '!')| + +select bug3132('Bob') union all select bug3132('Judy')| +drop function bug3132| + +# +# BUG#3843 +# +--disable_warnings ONCE +drop procedure if exists bug3843| +--error 1064 +create procedure bug3843() + analyze table t1| + +# Testing for packets out of order +--error 1305 +call bug3843()| +--error 1305 +call bug3843()| +select 1+2| +--error 1305 +drop procedure bug3843| + +# +# BUG#3368 +# +create table t3 ( s1 char(10) )| +insert into t3 values ('a'), ('b')| + +--disable_warnings ONCE +drop procedure if exists bug3368| +create procedure bug3368(v char(10)) +begin + select group_concat(v) from t3; +end| + +call bug3368('x')| +call bug3368('yz')| +drop procedure bug3368| +drop table t3| + +# +# BUG#4579 +# +create table t3 (f1 int, f2 int)| +insert into t3 values (1,1)| + +--disable_warnings ONCE +drop procedure if exists bug4579_1| +create procedure bug4579_1 () +begin + declare sf1 int; + + select f1 from t3 where f1=1 and f2=1 into sf1; + update t3 set f2 = f2 + 1 where f1=1 and f2=1; + call bug4579_2(); +end| + +--disable_warnings ONCE +drop procedure if exists bug4579_2| +create procedure bug4579_2 () +begin +end| + +call bug4579_1()| +call bug4579_1()| +call bug4579_1()| + +drop procedure bug4579_1| +drop procedure bug4579_2| +drop table t3| + +# +# BUG#2773: Function's data type ignored in stored procedures +# +--disable_warnings ONCE +drop function if exists bug2773| + +create function bug2773() returns int return null| +create table t3 as select bug2773()| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create table t3| +drop table t3| +drop function bug2773| + +# +# BUG#3788: Stored procedure packet error +# +--disable_warnings ONCE +drop procedure if exists bug3788| + +create function bug3788() returns date return cast("2005-03-04" as date)| +select bug3788()| +drop function bug3788| + +create function bug3788() returns binary(1) return 5| +select bug3788()| +drop function bug3788| + + +# +# BUG#4726 +# +create table t3 (f1 int, f2 int, f3 int)| +insert into t3 values (1,1,1)| + +--disable_warnings ONCE +drop procedure if exists bug4726| +create procedure bug4726() +begin + declare tmp_o_id INT; + declare tmp_d_id INT default 1; + + while tmp_d_id <= 2 do + begin + select f1 from t3 where f2=1 and f3=1 into tmp_o_id; + set tmp_d_id = tmp_d_id + 1; + end; + end while; +end| + +call bug4726()| +call bug4726()| +call bug4726()| + +drop procedure bug4726| +drop table t3| + +# +# BUG#4318 +# + +--disable_parsing # Don't know if HANDLER commands can work with SPs, or at all.. +create table t3 (s1 int)| +insert into t3 values (3), (4)| + +--disable_warnings ONCE +drop procedure if exists bug4318| +create procedure bug4318() + handler t3 read next| + +handler t3 open| +# Expect no results, as tables are closed, but there shouldn't be any errors +call bug4318()| +call bug4318()| +handler t3 close| + +drop procedure bug4318| +drop table t3| +--enable_parsing + +# +# BUG#4902: Stored procedure with SHOW WARNINGS leads to packet error +# +# Added tests for most other show commands we could find too. +# (Skipping those already tested, and the ones depending on optional handlers.) +# +# Note: This will return a large number of results of different formats, +# which makes it impossible to filter with --replace_column. +# It's possible that some of these are not deterministic across +# platforms. If so, just remove the offending command. +# +--disable_warnings ONCE +drop procedure if exists bug4902| +create procedure bug4902() +begin + show charset like 'foo'; + show collation like 'foo'; + show create table t1; + show create database test; + show databases like 'foo'; + show errors; + show columns from t1; + show keys from t1; + #show open tables like 'foo'; + # Removed because result will differ in embedded mode. + #show privileges; + show status like 'foo'; + show tables like 'foo'; + show variables like 'foo'; + show warnings; +end| +--disable_parsing +--replace_regex /table_id: [0-9]+/table_id: #/ +show binlog events| +show storage engines| +show master status| +show slave hosts| +show slave status| +--enable_parsing +#TODO: core +#call bug4902()| +#call bug4902()| + +drop procedure bug4902| + +# +# BUG#4904 +# +--disable_warnings ONCE +drop procedure if exists bug4904| +create procedure bug4904() +begin + declare continue handler for sqlstate 'HY000' begin end; + + create table t2 as select * from t3; +end| + +-- error 1146 +call bug4904()| + +drop procedure bug4904| +--error 1115 +create table t3 (s1 char character set latin1, s2 char character set latin2)| +create table t3 (s1 char character set utf8, s2 char character set utf8)| +--disable_warnings ONCE +drop procedure if exists bug4904| +create procedure bug4904 () +begin + declare continue handler for sqlstate 'HY000' begin end; + + select s1 from t3 union select s2 from t3; +end| + +call bug4904()| + +drop procedure bug4904| +drop table t3| + +# +# BUG#336 +# +--disable_warnings ONCE +drop procedure if exists bug336| +create procedure bug336(out y int) +begin + declare x int; + set x = (select sum(t.data) from test.t1 t); + set y = x; +end| + +insert into t1 values ("a", 2), ("b", 3)| + +call bug336(@y)| +select @y| +delete from t1| +drop procedure bug336| + +# +# BUG#3157 +# +--disable_warnings ONCE +drop procedure if exists bug3157| +create procedure bug3157() +begin + if exists(select * from t1) then + set @n= @n + 1; + end if; + if (select count(*) from t1) then + set @n= @n + 1; + end if; +end| + +set @n = 0| +insert into t1 values ("a", 1)| + +call bug3157()| +select @n| +delete from t1| +drop procedure bug3157| + +# +# BUG#5251: mysql changes creation time of a procedure/function when altering +# +--disable_warnings ONCE +drop procedure if exists bug5251| +create procedure bug5251() +begin +end| + +#--error 1222 +select created from mysql.proc + where db='test' and name='bug5251' into @c1| +--sleep 2 +alter procedure bug5251 comment 'foobar'| +select count(*) from mysql.proc + where db='test' and name='bug5251' and created = @c1| + +drop procedure bug5251| + +# +# BUG#5279: Stored procedure packets out of order if CHECKSUM TABLE +# +--disable_warnings ONCE +drop procedure if exists bug5251| +--error 1064 +create procedure bug5251() + checksum table t1| +--error 1305 +call bug5251()| +--error 1305 +call bug5251()| +--error 1305 +drop procedure bug5251| + +# +# BUG#5287: Stored procedure crash if leave outside loop +# +--disable_warnings ONCE +drop procedure if exists bug5287| +create procedure bug5287(param1 int) +label1: + begin + declare c cursor for select 5; + + loop + if param1 >= 0 then + leave label1; + end if; + end loop; +end| +call bug5287(1)| +drop procedure bug5287| + + +# +# BUG#5307: Stored procedure allows statement after BEGIN ... END +# +--disable_warnings ONCE +drop procedure if exists bug5307| +create procedure bug5307() +begin +end; set @x = 3| + +call bug5307()| +select @x| +drop procedure bug5307| + +# +# BUG#5258: Stored procedure modified date is 0000-00-00 +# (This was a design flaw) +--disable_warnings ONCE +drop procedure if exists bug5258| +create procedure bug5258() +begin +end| + +--disable_warnings ONCE +drop procedure if exists bug5258_aux| +create procedure bug5258_aux() +begin + declare c, m char(27); + + select created,modified from mysql.proc where name = 'bug5258' into c,m; + if c = m then + select 'Ok'; + else + select c, m; + end if; +end| + +call bug5258_aux()| + +drop procedure bug5258| +drop procedure bug5258_aux| + +# +# BUG#4487: Stored procedure connection aborted if uninitialized char +# +--disable_warnings ONCE +drop function if exists bug4487| +create function bug4487() returns char +begin + declare v char; + return v; +end| + +select bug4487()| +drop function bug4487| + + +# +# BUG#4941: Stored procedure crash fetching null value into variable. +# +--disable_warnings +drop procedure if exists bug4941| +drop procedure if exists bug4941| +--enable_warnings +create procedure bug4941(out x int) +begin + declare c cursor for select i from t2 limit 1; + open c; + fetch c into x; + close c; +end| + +insert into t2 values (null, null, null)| +set @x = 42| +call bug4941(@x)| +select @x| +delete from t1| +drop procedure bug4941| + +# +# BUG#4905: Stored procedure doesn't clear for "Rows affected" +# +--disable_warnings ONCE +drop procedure if exists bug4905| + +create table t3 (s1 int,primary key (s1))| + +--disable_warnings ONCE +drop procedure if exists bug4905| +create procedure bug4905() +begin + declare v int; + declare continue handler for sqlstate '23000' set v = 5; + + insert into t3 values (1); +end| + +call bug4905()| +select row_count()| +call bug4905()| +select row_count()| +call bug4905()| +select row_count()| +select * from t3| + +drop procedure bug4905| +drop table t3| + +# +# BUG#6022: Stored procedure shutdown problem with self-calling function. +# + +--disable_parsing # until we implement support for recursive stored functions. +--disable_warnings ONCE +drop function if exists bug6022| + +--disable_warnings ONCE +drop function if exists bug6022| +create function bug6022(x int) returns int +begin + if x < 0 then + return 0; + else + return bug6022(x-1); + end if; +end| + +select bug6022(5)| +drop function bug6022| +--enable_parsing + +# +# BUG#6029: Stored procedure specific handlers should have priority +# +--disable_warnings ONCE +drop procedure if exists bug6029| + +--disable_warnings ONCE +drop procedure if exists bug6029| +create procedure bug6029() +begin + declare exit handler for 1136 select '1136'; + declare exit handler for sqlstate '23000' select 'sqlstate 23000'; + declare continue handler for sqlexception select 'sqlexception'; + + insert into t3 values (1); + insert into t3 values (1,2); +end| + +create table t3 (s1 int, primary key (s1))| +insert into t3 values (1)| +call bug6029()| +delete from t3| +call bug6029()| + +drop procedure bug6029| +drop table t3| + +# +# BUG#8540: Local variable overrides an alias +# +--disable_warnings ONCE +drop procedure if exists bug8540| + +create procedure bug8540() +begin + declare x int default 1; + select x as y, x+0 as z; +end| + +call bug8540()| +drop procedure bug8540| + +# +# BUG#6642: Stored procedure crash if expression with set function +# +create table t3 (s1 int)| + +--disable_warnings ONCE +drop procedure if exists bug6642| + +create procedure bug6642() + select abs(count(s1)) from t3| + +call bug6642()| +call bug6642()| +drop procedure bug6642| + +# +# BUG#7013: Stored procedure crash if group by ... with rollup +# +insert into t3 values (0),(1)| +--disable_warnings ONCE +drop procedure if exists bug7013| +create procedure bug7013() + select s1,count(s1) from t3 group by s1 with rollup| +call bug7013()| +call bug7013()| +drop procedure bug7013| + +# +# BUG#7743: 'Lost connection to MySQL server during query' on Stored Procedure +# +--disable_warnings ONCE +drop table if exists t4| +--error 1115 +create table t4 ( + a mediumint(8) unsigned not null auto_increment, + b smallint(5) unsigned not null, + c char(32) not null, + primary key (a) +) engine=myisam default charset=latin1| +create table t4 ( + a mediumint(8) unsigned not null auto_increment, + b smallint(5) unsigned not null, + c char(32) not null, + primary key (a) +) engine=myisam default charset=utf8mb4| +insert into t4 values (1, 2, 'oneword')| +insert into t4 values (2, 2, 'anotherword')| + +--disable_warnings ONCE +drop procedure if exists bug7743| +create procedure bug7743 ( searchstring char(28) ) +begin + declare var mediumint(8) unsigned; + select a from t4 where b = 2 and c = binary searchstring limit 1 into var; + select var; +end| + +call bug7743("oneword")| +call bug7743("OneWord")| +call bug7743("anotherword")| +call bug7743("AnotherWord")| +drop procedure bug7743| +drop table t4| + +# +# BUG#7992: SELECT .. INTO variable .. within Stored Procedure crashes +# the server +# +delete from t3| +insert into t3 values(1)| +drop procedure if exists bug7992_1| +drop procedure if exists bug7992_2| +create procedure bug7992_1() +begin + declare i int; + select max(s1)+1 from t3 into i; +end| +create procedure bug7992_2() + insert into t3 (s1) select max(t4.s1)+1 from t3 as t4| + +call bug7992_1()| +call bug7992_1()| +call bug7992_2()| +call bug7992_2()| + +drop procedure bug7992_1| +drop procedure bug7992_2| +drop table t3| + +# +# BUG#8116: calling simple stored procedure twice in a row results +# in server crash +# +create table t3 ( userid bigint(20) not null default 0 )| + +--disable_warnings ONCE +drop procedure if exists bug8116| +create procedure bug8116(in _userid int) + select * from t3 where userid = _userid| + +call bug8116(42)| +call bug8116(42)| +drop procedure bug8116| +drop table t3| + +# +# BUG#6857: current_time() in STORED PROCEDURES +# +--disable_warnings +drop procedure if exists bug6857| +--enable_warnings +create procedure bug6857() +begin + declare t0, t1 int; + declare plus bool default 0; + set t0 = unix_timestamp(); + select sleep(1.1); + set t1 = unix_timestamp(); + if t1 > t0 then + set plus = 1; + end if; + select plus; +end| + +call bug6857()| + +drop procedure bug6857| + +# +# BUG#8757: Stored Procedures: Scope of Begin and End Statements do not +# work properly. +--disable_warnings ONCE +drop procedure if exists bug8757| +create procedure bug8757() +begin + declare x int; + declare c1 cursor for select data from t1 limit 1; + + begin + declare y int; + declare c2 cursor for select i from t2 limit 1; + + open c2; + fetch c2 into y; + close c2; + select 2,y; + end; + open c1; + fetch c1 into x; + close c1; + select 1,x; +end| + +delete from t1| +delete from t2| +insert into t1 values ("x", 1)| +insert into t2 values ("y", 2, 0.0)| + +call bug8757()| + +delete from t1| +delete from t2| +drop procedure bug8757| + + +# +# BUG#8762: Stored Procedures: Inconsistent behavior +# of DROP PROCEDURE IF EXISTS statement. +--disable_warnings ONCE +drop procedure if exists bug8762| +# Doesn't exist +drop procedure if exists bug8762| create procedure bug8762() begin end| +# Does exist +drop procedure if exists bug8762| create procedure bug8762() begin end| +drop procedure bug8762| + + +# +# BUG#5240: Stored procedure crash if function has cursor declaration +# +--disable_warnings ONCE +drop function if exists bug5240| +create function bug5240 () returns int +begin + declare x int; + declare c cursor for select data from t1 limit 1; + + open c; + fetch c into x; + close c; + return x; +end| + +delete from t1| +insert into t1 values ("answer", 42)| +select id, bug5240() from t1| +drop function bug5240| + +# +# BUG#7992: rolling back temporary Item tree changes in SP +# +--disable_warnings ONCE +drop procedure if exists p1| +create table t3(id int)| +insert into t3 values(1)| +create procedure bug7992() +begin + declare i int; + select max(id)+1 from t3 into i; +end| + +call bug7992()| +call bug7992()| +drop procedure bug7992| +drop table t3| +delimiter ;| + +# +# BUG#8849: problem with insert statement with table alias's +# +# Rolling back changes to AND/OR structure of ON and WHERE clauses in SP +# + +delimiter |; +--disable_warnings ONCE +drop table if exists t3;| +create table t3 ( + lpitnumber int(11) default null, + lrecordtype int(11) default null +)| + +--disable_warnings ONCE +drop table if exists t4;| +create table t4 ( + lbsiid int(11) not null default '0', + ltradingmodeid int(11) not null default '0', + ltradingareaid int(11) not null default '0', + csellingprice decimal(19,4) default null, + primary key (lbsiid,ltradingmodeid,ltradingareaid) +)| + +--disable_warnings ONCE +drop table if exists t5;| +create table t5 ( + lbsiid int(11) not null default '0', + ltradingareaid int(11) not null default '0', + primary key (lbsiid,ltradingareaid) +)| + +--disable_warnings ONCE +drop procedure if exists bug8849| +create procedure bug8849() +begin + insert into t5 + ( + t5.lbsiid, + t5.ltradingareaid + ) + select distinct t3.lpitnumber, t4.ltradingareaid + from + t4 join t3 on + t3.lpitnumber = t4.lbsiid + and t3.lrecordtype = 1 + left join t4 as price01 on + price01.lbsiid = t4.lbsiid and + price01.ltradingmodeid = 1 and + t4.ltradingareaid = price01.ltradingareaid; +end| + +call bug8849()| +call bug8849()| +call bug8849()| +drop procedure bug8849| +drop tables t3,t4,t5| + +# +# BUG#8937: Stored Procedure: AVG() works as SUM() in SELECT ... INTO statement +# +--disable_warnings ONCE +drop procedure if exists bug8937| +create procedure bug8937() +begin + declare s,x,y,z int; + declare a float; + + select sum(data),avg(data),min(data),max(data) from t1 into s,x,y,z; + select s,x,y,z; + select avg(data) from t1 into a; + select a; +end| + +delete from t1| +insert into t1 (data) values (1), (2), (3), (4), (6)| +call bug8937()| + +drop procedure bug8937| +delete from t1| + + +# +# BUG#6900: Stored procedure inner handler ignored +# BUG#9074: STORED PROC: The scope of every handler declared is not +# properly applied +# +--disable_warnings +drop procedure if exists bug6900| +drop procedure if exists bug9074| +drop procedure if exists bug6900_9074| +--enable_warnings + +create table t3 (w char unique, x char)| +insert into t3 values ('a', 'b')| + +create procedure bug6900() +begin + declare exit handler for sqlexception select '1'; + + begin + declare exit handler for sqlexception select '2'; + + insert into t3 values ('x', 'y', 'z'); + end; +end| + +create procedure bug9074() +begin + declare x1, x2, x3, x4, x5, x6 int default 0; + + begin + declare continue handler for sqlstate '23000' set x5 = 1; + + insert into t3 values ('a', 'b'); + set x6 = 1; + end; + + begin1_label: + begin + declare continue handler for sqlstate '23000' set x1 = 1; + + insert into t3 values ('a', 'b'); + set x2 = 1; + + begin2_label: + begin + declare exit handler for sqlstate '23000' set x3 = 1; + + set x4= 1; + insert into t3 values ('a','b'); + set x4= 0; + end begin2_label; + end begin1_label; + + select x1, x2, x3, x4, x5, x6; +end| + +create procedure bug6900_9074(z int) +begin + declare exit handler for sqlstate '23000' select '23000'; + + begin + declare exit handler for sqlexception select 'sqlexception'; + + if z = 1 then + insert into t3 values ('a', 'b'); + else + insert into t3 values ('x', 'y', 'z'); + end if; + end; +end| + +call bug6900()| +call bug9074()| +call bug6900_9074(0)| +call bug6900_9074(1)| + +drop procedure bug6900| +drop procedure bug9074| +drop procedure bug6900_9074| +drop table t3| + + +# +# BUG#7185: Stored procedure crash if identifier is AVG +# +--disable_warnings ONCE +drop procedure if exists avg| +create procedure avg () +begin +end| + +call avg ()| +drop procedure avg| + + +# +# BUG#6129: Stored procedure won't display @@sql_mode value +# +--disable_warnings ONCE +drop procedure if exists bug6129| +set @old_mode= @@sql_mode| +set @@sql_mode= "ONLY_FULL_GROUP_BY"| +create procedure bug6129() + select @@sql_mode| +call bug6129()| +set @@sql_mode= "PAD_CHAR_TO_FULL_LENGTH,PIPES_AS_CONCAT,ONLY_FULL_GROUP_BY"| +call bug6129()| +set @@sql_mode= "PIPES_AS_CONCAT"| +call bug6129()| +set @@sql_mode=@old_mode; + +drop procedure bug6129| + + +# +# BUG#9856: Stored procedures: crash if handler for sqlexception, not found +# +--disable_warnings ONCE +drop procedure if exists bug9856| +create procedure bug9856() +begin + declare v int; + declare c cursor for select data from t1; + declare exit handler for sqlexception, not found select '16'; + + open c; + fetch c into v; + select v; +end| + +delete from t1| +call bug9856()| +call bug9856()| +drop procedure bug9856| + + +# +# BUG##9674: Stored Procs: Using declared vars in algebric operation causes +# system crash. +# +--disable_warnings +drop procedure if exists bug9674_1| +drop procedure if exists bug9674_2| +--enable_warnings +create procedure bug9674_1(out arg int) +begin + declare temp_in1 int default 0; + declare temp_fl1 int default 0; + + set temp_in1 = 100; + set temp_fl1 = temp_in1/10; + set arg = temp_fl1; +end| + +create procedure bug9674_2() +begin + declare v int default 100; + + select v/10; +end| + +call bug9674_1(@sptmp)| +call bug9674_1(@sptmp)| +select @sptmp| +call bug9674_2()| +call bug9674_2()| +drop procedure bug9674_1| +drop procedure bug9674_2| + + +# +# BUG#9598: stored procedure call within stored procedure overwrites IN variable +# +--disable_warnings +drop procedure if exists bug9598_1| +drop procedure if exists bug9598_2| +--enable_warnings +create procedure bug9598_1(in var_1 char(16), + out var_2 integer, out var_3 integer) +begin + set var_2 = 50; + set var_3 = 60; +end| + +create procedure bug9598_2(in v1 char(16), + in v2 integer, + in v3 integer, + in v4 integer, + in v5 integer) +begin + select v1,v2,v3,v4,v5; + call bug9598_1(v1,@tmp1,@tmp2); + select v1,v2,v3,v4,v5; +end| + +call bug9598_2('Test',2,3,4,5)| +select @tmp1, @tmp2| + +drop procedure bug9598_1| +drop procedure bug9598_2| + + +# +# BUG#9902: Crash with simple stored function using user defined variables +# +--disable_warnings ONCE +drop procedure if exists bug9902| +create function bug9902() returns int(11) +begin + set @x = @x + 1; + return @x; +end| + +set @qcs1 = @@query_cache_size| +set global query_cache_size = 102400| +set @x = 1| +insert into t1 values ("qc", 42)| +#select bug9902() from t1| +#select bug9902() from t1| +#select @x| + +set global query_cache_size = @qcs1| +delete from t1| +drop function bug9902| + + +# +# BUG#9102: Stored proccedures: function which returns blob causes crash +# +--disable_warnings ONCE +drop function if exists bug9102| +create function bug9102() returns blob return 'a'| +--disable_warnings ONCE +drop function if exists bug9102| +create function bug9102() returns varchar(1024) return 'a'| +select bug9102()| +drop function bug9102| + + +# +# BUG#7648: Stored procedure crash when invoking a function that returns a bit +# +--disable_warnings ONCE +drop function if exists bug7648| +create function bug7648() returns bit(8) return 'a'| +select bug7648()| +drop function bug7648| + + +# +# BUG#9775: crash if create function that returns enum or set +# +--disable_warnings ONCE +drop function if exists bug9775| +create function bug9775(v1 char(1)) returns enum('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('c')| +drop function bug9775| +create function bug9775(v1 int) returns enum('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3)| +drop function bug9775| + +create function bug9775(v1 char(1)) returns set('a','b') return v1| +select bug9775('a'),bug9775('b'),bug9775('a,b'),bug9775('c')| +drop function bug9775| +create function bug9775(v1 int) returns set('a','b') return v1| +select bug9775(1),bug9775(2),bug9775(3),bug9775(4)| +drop function bug9775| + + +# +# BUG#8861: If Return is a YEAR data type, value is not shown in year format +# +--disable_warnings ONCE +drop function if exists bug8861| +create function bug8861(v1 int) returns year return v1| +select bug8861(05)| +set @x = bug8861(05)| +select @x| +drop function bug8861| + + +# +# BUG#9004: Inconsistent behaviour of SP re. warnings +# +--disable_warnings +drop procedure if exists bug9004_1| +drop procedure if exists bug9004_2| +--enable_warnings +create procedure bug9004_1(x char(16)) +begin + insert into t1 values (x, 42); + insert into t1 values (x, 17); +end| +create procedure bug9004_2(x char(16)) + call bug9004_1(x)| + +# Truncation warnings expected... +call bug9004_1('12345678901234567')| +call bug9004_2('12345678901234567890')| + +delete from t1| +drop procedure bug9004_1| +drop procedure bug9004_2| + +# +# BUG#7293: Stored procedure crash with soundex +# +--disable_warnings ONCE +drop procedure if exists bug7293| +insert into t1 values ('secret', 0)| +create procedure bug7293(p1 varchar(100)) +begin + if exists (select id from t1 where soundex(p1)=soundex(id)) then + select 'yes'; + end if; +end;| + +call bug7293('secret')| +call bug7293 ('secrete')| +drop procedure bug7293| +delete from t1| + + +# +# BUG#9841: Unexpected read lock when trying to update a view in a +# stored procedure +# +--disable_warnings +drop procedure if exists bug9841| +drop view if exists v1| +--enable_warnings + +create view v1 as select * from t1, t2 where id = s| +create procedure bug9841 () + update v1 set data = 10| +call bug9841()| + +drop view v1| +drop procedure bug9841| + + +# +# BUG#5963 subqueries in SET/IF +# +--disable_warnings ONCE +drop procedure if exists bug5963_1| +drop procedure if exists bug5963_2| +--enable_warnings +create procedure bug5963_1 () begin declare v int; set v = (select s1 from t3); select v; end;| +create table t3 (s1 int)| +insert into t3 values (5)| + +call bug5963_1()| +call bug5963_1()| +drop procedure bug5963_1| +drop table t3| + + +create procedure bug5963_2 (cfk_value int) +begin + if cfk_value in (select cpk from t3) then + set @x = 5; + end if; + end; +| +create table t3 (cpk int)| +insert into t3 values (1)| + +call bug5963_2(1)| +call bug5963_2(1)| +drop procedure bug5963_2| +drop table t3| + + +# +# BUG#9559: Functions: Numeric Operations using -ve value gives incorrect +# results. +# +--disable_warnings ONCE +drop function if exists bug9559| +create function bug9559() + returns int +begin + set @y = -6/2; + return @y; +end| + +select bug9559()| + +drop function bug9559| + + +# +# BUG#10961: Stored procedures: crash if select * from dual +# +--disable_warnings ONCE +drop procedure if exists bug10961| +# "select * from dual" results in an error, so the cursor will not open +create procedure bug10961() +begin + declare v char; + declare x int; + declare c cursor for select * from dual; + declare continue handler for sqlexception select x; + + set x = 1; + open c; + set x = 2; + fetch c into v; + set x = 3; + close c; +end| + +call bug10961()| +call bug10961()| + +drop procedure bug10961| + +# +# BUG #6866: Second call of a stored procedure using a view with on expressions +# + +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS bug6866| + +--disable_warnings ONCE +DROP VIEW IF EXISTS tv| +DROP TABLE IF EXISTS tt1,tt2,tt3| + +CREATE TABLE tt1 (a1 int, a2 int, a3 int, data varchar(10))| +CREATE TABLE tt2 (a2 int, data2 varchar(10))| +CREATE TABLE tt3 (a3 int, data3 varchar(10))| + +INSERT INTO tt1 VALUES (1, 1, 4, 'xx')| + +INSERT INTO tt2 VALUES (1, 'a')| +INSERT INTO tt2 VALUES (2, 'b')| +INSERT INTO tt2 VALUES (3, 'c')| + +INSERT INTO tt3 VALUES (4, 'd')| +INSERT INTO tt3 VALUES (5, 'e')| +INSERT INTO tt3 VALUES (6, 'f')| + +CREATE VIEW tv AS +SELECT tt1.*, tt2.data2, tt3.data3 + FROM tt1 INNER JOIN tt2 ON tt1.a2 = tt2.a2 + LEFT JOIN tt3 ON tt1.a3 = tt3.a3 + ORDER BY tt1.a1, tt2.a2, tt3.a3| + +CREATE PROCEDURE bug6866 (_a1 int) +BEGIN +SELECT * FROM tv WHERE a1 = _a1; +END| + +CALL bug6866(1)| +CALL bug6866(1)| +CALL bug6866(1)| + +DROP PROCEDURE bug6866; + +DROP VIEW tv| +DROP TABLE tt1, tt2, tt3| + +# +# BUG#10136: items cleunup +# +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS bug10136| +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin + declare done int default 3; + + repeat + select * from t3; + set done = done - 1; + until done <= 0 end repeat; + +end| +call bug10136()| +call bug10136()| +call bug10136()| +drop procedure bug10136| +drop table t3| + +# +# BUG#11529: crash server after use stored procedure +# +--disable_warnings ONCE +drop procedure if exists bug11529| +create procedure bug11529() +begin + declare c cursor for select id, data from t1 where data in (10,13); + + open c; + begin + declare vid char(16); + declare vdata int; + declare exit handler for not found begin end; + + while true do + fetch c into vid, vdata; + end while; + end; + close c; +end| + +insert into t1 values + ('Name1', 10), + ('Name2', 11), + ('Name3', 12), + ('Name4', 13), + ('Name5', 14)| + +call bug11529()| +call bug11529()| +delete from t1| +drop procedure bug11529| + + +# +# BUG#6063: Stored procedure labels are subject to restrictions (partial) +# BUG#7088: Stored procedures: labels won't work if character set is utf8 +# + +set character set utf8| + +--disable_warnings +drop procedure if exists bug6063| +drop procedure if exists bug7088_1| +drop procedure if exists bug7088_2| +--enable_warnings + +create procedure bug6063() +begin + lâbel: begin end; + label: begin end; + label1: begin end; +end| + +create procedure bug7088_1() + label1: begin end label1| + +create procedure bug7088_2() + läbel1: begin end| + +call bug6063()| +call bug7088_1()| +call bug7088_2()| + +set character set default| + +show create procedure bug6063| +show create procedure bug7088_1| +show create procedure bug7088_2| + +drop procedure bug6063| +drop procedure bug7088_1| +drop procedure bug7088_2| + +# +# BUG#9565: "Wrong locking in stored procedure if a sub-sequent procedure +# is called". +# +--disable_warnings +drop procedure if exists bug9565_sub| +drop procedure if exists bug9565| +--enable_warnings +create procedure bug9565_sub() +begin + select * from t1; +end| +create procedure bug9565() +begin + insert into t1 values ("one", 1); + call bug9565_sub(); +end| +call bug9565()| +delete from t1| +drop procedure bug9565_sub| +drop procedure bug9565| + + +# +# BUG#9538: SProc: Creation fails if we try to SET system variable +# using @@var_name in proc +# +--disable_warnings ONCE +drop procedure if exists bug9538| +create procedure bug9538() + set @@ob_bnl_join_cache_size = 1000000| + +set @x = @@ob_bnl_join_cache_size| +set @@ob_bnl_join_cache_size = 2000000| +select @@ob_bnl_join_cache_size| +call bug9538()| +select @@ob_bnl_join_cache_size| +set @@ob_bnl_join_cache_size = @x| + +drop procedure bug9538| + + +# +# BUG#8692: Cursor fetch of empty string +# +--disable_warnings ONCE +drop procedure if exists bug8692| +create table t3 (c1 varchar(5), c2 char(5), c3 enum('one','two'), c4 text, c5 blob, c6 char(5), c7 varchar(5))| +insert into t3 values ('', '', '', '', '', '', NULL)| + +create procedure bug8692() +begin + declare v1 VARCHAR(10); + declare v2 VARCHAR(10); + declare v3 VARCHAR(10); + declare v4 VARCHAR(10); + declare v5 VARCHAR(10); + declare v6 VARCHAR(10); + declare v7 VARCHAR(10); + declare c8692 cursor for select c1,c2,c3,c4,c5,c6,c7 from t3; + open c8692; + fetch c8692 into v1,v2,v3,v4,v5,v6,v7; + select v1, v2, v3, v4, v5, v6, v7; +end| + +call bug8692()| +drop procedure bug8692| +drop table t3| + +# +# Bug#10055 "Using stored function with information_schema causes empty +# result set" +# +--disable_warnings ONCE +drop function if exists bug10055| +create function bug10055(v char(255)) returns char(255) return lower(v)| +# This select should not crash server and should return all fields in t1 +select t.column_name, bug10055(t.column_name) +from information_schema.columns as t +where t.table_schema = 'test' and t.table_name = 't1'| +drop function bug10055| + +# +# Bug #12297 "SP crashes the server if data inserted inside a lon loop" +# The test for memleak bug, so actually there is no way to test it +# from the suite. The test below could be used to check SP memory +# consumption by passing large input parameter. +# + +--disable_warnings ONCE +drop procedure if exists bug12297| + +create procedure bug12297(lim int) +begin + set @x = 0; + repeat + insert into t1(id,data) + values('aa', @x); + set @x = @x + 1; + until @x >= lim + end repeat; +end| + +call bug12297(10)| +drop procedure bug12297| + +# +# Bug #11247 "Stored procedures: Function calls in long loops leak memory" +# One more memleak bug test. One could use this test to check that the memory +# isn't leaking by increasing the input value for p_bug11247. +# + +--disable_warnings +drop function if exists f_bug11247| +drop procedure if exists p_bug11247| +--enable_warnings + +create function f_bug11247(param int) + returns int +return param + 1| + +create procedure p_bug11247(lim int) +begin + declare v int default 0; + + while v < lim do + set v= f_bug11247(v); + end while; +end| + +call p_bug11247(10)| +drop function f_bug11247| +drop procedure p_bug11247| +# +# BUG#12168: "'DECLARE CONTINUE HANDLER FOR NOT FOUND ...' in conditional +# handled incorrectly" +# +--disable_warnings +drop procedure if exists bug12168| +drop table if exists t3, t4| +--enable_warnings + +create table t3 (a int)| +insert into t3 values (1),(2),(3),(4)| + +create table t4 (a int)| + +create procedure bug12168(arg1 char(1)) +begin + declare b, c integer; + if arg1 = 'a' then + begin + declare c1 cursor for select a from t3 where a % 2; + declare continue handler for not found set b = 1; + set b = 0; + open c1; + c1_repeat: repeat + fetch c1 into c; + if (b = 1) then + leave c1_repeat; + end if; + + insert into t4 values (c); + until b = 1 + end repeat; + end; + end if; + if arg1 = 'b' then + begin + declare c2 cursor for select a from t3 where not a % 2; + declare continue handler for not found set b = 1; + set b = 0; + open c2; + c2_repeat: repeat + fetch c2 into c; + if (b = 1) then + leave c2_repeat; + end if; + + insert into t4 values (c); + until b = 1 + end repeat; + end; + end if; +end| + +call bug12168('a')| +select * from t4| +truncate t4| +call bug12168('b')| +select * from t4| +truncate t4| +call bug12168('a')| +select * from t4| +truncate t4| +call bug12168('b')| +select * from t4| +truncate t4| +drop table t3, t4| +drop procedure if exists bug12168| + +# +# Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO +# query" +# One more memleak bug. Use the test to check memory consumption. +# + +--disable_warnings +drop table if exists t3| +drop procedure if exists bug11333| +--enable_warnings + +create table t3 (c1 char(128))| + +insert into t3 values + ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')| + + +create procedure bug11333(i int) +begin + declare tmp varchar(128); + set @x = 0; + repeat + select c1 from t3 + where c1 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' into tmp; + set @x = @x + 1; + until @x >= i + end repeat; +end| + +call bug11333(10)| + +drop procedure bug11333| +drop table t3| + +# +# BUG#9048: Creating a function with char binary IN parameter fails +# +--disable_warnings ONCE +drop function if exists bug9048| +create function bug9048(f1 char binary) returns char +begin + set f1= concat( 'hello', f1 ); + return f1; +end| +drop function bug9048| +# +# This was disabled in 5.1.12. See bug #20701 +# When collation support in SP is implemented, then this test should +# be removed. +# +create function bug9048(f1 char binary) returns char binary +begin + set f1= concat( 'hello', f1 ); + return f1; +end| +select bug9048('1')| +drop function bug9048| +# Bug #12849 Stored Procedure: Crash on procedure call with CHAR type +# 'INOUT' parameter +# + +--disable_warnings ONCE +drop procedure if exists bug12849_1| +create procedure bug12849_1(inout x char) select x into x| +set @var='a'| +call bug12849_1(@var)| +select @var| +drop procedure bug12849_1| + +--disable_warnings ONCE +drop procedure if exists bug12849_2| +create procedure bug12849_2(inout foo varchar(15)) +begin +select concat(foo, foo) INTO foo; +end| +set @var='abcd'| +call bug12849_2(@var)| +select @var| +drop procedure bug12849_2| + +# +# BUG#13133: Local variables in stored procedures are not initialized correctly. +# +--disable_warnings +drop procedure if exists bug131333| +drop function if exists bug131333| +--enable_warnings +create procedure bug131333() +begin + begin + declare a int; + + select a; + set a = 1; + select a; + end; + begin + declare b int; + + select b; + end; +end| + +create function bug131333() + returns int +begin + begin + declare a int; + + set a = 1; + end; + begin + declare b int; + + return b; + end; +end| + +call bug131333()| +select bug131333()| + +drop procedure bug131333| +drop function bug131333| + +# +# BUG#12379: PROCEDURE with HANDLER calling FUNCTION with error get +# strange result +# +--disable_warnings +drop function if exists bug12379| +drop procedure if exists bug12379_1| +drop procedure if exists bug12379_2| +drop procedure if exists bug12379_3| +drop table if exists t3| +--enable_warnings + +create table t3 (c1 char(1) primary key not null)| + +create function bug12379() + returns integer +begin + insert into t3 values('X'); + insert into t3 values('X'); + return 0; +end| + +create procedure bug12379_1() +begin + declare exit handler for sqlexception select 42; + + select bug12379(); +END| +create procedure bug12379_2() +begin + declare exit handler for sqlexception begin end; + + select bug12379(); +end| +create procedure bug12379_3() +begin + select bug12379(); +end| + +--error ER_DUP_ENTRY,1235 +select bug12379()| +select 1| +# statement-based binlogging will show warning which row-based won't; +# so we hide it (this warning is already tested in rpl_stm_sp.test) +--disable_warnings +call bug12379_1()| +select 2| +call bug12379_2()| +--enable_warnings +select 3| +--error ER_DUP_ENTRY,4016,1235 +call bug12379_3()| +select 4| + +drop function bug12379| +drop procedure bug12379_1| +drop procedure bug12379_2| +drop procedure bug12379_3| +drop table t3| + +# +# Bug #13124 Stored Procedure using SELECT INTO crashes server +# + +--disable_warnings ONCE +drop procedure if exists bug13124| +create procedure bug13124() +begin + declare y integer; + set @x=y; +end| +call bug13124()| +drop procedure bug13124| + +# +# Bug #12979 Stored procedures: crash if inout decimal parameter +# + +# check NULL inout parameters processing + +--disable_warnings ONCE +drop procedure if exists bug12979_1| +create procedure bug12979_1(inout d decimal(5)) set d = d / 2| +set @bug12979_user_var = NULL| +call bug12979_1(@bug12979_user_var)| +drop procedure bug12979_1| + +# check NULL local variables processing + +--disable_warnings ONCE +drop procedure if exists bug12979_2| +create procedure bug12979_2() +begin +declare internal_var decimal(5); +set internal_var= internal_var / 2; +select internal_var; +end| +call bug12979_2()| +drop procedure bug12979_2| + + +# +# BUG#6127: Stored procedure handlers within handlers don't work +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug6127| +--enable_warnings +create table t3 (s1 int unique)| + +set @sm=@@sql_mode| +--error 1235 +set sql_mode='traditional'| + +create procedure bug6127() +begin + declare continue handler for sqlstate '23000' + begin + declare continue handler for sqlstate '22003' + insert into t3 values (0); + + insert into t3 values (1000000000000000); + end; + + insert into t3 values (1); + insert into t3 values (1); +end| + +call bug6127()| +select * from t3| +--error ER_DUP_ENTRY +call bug6127()| +select * from t3| +set sql_mode=@sm| +drop table t3| +drop procedure bug6127| + + +# +# BUG#12589: Assert when creating temp. table from decimal stored procedure +# variable +# +--disable_warnings +drop procedure if exists bug12589_1| +drop procedure if exists bug12589_2| +drop procedure if exists bug12589_3| +--enable_warnings + +create procedure bug12589_1() +begin + declare spv1 decimal(3,3); + set spv1= 123.456; + + set spv1 = 'test'; + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +create procedure bug12589_2() +begin + declare spv1 decimal(6,3); + set spv1= 123.456; + + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +create procedure bug12589_3() +begin + declare spv1 decimal(6,3); + set spv1= -123.456; + + create temporary table tm1 as select spv1; + show create table tm1; + drop temporary table tm1; +end| + +# Note: The type of the field will match the value, not the declared +# type of the variable. (This is a type checking issue which +# might be changed later.) + +# Warning expected from "set spv1 = 'test'", the value is set to decimal "0". +call bug12589_1()| +# No warnings here +call bug12589_2()| +call bug12589_3()| + +drop procedure bug12589_1| +drop procedure bug12589_2| +drop procedure bug12589_3| + +# +# BUG#7049: Stored procedure CALL errors are ignored +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug7049_1| +drop procedure if exists bug7049_2| +drop procedure if exists bug7049_3| +drop procedure if exists bug7049_4| +drop function if exists bug7049_1| +drop function if exists bug7049_2| +--enable_warnings + +create table t3 ( x int unique )| + +create procedure bug7049_1() +begin + insert into t3 values (42); + insert into t3 values (42); +end| + +create procedure bug7049_2() +begin + declare exit handler for sqlexception + select 'Caught it' as 'Result'; + + call bug7049_1(); + select 'Missed it' as 'Result'; +end| + +create procedure bug7049_3() + call bug7049_1()| + +create procedure bug7049_4() +begin + declare exit handler for sqlexception + select 'Caught it' as 'Result'; + + call bug7049_3(); + select 'Missed it' as 'Result'; +end| + +create function bug7049_1() + returns int +begin + insert into t3 values (42); + insert into t3 values (42); + return 42; +end| + +create function bug7049_2() + returns int +begin + declare x int default 0; + declare continue handler for sqlexception + set x = 1; + + set x = bug7049_1(); + return x; +end| + +call bug7049_2()| +select * from t3| +delete from t3| +call bug7049_4()| +select * from t3| +select bug7049_2()| + +drop table t3| +drop procedure bug7049_1| +drop procedure bug7049_2| +drop procedure bug7049_3| +drop procedure bug7049_4| +drop function bug7049_1| +drop function bug7049_2| + + +# +# BUG#13941: replace() string fuction behaves badly inside stored procedure +# (BUG#13914: IFNULL is returning garbage in stored procedure) +# +--disable_warnings +drop function if exists bug13941| +drop procedure if exists bug13941| +--enable_warnings + +create function bug13941(p_input_str varchar(1024)) + returns varchar(1024) +begin + declare p_output_str varchar(1024); + + set p_output_str = p_input_str; + + set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); + set p_output_str = replace(p_output_str, 'test', 'prova'); + set p_output_str = replace(p_output_str, 'this', 'questo'); + set p_output_str = replace(p_output_str, ' a ', 'una '); + set p_output_str = replace(p_output_str, 'is', ''); + + return p_output_str; +end| + +create procedure bug13941(out sout varchar(128)) +begin + set sout = 'Local'; + set sout = ifnull(sout, 'DEF'); +end| + +# Note: The bug showed different behaviour in different types of builds, +# giving garbage results in some, and seemingly working in others. +# Running with valgrind (or purify) is the safe way to check that it's +# really working correctly. +select bug13941('this is a test')| +call bug13941(@a)| +select @a| + +drop function bug13941| +drop procedure bug13941| + + +# +# BUG#13095: Cannot create VIEWs in prepared statements +# + +delimiter ;| + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13095; +DROP TABLE IF EXISTS bug13095_t1; +DROP VIEW IF EXISTS bug13095_v1; +--enable_warnings + +delimiter |; + +CREATE PROCEDURE bug13095(tbl_name varchar(32)) +BEGIN + SET @str = + CONCAT("CREATE TABLE ", tbl_name, "(stuff char(15))"); + SELECT @str; + PREPARE stmt1 FROM @str; + EXECUTE stmt1; + + SET @str = + CONCAT("INSERT INTO ", tbl_name, " VALUES('row1'),('row2'),('row3')" ); + SELECT @str; + PREPARE stmt2 FROM @str; + EXECUTE stmt2; + + SET @str = + CONCAT("CREATE VIEW bug13095_v1(c1) AS SELECT stuff FROM ", tbl_name); + SELECT @str; + PREPARE stmt3 FROM @str; + EXECUTE stmt3; + + SELECT * FROM bug13095_v1; + + SET @str = + "DROP VIEW bug13095_v1"; + SELECT @str; + PREPARE stmt4 FROM @str; + EXECUTE stmt4; +END| + +delimiter ;| + +--error 0,1146,1050,4038 +CALL bug13095('bug13095_t1'); + +--disable_warnings +DROP PROCEDURE IF EXISTS bug13095; +DROP VIEW IF EXISTS bug13095_v1; +DROP TABLE IF EXISTS bug13095_t1; +--enable_warnings + +delimiter |; + +# +# Bug#14845 "mysql_stmt_fetch returns MYSQL_NO_DATA when COUNT(*) is 0" +# Check that when fetching from a cursor, COUNT(*) works properly. +# +create procedure bug14845() +begin + declare a char(255); + declare done int default 0; + declare c cursor for select count(*) from t1 where 1 = 0; + declare continue handler for sqlstate '02000' set done = 1; + open c; + repeat + fetch c into a; + if not done then + select a; + end if; + until done end repeat; + close c; +end| +call bug14845()| +drop procedure bug14845| + +# +# BUG#13549 "Server crash with nested stored procedures". +# Server should not crash when during execution of stored procedure +# we have to parse trigger/function definition and this new trigger/ +# function has more local variables declared than invoking stored +# procedure and last of these variables is used in argument of NOT +# operator. +# +--disable_warnings +drop procedure if exists bug13549_1| +drop procedure if exists bug13549_2| +--enable_warnings +CREATE PROCEDURE `bug13549_2`() +begin + call bug13549_1(); +end| +CREATE PROCEDURE `bug13549_1`() +begin + declare done int default 0; + set done= not done; +end| +CALL bug13549_2()| +drop procedure bug13549_2| +drop procedure bug13549_1| + +# +# BUG#10100: function (and stored procedure?) recursivity problem +# +--disable_warnings +drop function if exists bug10100f| +drop procedure if exists bug10100p| +drop procedure if exists bug10100t| +drop procedure if exists bug10100pt| +drop procedure if exists bug10100pv| +drop procedure if exists bug10100pd| +drop procedure if exists bug10100pc| +--enable_warnings +# routines with simple recursion +create function bug10100f(prm int) returns int +begin + if prm > 1 then + return prm * bug10100f(prm - 1); + end if; + return 1; +end| +create procedure bug10100p(prm int, inout res int) +begin + set res = res * prm; + if prm > 1 then + call bug10100p(prm - 1, res); + end if; +end| +create procedure bug10100t(prm int) +begin + declare res int; + set res = 1; + call bug10100p(prm, res); + select res; +end| + +# a procedure which use tables and recursion +create table t3 (a int)| +insert into t3 values (0)| +create view v1 as select a from t3| +--error 1064 +create procedure bug10100pt(level int, lim int) +begin + if level < lim then + update t3 set a=level; + FLUSH TABLES; + call bug10100pt(level+1, lim); + else + select * from t3; + end if; +end| +# view & recursion +--error 1064 +create procedure bug10100pv(level int, lim int) +begin + if level < lim then + update v1 set a=level; + FLUSH TABLES; + call bug10100pv(level+1, lim); + else + select * from v1; + end if; +end| +# dynamic sql & recursion +prepare stmt2 from "select * from t3;"| +--error 1064 +create procedure bug10100pd(level int, lim int) +begin + if level < lim then + select level; + prepare stmt1 from "update t3 set a=a+2"; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + execute stmt1; + FLUSH TABLES; + deallocate prepare stmt1; + execute stmt2; + select * from t3; + call bug10100pd(level+1, lim); + else + execute stmt2; + end if; +end| +# cursor & recursion +--error 1064 +create procedure bug10100pc(level int, lim int) +begin + declare lv int; + declare c cursor for select a from t3; + open c; + if level < lim then + select level; + fetch c into lv; + select lv; + update t3 set a=level+lv; + FLUSH TABLES; + call bug10100pc(level+1, lim); + else + select * from t3; + end if; + close c; +end| + +set @@max_sp_recursion_depth=4| +select @@max_sp_recursion_depth| +-- error ER_SP_NO_RECURSION +select bug10100f(3)| +-- error ER_SP_NO_RECURSION +select bug10100f(6)| +call bug10100t(5)| +--error 1305 +call bug10100pt(1,5)| +--error 1305 +call bug10100pv(1,5)| +update t3 set a=1| +--error 1305 +call bug10100pd(1,5)| +select * from t3| +update t3 set a=1| +--error 1305 +call bug10100pc(1,5)| +select * from t3| +set @@max_sp_recursion_depth=0| +select @@max_sp_recursion_depth| +-- error ER_SP_NO_RECURSION +select bug10100f(5)| +-- error ER_SP_RECURSION_LIMIT +call bug10100t(5)| + +#end of the stack checking +deallocate prepare stmt2| + +drop function bug10100f| +drop procedure bug10100p| +drop procedure bug10100t| +--error 1305 +drop procedure bug10100pt| +--error 1305 +drop procedure bug10100pv| +--error 1305 +drop procedure bug10100pd| +--error 1305 +drop procedure bug10100pc| +drop view v1| + +# +# BUG#13729: Stored procedures: packet error after exception handled +# +--disable_warnings +drop procedure if exists bug13729| +drop table if exists t3| +--enable_warnings + +create table t3 (s1 int, primary key (s1))| + +insert into t3 values (1),(2)| + +create procedure bug13729() +begin + declare continue handler for sqlexception select 55; + + update t3 set s1 = 1; +end| + +call bug13729()| +# Used to cause Packets out of order +select * from t3| + +drop procedure bug13729| +drop table t3| + +# +# BUG#14643: Stored Procedure: Continuing after failed var. initialization +# crashes server. +# +--disable_warnings +drop procedure if exists bug14643_1| +drop procedure if exists bug14643_2| +--enable_warnings + +--error 1327 +create procedure bug14643_1() +begin + declare continue handler for sqlexception select 'boo' as 'Handler'; + + begin + declare v int default undefined_var; + + if v = 1 then + select 1; + else + select v, isnull(v); + end if; + end; +end| + +--error 1327 +create procedure bug14643_2() +begin + declare continue handler for sqlexception select 'boo' as 'Handler'; + + case undefined_var + when 1 then + select 1; + else + select 2; + end case; + + select undefined_var; +end| + + +# +# BUG#14304: auto_increment field incorrect set in SP +# +--disable_warnings +drop procedure if exists bug14304| +drop table if exists t3, t4| +--enable_warnings + +create table t3(a int primary key auto_increment)| +create table t4(a int primary key auto_increment)| + +create procedure bug14304() +begin + insert into t3 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 set a=null; + insert into t4 select null as a; + + insert into t3 set a=null; + insert into t3 set a=null; + + select * from t3; +end| + +call bug14304()| + +drop procedure bug14304| +drop table t3, t4| + +# +# BUG#14376: MySQL crash on scoped variable (re)initialization +# +--disable_warnings ONCE +drop procedure if exists bug14376| + +--error 1327 +create procedure bug14376() +begin + declare x int default x; +end| + +create procedure bug14376() +begin + declare x int default 42; + + begin + declare x int default x; + + select x; + end; +end| + +call bug14376()| + +drop procedure bug14376| + +create procedure bug14376(x int) +begin + declare x int default x; + + select x; +end| + +call bug14376(4711)| + +drop procedure bug14376| + +# +# Bug#5967 "Stored procedure declared variable used instead of column" +# The bug should be fixed later. +# Test precedence of names of parameters, variable declarations, +# variable declarations in nested compound statements, table columns, +# table columns in cursor declarations. +# According to the standard, table columns take precedence over +# variable declarations. In MySQL 5.0 it's vice versa. +# + +--disable_warnings +drop procedure if exists bug5967| +drop table if exists t3| +--enable_warnings +create table t3 (a varchar(255))| +insert into t3 (a) values ("a - table column")| +create procedure bug5967(a varchar(255)) +begin + declare i varchar(255); + declare c cursor for select a from t3; + select a; + select a from t3 into i; + select i as 'Parameter takes precedence over table column'; open c; + fetch c into i; + close c; + select i as 'Parameter takes precedence over table column in cursors'; + begin + declare a varchar(255) default 'a - local variable'; + declare c1 cursor for select a from t3; + select a as 'A local variable takes precedence over parameter'; + open c1; + fetch c1 into i; + close c1; + select i as 'A local variable takes precedence over parameter in cursors'; + begin + declare a varchar(255) default 'a - local variable in a nested compound statement'; + declare c2 cursor for select a from t3; + select a as 'A local variable in a nested compound statement takes precedence over a local variable in the outer statement'; + select a from t3 into i; + select i as 'A local variable in a nested compound statement takes precedence over table column'; + open c2; + fetch c2 into i; + close c2; + select i as 'A local variable in a nested compound statement takes precedence over table column in cursors'; + end; + end; +end| +call bug5967("a - stored procedure parameter")| +drop procedure bug5967| + +# +# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server" +# +--let $backupdir = /home/linlin.xll/tmp/ +--error 0,1 +--remove_file $backupdir/t1.frm +--error 0,1 +--remove_file $backupdir/t1.MYD + +--disable_warnings +drop procedure if exists bug13012| +# Disable warnings also for BACKUP/RESTORE: they are deprecated. +--error 1064 +eval create procedure bug13012() + BEGIN + REPAIR TABLE t1; + END| +--error 1305 +call bug13012()| + +--enable_warnings + +--error 1305 +drop procedure bug13012| + +create view v1 as select * from t1| +--error 1064 +create procedure bug13012() +BEGIN + REPAIR TABLE t1,t2,t3,v1; + OPTIMIZE TABLE t1,t2,t3,v1; + ANALYZE TABLE t1,t2,t3,v1; +END| +--error 1305 +call bug13012()| +--error 1305 +call bug13012()| +--error 1305 +call bug13012()| +--error 1305 +drop procedure bug13012| +drop view v1| +select * from t1 order by data| + +# +# A test case for Bug#15392 "Server crashes during prepared statement +# execute": make sure that stored procedure check for error conditions +# properly and do not continue execution if an error has been set. +# +# It's necessary to use several DBs because in the original code +# the successful return of mysql_change_db overrode the error from +# execution. +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +create schema mysqltest1| +create schema mysqltest2| +create schema mysqltest3| +use mysqltest3| + +create procedure mysqltest1.p1 (out prequestid varchar(100)) +begin + call mysqltest2.p2('call mysqltest3.p3(1, 2)'); +end| + +create procedure mysqltest2.p2(in psql varchar(1024)) +begin + declare lsql varchar(1024); + set @lsql= psql; + prepare lstatement from @lsql; + execute lstatement; + deallocate prepare lstatement; +end| + +create procedure mysqltest3.p3(in p1 int) +begin + select p1; +end| + +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +--error ER_SP_WRONG_NO_OF_ARGS +call mysqltest1.p1(@rs)| +drop procedure mysqltest1.p1| +drop procedure mysqltest2.p2| +drop procedure mysqltest3.p3| +drop schema if exists mysqltest1| +drop schema if exists mysqltest2| +drop schema if exists mysqltest3| +use test| + +# +# Bug#15441 "Running SP causes Server to Crash": check that an SP variable +# can not be used in VALUES() function. +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15441| +--enable_warnings +create table t3 (id int not null primary key, county varchar(25))| +insert into t3 (id, county) values (1, 'York')| + +# First check that a stored procedure that refers to a parameter in VALUES() +# function won't parse. + +create procedure bug15441(c varchar(25)) +begin + update t3 set id=2, county=values(c); +end| +--error ER_BAD_FIELD_ERROR +call bug15441('county')| +drop procedure bug15441| + +# Now check the case when there is an ambiguity between column names +# and stored procedure parameters: the parser shall resolve the argument +# of VALUES() function to the column name. + +# It's hard to deduce what county refers to in every case (INSERT statement): +# 1st county refers to the column +# 2nd county refers to the procedure parameter +# 3d and 4th county refers to the column, again, but +# for 4th county it has the value of SP parameter + +# In UPDATE statement, just check that values() function returns NULL for +# non- INSERT...UPDATE statements, as stated in the manual. + +create procedure bug15441(county varchar(25)) +begin + declare c varchar(25) default "hello"; + + insert into t3 (id, county) values (1, county) + on duplicate key update county= values(county); + select * from t3; + + update t3 set id=2, county=values(id); + select * from t3; +end| +call bug15441('Yale')| +drop table t3| +drop procedure bug15441| + +# +# BUG#14498: Stored procedures: hang if undefined variable and exception +# +--disable_warnings +drop procedure if exists bug14498_1| +drop procedure if exists bug14498_2| +drop procedure if exists bug14498_3| +drop procedure if exists bug14498_4| +drop procedure if exists bug14498_5| +--enable_warnings + +--error 1327 +create procedure bug14498_1() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + if v then + select 'yes' as 'v'; + else + select 'no' as 'v'; + end if; + select 'done' as 'End'; +end| + +--error 1327 +create procedure bug14498_2() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + while v do + select 'yes' as 'v'; + end while; + select 'done' as 'End'; +end| + +--error 1327 +create procedure bug14498_3() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + repeat + select 'maybe' as 'v'; + until v end repeat; + select 'done' as 'End'; +end| + +--error 1327 +create procedure bug14498_4() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + case v + when 1 then + select '1' as 'v'; + when 2 then + select '2' as 'v'; + else + select '?' as 'v'; + end case; + select 'done' as 'End'; +end| + +--error 1327 +create procedure bug14498_5() +begin + declare continue handler for sqlexception select 'error' as 'Handler'; + + case + when v = 1 then + select '1' as 'v'; + when v = 2 then + select '2' as 'v'; + else + select '?' as 'v'; + end case; + select 'done' as 'End'; +end| + +# +# BUG#15231: Stored procedure bug with not found condition handler +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15231_1| +drop procedure if exists bug15231_2| +drop procedure if exists bug15231_3| +drop procedure if exists bug15231_4| +drop procedure if exists bug15231_5| +drop procedure if exists bug15231_6| +--enable_warnings + +create table t3 (id int not null)| + +create procedure bug15231_1() +begin + declare xid integer; + declare xdone integer default 0; + declare continue handler for not found set xdone = 1; + + set xid=null; + call bug15231_2(xid); + select xid, xdone; +end| + +create procedure bug15231_2(inout ioid integer) +begin + select "Before NOT FOUND condition is triggered" as '1'; + select id from t3 where id=ioid into ioid; + select "After NOT FOUND condtition is triggered" as '2'; + + if ioid is null then + set ioid=1; + end if; +end| + +create procedure bug15231_3() +begin + declare exit handler for sqlwarning + select 'Caught it (correct)' as 'Result'; + + call bug15231_4(); +end| + +create procedure bug15231_4() +begin + declare x decimal(2,1); + + set x = 'zap'; + select 'Missed it (correct)' as 'Result'; + show warnings; +end| + +create procedure bug15231_5() +begin + declare exit handler for sqlwarning + select 'Caught it (wrong)' as 'Result'; + + call bug15231_6(); +end| + +create procedure bug15231_6() +begin + declare x decimal(2,1); + + set x = 'zap'; + select 'Missed it (correct)' as 'Result'; + select id from t3; +end| + +call bug15231_1()| +call bug15231_3()| +call bug15231_5()| + +drop table t3| +drop procedure bug15231_1| +drop procedure bug15231_2| +drop procedure bug15231_3| +drop procedure bug15231_4| +drop procedure bug15231_5| +drop procedure bug15231_6| + + +# +# BUG#15011: error handler in nested block not activated +# +--disable_warnings ONCE +drop procedure if exists bug15011| + +create table t3 (c1 int primary key)| + +insert into t3 values (1)| + +create procedure bug15011() + deterministic +begin + declare continue handler for 1062 + select 'Outer' as 'Handler'; + + begin + declare continue handler for 1062 + select 'Inner' as 'Handler'; + + insert into t3 values (1); + end; +end| + +call bug15011()| + +drop procedure bug15011| +drop table t3| + + +# +# BUG#17476: Stored procedure not returning data when it is called first +# time per connection +# +--disable_warnings ONCE +drop procedure if exists bug17476| + +create table t3 ( d date )| +insert into t3 values + ( '2005-01-01' ), ( '2005-01-02' ), ( '2005-01-03' ), + ( '2005-01-04' ), ( '2005-02-01' ), ( '2005-02-02' )| + +create procedure bug17476(pDateFormat varchar(10)) + select date_format(t3.d, pDateFormat), count(*) + from t3 + group by date_format(t3.d, pDateFormat)| + +call bug17476('%Y-%m')| +call bug17476('%Y-%m')| + +drop table t3| +drop procedure bug17476| + + +# +# BUG#16887: Cursor causes server segfault +# +--disable_warnings +drop table if exists t3| +drop procedure if exists bug16887| +--enable_warnings + +create table t3 ( c varchar(1) )| + +insert into t3 values + (' '),('.'),(';'),(','),('-'),('_'),('('),(')'),('/'),('\\')| + +create procedure bug16887() +begin + declare i int default 10; + + again: + while i > 0 do + begin + declare breakchar varchar(1); + declare done int default 0; + declare t3_cursor cursor for select c from t3; + declare continue handler for not found set done = 1; + + set i = i - 1; + select i; + + if i = 3 then + iterate again; + end if; + + open t3_cursor; + + loop + fetch t3_cursor into breakchar; + + if done = 1 then + begin + close t3_cursor; + iterate again; + end; + end if; + end loop; + end; + end while; +end| + +call bug16887()| + +drop table t3| +drop procedure bug16887| + +# +# BUG#16474: SP crashed MySQL +# (when using "order by localvar", where 'localvar' is just that. +# +--disable_warnings +drop procedure if exists bug16474_1| +drop procedure if exists bug16474_2| +--enable_warnings + +delete from t1| +insert into t1 values ('c', 2), ('b', 3), ('a', 1)| + +create procedure bug16474_1() +begin + declare x int; + + select id from t1 order by x, id; +end| + +# +# BUG#14945: Truncate table doesn't reset the auto_increment counter +# +--disable_warnings ONCE +drop procedure if exists bug14945| +create table t3 (id int not null auto_increment primary key)| +create procedure bug14945() deterministic truncate t3| +insert into t3 values (null)| +call bug14945()| +insert into t3 values (null)| +select * from t3| +drop table t3| +drop procedure bug14945| + +# This does NOT order by column index; variable is an expression. +create procedure bug16474_2(x int) + select id from t1 order by x, id| + +call bug16474_1()| +call bug16474_2(1)| +call bug16474_2(2)| +drop procedure bug16474_1| +drop procedure bug16474_2| + +# For reference: user variables are expressions too and do not affect ordering. +set @x = 2| +select * from t1 order by @x, data| + +delete from t1| + + +# +# BUG#15728: LAST_INSERT_ID function inside a stored function returns 0 +# +# The solution is not to reset last_insert_id on enter to sub-statement. +# +--disable_warnings +drop function if exists bug15728| +drop table if exists t3| +--enable_warnings + +create table t3 ( + id int not null auto_increment, + primary key (id) +)| +create function bug15728() returns int(11) + return last_insert_id()| + +insert into t3 values (0)| +select last_insert_id()| +select bug15728()| + +drop function bug15728| +drop table t3| + + +# +# BUG#18787: Server crashed when calling a stored procedure containing +# a misnamed function +# +--disable_warnings ONCE +drop procedure if exists bug18787| +create procedure bug18787() +begin + declare continue handler for sqlexception begin end; + + select no_such_function(); +end| + +call bug18787()| +drop procedure bug18787| + + +# +# BUG#18344: DROP DATABASE does not drop associated routines +# (... if the database name is longer than 21 characters) +# +# 1234567890123456789012 +create database bug18344_012345678901| +use bug18344_012345678901| +create procedure bug18344() begin end| +create procedure bug18344_2() begin end| + +create database bug18344_0123456789012| +use bug18344_0123456789012| +create procedure bug18344() begin end| +create procedure bug18344_2() begin end| + +use test| + +select schema_name from information_schema.schemata where + schema_name like 'bug18344%'| +select routine_name,routine_schema from information_schema.routines where + routine_schema like 'bug18344%'| + +drop database bug18344_012345678901| +drop database bug18344_0123456789012| + +# Should be nothing left. +select schema_name from information_schema.schemata where + schema_name like 'bug18344%'| +select routine_name,routine_schema from information_schema.routines where + routine_schema like 'bug18344%'| + + +# +# BUG#12472/BUG#15137 'CREATE TABLE ... SELECT ... which explicitly or +# implicitly uses stored function gives "Table not locked" error'. +# +--disable_warnings ONCE +drop function if exists bug12472| +create function bug12472() returns int return (select count(*) from t1)| +# Check case when function is used directly +# --error 1241 +# create table t3 as select bug12472() as i| +--error 1146 +show create table t3| +--error 1146 +select * from t3| +--error 1051 +drop table t3| +# Check case when function is used indirectly through view +create view v1 as select bug12472() as j| + +create table t3 as select * from v1| + +show create table t3| + +select * from t3| + +drop table t3| +drop view v1| +drop function bug12472| + + +# +# BUG#18587: Function that accepts and returns TEXT garbles data if longer than +# 766 chars +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug18589_f1| +DROP PROCEDURE IF EXISTS bug18589_p1| +DROP PROCEDURE IF EXISTS bug18589_p2| +--enable_warnings + +CREATE FUNCTION bug18589_f1(arg varchar(1024)) RETURNS varchar(1024) +BEGIN + RETURN CONCAT(arg, ""); +END| + +CREATE PROCEDURE bug18589_p1(arg varchar(1024), OUT ret varchar(1024)) +BEGIN + SET ret = CONCAT(arg, ""); +END| + +CREATE PROCEDURE bug18589_p2(arg varchar(1024)) +BEGIN + DECLARE v varchar(1024); + CALL bug18589_p1(arg, v); + SELECT v; +END| + +# Test case. + +SELECT bug18589_f1(REPEAT("a", 767))| + +SET @bug18589_v1 = ""| +CALL bug18589_p1(REPEAT("a", 767), @bug18589_v1)| +SELECT @bug18589_v1| + +CALL bug18589_p2(REPEAT("a", 767))| + +# Cleanup. + +DROP FUNCTION bug18589_f1| +DROP PROCEDURE bug18589_p1| +DROP PROCEDURE bug18589_p2| + + +# +# BUG#18037: Server crash when returning system variable in stored procedures +# BUG#19633: Stack corruption in fix_fields()/THD::rollback_item_tree_changes() +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug18037_f1| +DROP PROCEDURE IF EXISTS bug18037_p1| +DROP PROCEDURE IF EXISTS bug18037_p2| +--enable_warnings + +# Test case. + +CREATE FUNCTION bug18037_f1() RETURNS INT +BEGIN + RETURN @@ob_org_cluster_id; +END| + +CREATE PROCEDURE bug18037_p1() +BEGIN + DECLARE v INT DEFAULT @@ob_org_cluster_id; +END| + +CREATE PROCEDURE bug18037_p2() +BEGIN + CASE @@ob_org_cluster_id + WHEN -1 THEN + SELECT 0; + ELSE + SELECT 1; + END CASE; +END| + +SELECT bug18037_f1()| +CALL bug18037_p1()| +CALL bug18037_p2()| + +# Cleanup. + +DROP FUNCTION bug18037_f1| +DROP PROCEDURE bug18037_p1| +DROP PROCEDURE bug18037_p2| + +# +# Bug#17199: "Table not found" error occurs if the query contains a call +# to a function from another database. +# See also ps.test for an additional test case for this bug. +# +use test| +create table t3 (i int)| +insert into t3 values (1), (2)| +create database mysqltest1| +use mysqltest1| +create function bug17199() returns varchar(2) deterministic return 'ok'| +use test| +select *, mysqltest1.bug17199() from t3| +# +# Bug#18444: Fully qualified stored function names don't work correctly +# in select statements +# +use mysqltest1| +create function bug18444(i int) returns int no sql deterministic return i + 1| +use test| +select mysqltest1.bug18444(i) from t3| +drop database mysqltest1| +# +# Check that current database has no influence to a stored procedure +# +create database mysqltest1 charset=utf8| +create database mysqltest2 charset=utf8| +create procedure mysqltest1.p1() +begin +-- alters the default collation of database test + alter database character set koi8r; +end| +use mysqltest1| +--error 1115 +call p1()| +drop procedure mysqltest1.p1| +create procedure mysqltest1.p1() +begin +-- alters the default collation of database test + alter database character set binary; +end| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create database mysqltest1| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create database mysqltest2| +alter database mysqltest1 character set utf8| +use mysqltest2| +call mysqltest1.p1()| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create database mysqltest1| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create database mysqltest2| +drop procedure mysqltest1.p1| +drop database mysqltest1| +drop database mysqltest2| +# +# Restore the old environemnt +use test| +# +# Bug#15217 "Using a SP cursor on a table created with PREPARE fails with +# weird error". Check that the code that is supposed to work at +# the first execution of a stored procedure actually works for +# sp_instr_copen. + +--disable_warnings +drop table if exists t3| +drop procedure if exists bug15217| +--enable_warnings +create table t3 as select 1| +create procedure bug15217() +begin + declare var1 char(255); + declare cur1 cursor for select * from t3; + open cur1; + fetch cur1 into var1; + select concat('data was: /', var1, '/'); + close cur1; +end | +# Returns expected result +call bug15217()| +--error 1064 +flush tables | +# Returns error with garbage as column name +call bug15217()| +drop table t3| +drop procedure bug15217| + + +# +# BUG#21013: Performance Degrades when importing data that uses +# Trigger and Stored Procedure +# +# This is a performance and memory leak test. Run with large number +# passed to bug21013() procedure. +# +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS bug21013 | + +CREATE PROCEDURE bug21013(IN lim INT) +BEGIN + DECLARE i INT DEFAULT 0; + WHILE (i < lim) DO + SET @b = LOCATE(_utf8mb4'b', @a, 1); + SET i = i + 1; + END WHILE; +END | + +SET @a = _utf8mb4"aaaaaaaaaa" | +CALL bug21013(10) | + +DROP PROCEDURE bug21013 | + + +# +# BUG#16211: Stored function return type for strings is ignored +# + +# Prepare: create database with fixed, pre-defined character set. + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +--enable_warnings + +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET utf8| + +# Test case: + +use mysqltest1| + +# - Create two stored functions -- with and without explicit CHARSET-clause +# for return value; + +CREATE FUNCTION bug16211_f1() RETURNS CHAR(10) + RETURN ""| + +--error 1115 +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET koi8r + RETURN ""| +CREATE FUNCTION bug16211_f2() RETURNS CHAR(10) CHARSET binary + RETURN ""| + +CREATE FUNCTION mysqltest2.bug16211_f3() RETURNS CHAR(10) + RETURN ""| + +--error 1115 +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET koi8r + RETURN ""| +CREATE FUNCTION mysqltest2.bug16211_f4() RETURNS CHAR(10) CHARSET binary + RETURN ""| + +# - Check that CHARSET-clause is specified for the second function; + +SHOW CREATE FUNCTION bug16211_f1| +SHOW CREATE FUNCTION bug16211_f2| + +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| + +SELECT CHARSET(bug16211_f1())| +SELECT CHARSET(bug16211_f2())| + +SELECT CHARSET(mysqltest2.bug16211_f3())| +SELECT CHARSET(mysqltest2.bug16211_f4())| + +# - Alter database character set. + +--error 1115 +ALTER DATABASE mysqltest1 CHARACTER SET cp1251| +ALTER DATABASE mysqltest1 CHARACTER SET utf8mb4| +--error 1115 +ALTER DATABASE mysqltest2 CHARACTER SET cp1251| +ALTER DATABASE mysqltest2 CHARACTER SET utf8mb4| + +# - Check that CHARSET-clause has not changed. + +SHOW CREATE FUNCTION bug16211_f1| +SHOW CREATE FUNCTION bug16211_f2| + +SHOW CREATE FUNCTION mysqltest2.bug16211_f3| +SHOW CREATE FUNCTION mysqltest2.bug16211_f4| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f1"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest1" AND ROUTINE_NAME = "bug16211_f2"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f3"| + +SELECT dtd_identifier +FROM INFORMATION_SCHEMA.ROUTINES +WHERE ROUTINE_SCHEMA = "mysqltest2" AND ROUTINE_NAME = "bug16211_f4"| + +SELECT CHARSET(bug16211_f1())| +SELECT CHARSET(bug16211_f2())| + +SELECT CHARSET(mysqltest2.bug16211_f3())| +SELECT CHARSET(mysqltest2.bug16211_f4())| + +# Cleanup. + +use test| + +DROP DATABASE mysqltest1| +DROP DATABASE mysqltest2| + + +# +# BUG#16676: Database CHARSET not used for stored procedures +# + +# Prepare: create database with fixed, pre-defined character set. + +--disable_warnings ONCE +DROP DATABASE IF EXISTS mysqltest1| + +CREATE DATABASE mysqltest1 DEFAULT CHARACTER SET utf8| + +# Test case: + +use mysqltest1| + +# - Create two stored procedures -- with and without explicit CHARSET-clause; + +CREATE PROCEDURE bug16676_p1( + IN p1 CHAR(10), + INOUT p2 CHAR(10), + OUT p3 CHAR(10)) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| + +--error 1115 +CREATE PROCEDURE bug16676_p2( + IN p1 CHAR(10) CHARSET koi8r, + INOUT p2 CHAR(10) CHARSET cp1251, + OUT p3 CHAR(10) CHARSET greek) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| +CREATE PROCEDURE bug16676_p2( + IN p1 CHAR(10) CHARSET binary, + INOUT p2 CHAR(10) CHARSET binary, + OUT p3 CHAR(10) CHARSET binary) +BEGIN + SELECT CHARSET(p1), COLLATION(p1); + SELECT CHARSET(p2), COLLATION(p2); + SELECT CHARSET(p3), COLLATION(p3); +END| + +# - Call procedures. + +SET @v2 = 'b'| +SET @v3 = 'c'| + +CALL bug16676_p1('a', @v2, @v3)| +CALL bug16676_p2('a', @v2, @v3)| + +# Cleanup. + +use test| + +DROP DATABASE mysqltest1| +# +# BUG#8153: Stored procedure with subquery and continue handler, wrong result +# + +--disable_warnings +drop table if exists t3| +drop table if exists t4| +drop procedure if exists bug8153_subselect| +drop procedure if exists bug8153_subselect_a| +drop procedure if exists bug8153_subselect_b| +drop procedure if exists bug8153_proc_a| +drop procedure if exists bug8153_proc_b| +--enable_warnings + +create table t3 (a int)| +create table t4 (a int)| +insert into t3 values (1), (1), (2), (3)| +insert into t4 values (1), (1)| + +## Testing the use case reported in Bug#8153 + +create procedure bug8153_subselect() +begin + declare continue handler for sqlexception + begin + select 'statement failed'; + end; + update t3 set a=a+1 where (select a from t4 where a=1) is null; + select 'statement after update'; +end| + +call bug8153_subselect()| +select * from t3| + +call bug8153_subselect()| +select * from t3| + +drop procedure bug8153_subselect| + +## Testing a subselect with a non local handler + +create procedure bug8153_subselect_a() +begin + declare continue handler for sqlexception + begin + select 'in continue handler'; + end; + + select 'reachable code a1'; + call bug8153_subselect_b(); + select 'reachable code a2'; +end| + +create procedure bug8153_subselect_b() +begin + select 'reachable code b1'; + update t3 set a=a+1 where (select a from t4 where a=1) is null; + select 'unreachable code b2'; +end| + +call bug8153_subselect_a()| +select * from t3| + +call bug8153_subselect_a()| +select * from t3| + +drop procedure bug8153_subselect_a| +drop procedure bug8153_subselect_b| + +## Testing extra use cases, found while investigating +## This is related to BUG#18787, with a non local handler + +create procedure bug8153_proc_a() +begin + declare continue handler for sqlexception + begin + select 'in continue handler'; + end; + + select 'reachable code a1'; + call bug8153_proc_b(); + select 'reachable code a2'; +end| + +create procedure bug8153_proc_b() +begin + select 'reachable code b1'; + select no_such_function(); + select 'unreachable code b2'; +end| + +call bug8153_proc_a()| + +drop procedure bug8153_proc_a| +drop procedure bug8153_proc_b| +drop table t3| +drop table t4| + +# +# BUG#19862: Sort with filesort by function evaluates function twice +# +--disable_warnings ONCE +drop procedure if exists bug19862| +--disable_warnings ONCE +DROP TABLE if exists t11| +--disable_warnings ONCE +DROP TABLE if exists t12| +--disable_warnings ONCE +DROP FUNCTION if exists bug19862| +CREATE TABLE t11 (a INT)| +CREATE TABLE t12 (a INT)| +--disable_warnings ONCE +drop function if exists bug19862| +CREATE FUNCTION bug19862(x INT) RETURNS INT + BEGIN + INSERT INTO t11 VALUES (x); + RETURN x+1; + END| +INSERT INTO t12 VALUES (1), (2)| +SELECT bug19862(a) FROM t12 ORDER BY 1| +SELECT * FROM t11| +DROP TABLE t11, t12| +DROP FUNCTION bug19862| + + +# Bug#21002 "Derived table not selecting from a "real" table fails in JOINs" +# +# A regression caused by the fix for Bug#18444: for derived tables we should +# set an empty string as the current database. They do not belong to any +# database and must be usable even if there is no database +# selected. +--disable_warnings +drop table if exists t3| +drop database if exists mysqltest1| +--enable_warnings +create table t3 (a int)| +insert into t3 (a) values (1), (2)| + +create database mysqltest1| +use mysqltest1| +drop database mysqltest1| + +# No current database +select database()| + +select * from (select 1 as a) as t1 natural join (select * from test.t3) as t2| +use test| +drop table t3| + + +# Test for BUG#16899: Possible buffer overflow in handling of DEFINER-clause. +# +# Prepare. + +--disable_warnings +DROP PROCEDURE IF EXISTS bug16899_p1| +DROP FUNCTION IF EXISTS bug16899_f1| +--enable_warnings + +#--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=1234567890abcdefGHIKL@localhost PROCEDURE bug16899_p1() +BEGIN + SET @a = 1; +END| + +#--error ER_WRONG_STRING_LENGTH +CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY + FUNCTION bug16899_f1() RETURNS INT +BEGIN + RETURN 1; +END| + +DROP PROCEDURE bug16899_p1| +DROP FUNCTION bug16899_f1| + +# +# BUG#21416: SP: Recursion level higher than zero needed for non-recursive call +# +--disable_warnings ONCE +drop procedure if exists bug21416| +create procedure bug21416() show create procedure bug21416| +call bug21416()| +drop procedure bug21416| + + +# +# BUG#21414: SP: Procedure undroppable, to some extent +# +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS bug21414| + +CREATE PROCEDURE bug21414() SELECT 1| + +--error 1064 +FLUSH TABLES WITH READ LOCK| + +#--error ER_CANT_UPDATE_WITH_READLOCK +DROP PROCEDURE bug21414| + +UNLOCK TABLES| + +--echo The following should succeed. +--error 1305 +DROP PROCEDURE bug21414| + + +# +# BUG#21311: Possible stack overrun if SP has non-latin1 name +# +set names utf8| +--disable_warnings ONCE +--error 0,1064 +drop database if exists това_е_дълго_име_за_база_данни_нали| +--error 0,1064 +create database това_е_дълго_име_за_база_данни_нали| +--error 0,1235 +INSERT INTO mysql.proc VALUES ('това_е_дълго_име_за_база_данни_нали','това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго','PROCEDURE','това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго','SQL','CONTAINS_SQL','NO','DEFINER','','','bad_body','root@localhost',now(), now(),'','', 'utf8', 'utf8_general_ci', 'utf8_general_ci', 'n/a')| +#--error ER_SP_PROC_TABLE_CORRUPT +--error 1305 +call това_е_дълго_име_за_база_данни_нали.това_е_процедура_с_доста_дълго_име_нали_и_още_по_дълго()| +drop database това_е_дълго_име_за_база_данни_нали| + + +# +# BUG#21493: Crash on the second call of a procedure containing +# a select statement that uses an IN aggregating subquery +# + +CREATE TABLE t3 ( + Member_ID varchar(15) NOT NULL, + PRIMARY KEY (Member_ID) +)| + +CREATE TABLE t4 ( + ID int(10) unsigned NOT NULL auto_increment, + Member_ID varchar(15) NOT NULL default '', + Action varchar(12) NOT NULL, + Action_Date datetime NOT NULL, + Track varchar(15) default NULL, + User varchar(12) default NULL, + Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update + CURRENT_TIMESTAMP, + PRIMARY KEY (ID), + KEY Action (Action), + KEY Action_Date (Action_Date) +)| + + +INSERT INTO t3(Member_ID) VALUES + ('111111'), ('222222'), ('333333'), ('444444'), ('555555'), ('666666')| + +INSERT INTO t4(Member_ID, Action, Action_Date, Track) VALUES + ('111111', 'Disenrolled', '2006-03-01', 'CAD' ), + ('111111', 'Enrolled', '2006-03-01', 'CAD' ), + ('111111', 'Disenrolled', '2006-07-03', 'CAD' ), + ('222222', 'Enrolled', '2006-03-07', 'CAD' ), + ('222222', 'Enrolled', '2006-03-07', 'CHF' ), + ('222222', 'Disenrolled', '2006-08-02', 'CHF' ), + ('333333', 'Enrolled', '2006-03-01', 'CAD' ), + ('333333', 'Disenrolled', '2006-03-01', 'CAD' ), + ('444444', 'Enrolled', '2006-03-01', 'CAD' ), + ('555555', 'Disenrolled', '2006-03-01', 'CAD' ), + ('555555', 'Enrolled', '2006-07-21', 'CAD' ), + ('555555', 'Disenrolled', '2006-03-01', 'CHF' ), + ('666666', 'Enrolled', '2006-02-09', 'CAD' ), + ('666666', 'Enrolled', '2006-05-12', 'CHF' ), + ('666666', 'Disenrolled', '2006-06-01', 'CAD' )| + +--disable_warnings ONCE +DROP FUNCTION IF EXISTS bug21493| + +CREATE FUNCTION bug21493(paramMember VARCHAR(15)) RETURNS varchar(45) +BEGIN +DECLARE tracks VARCHAR(45); +SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t4 + WHERE Member_ID=paramMember AND Action='Enrolled' AND + (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t4 + WHERE Member_ID=paramMember GROUP BY Track) INTO tracks; +RETURN tracks; +END| +SELECT bug21493('111111')| +SELECT bug21493('222222')| +SELECT bug21493(Member_ID) FROM t3| + +DROP FUNCTION bug21493| +DROP TABLE t3,t4| + +# +# Bug#20028 Function with select return no data +# + +--disable_warnings +drop function if exists func_20028_a| +drop function if exists func_20028_b| +drop function if exists func_20028_c| +drop procedure if exists proc_20028_a| +drop procedure if exists proc_20028_b| +drop procedure if exists proc_20028_c| +drop table if exists table_20028| +--enable_warnings + +create table table_20028 (i int)| + +SET @save_sql_mode=@@sql_mode| + +SET sql_mode=''| + +create function func_20028_a() returns integer +begin + declare temp integer; + select i from table_20028 limit 1 into temp; + return ifnull(temp, 0); +end| + +create function func_20028_b() returns integer +begin + return func_20028_a(); +end| + +create function func_20028_c() returns integer +begin + declare div_zero integer; +# set SQL_MODE='TRADITIONAL'; + set SQL_MODE='ONLY_FULL_GROUP_BY'; + select 1/0 into div_zero; + return div_zero; +end| + +create procedure proc_20028_a() +begin + declare temp integer; + select i from table_20028 limit 1 into temp; +end| + +create procedure proc_20028_b() +begin + call proc_20028_a(); +end| + +create procedure proc_20028_c() +begin + declare div_zero integer; +# set SQL_MODE='TRADITIONAL'; + set SQL_MODE='ONLY_FULL_GROUP_BY'; + select 1/0 into div_zero; +end| + +select func_20028_a()| +select func_20028_b()| +#--error ER_DIVISION_BY_ZERO +select func_20028_c()| +call proc_20028_a()| +call proc_20028_b()| +#--error ER_DIVISION_BY_ZERO +call proc_20028_c()| + +#SET sql_mode='TRADITIONAL'| +set SQL_MODE='ONLY_FULL_GROUP_BY'; + +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| + +create function func_20028_a() returns integer +begin + declare temp integer; + select i from table_20028 limit 1 into temp; + return ifnull(temp, 0); +end| + +create function func_20028_b() returns integer +begin + return func_20028_a(); +end| + +create function func_20028_c() returns integer +begin + declare div_zero integer; + set SQL_MODE=''; + select 1/0 into div_zero; + return div_zero; +end| + +create procedure proc_20028_a() +begin + declare temp integer; + select i from table_20028 limit 1 into temp; +end| + +create procedure proc_20028_b() +begin + call proc_20028_a(); +end| + +create procedure proc_20028_c() +begin + declare div_zero integer; + set SQL_MODE=''; + select 1/0 into div_zero; +end| + +select func_20028_a()| +select func_20028_b()| +select func_20028_c()| +call proc_20028_a()| +call proc_20028_b()| +call proc_20028_c()| + +SET @@sql_mode=@save_sql_mode| + +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +drop table table_20028| + +# +# Bug#21462 Stored procedures with no arguments require parenthesis +# + +--disable_warnings +drop procedure if exists proc_21462_a| +drop procedure if exists proc_21462_b| +--enable_warnings + +create procedure proc_21462_a() +begin + select "Called A"; +end| + +create procedure proc_21462_b(x int) +begin + select "Called B"; +end| + +call proc_21462_a| +call proc_21462_a()| +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_a(1)| + +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_b| +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_b()| +call proc_21462_b(1)| + +drop procedure proc_21462_a| +drop procedure proc_21462_b| + + +# +# Bug#19733 "Repeated alter, or repeated create/drop, fails" +# Check that CREATE/DROP INDEX is re-execution friendly. +# +--disable_warnings +drop table if exists t3| +drop procedure if exists proc_bug19733| +--enable_warnings +create table t3 (s1 int)| + +create procedure proc_bug19733() +begin + declare v int default 0; + while v < 5 do + create index i on t3 (s1); + drop index i on t3; + set v = v + 1; + end while; +end| + +set ob_query_timeout=10000000000; +call proc_bug19733()| +call proc_bug19733()| +call proc_bug19733()| +set ob_query_timeout=default; + +drop procedure proc_bug19733| +drop table t3| + + +# +# BUG#20492: Subsequent calls to stored procedure yeild incorrect +# result if join is used +# +# Optimized ON expression in join wasn't properly saved for reuse. +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1| +DROP VIEW IF EXISTS v1, v2| +DROP TABLE IF EXISTS t3, t4| +--enable_warnings + +CREATE TABLE t3 (t3_id INT)| + +INSERT INTO t3 VALUES (0)| +INSERT INTO t3 VALUES (1)| + +CREATE TABLE t4 (t4_id INT)| + +INSERT INTO t4 VALUES (2)| + +CREATE VIEW v1 AS +SELECT t3.t3_id, t4.t4_id +FROM t3 JOIN t4 ON t3.t3_id = 0| + +CREATE VIEW v2 AS +SELECT t3.t3_id AS t3_id_1, v1.t3_id AS t3_id_2, v1.t4_id +FROM t3 LEFT JOIN v1 ON t3.t3_id = 0| + +CREATE PROCEDURE p1() SELECT * FROM v2| + +# Results should not differ. +CALL p1()| +CALL p1()| + +DROP PROCEDURE p1| +DROP VIEW v1, v2| +DROP TABLE t3, t4| + +--echo End of 5.0 tests + +--echo Begin of 5.1 tests + +# +# BUG#18239: Possible to overload internal functions with stored functions +# + +delimiter ;| + +--disable_warnings ONCE +drop function if exists pi; + +create function pi() returns varchar(50) +return "pie, my favorite desert."; + +SET @save_sql_mode=@@sql_mode; + +--error 1235 +SET SQL_MODE='IGNORE_SPACE'; + +select pi(), pi (); + +# Non deterministic warnings from db_load_routine +--disable_warnings ONCE +select test.pi(), test.pi (); + +SET SQL_MODE=''; + +select pi(), pi (); + +# Non deterministic warnings from db_load_routine +--disable_warnings ONCE +select test.pi(), test.pi (); + +SET @@sql_mode=@save_sql_mode; + +drop function pi; +# End of BUG#18239 + +# +# BUG#22619: Spaces considered harmful +# + +--disable_warnings +--error 1064 +drop function if exists test.database; +--error 1064 +drop function if exists test.current_user; +drop function if exists test.md5; +--enable_warnings + +create database nowhere; +use nowhere; +drop database nowhere; + +SET @save_sql_mode=@@sql_mode; + +--error 1235 +SET SQL_MODE='IGNORE_SPACE'; + +select database(), database (); +select current_user(), current_user (); +select md5("aaa"), md5 ("aaa"); + +SET SQL_MODE=''; + +select database(), database (); +select current_user(), current_user (); +select md5("aaa"), md5 ("aaa"); + +use test; + +--disable_warnings +drop function if exists `database`; +drop function if exists `current_user`; +drop function if exists `md5`; +--enable_warnings +create function `database`() returns varchar(50) +return "Stored function database"; + +create function `current_user`() returns varchar(50) +return "Stored function current_user"; + +create function md5(x varchar(50)) returns varchar(50) +return "Stored function md5"; + +--error 1235 +SET SQL_MODE='IGNORE_SPACE'; + +select database(), database (); +select current_user(), current_user (); +select md5("aaa"), md5 ("aaa"); + +# Non deterministic warnings from db_load_routine +--disable_warnings +select test.database(), test.database (); +select test.current_user(), test.current_user (); +select test.md5("aaa"), test.md5 ("aaa"); +--enable_warnings + +SET SQL_MODE=''; + +select database(), database (); +select current_user(), current_user (); +select md5("aaa"), md5 ("aaa"); + +# Non deterministic warnings from db_load_routine +--disable_warnings +select test.database(), test.database (); +select test.current_user(), test.current_user (); +select test.md5("aaa"), test.md5 ("aaa"); +--enable_warnings + +SET @@sql_mode=@save_sql_mode; + +--error 1064 +drop function test.database; +--error 1064 +drop function test.current_user; +drop function md5; + +use test; +delimiter |; +# End of BUG#22619 + +--echo End of 5.1 tests + +# +# BUG#23760: ROW_COUNT() and store procedure not owrking together +# +--disable_warnings +DROP TABLE IF EXISTS bug23760| +DROP TABLE IF EXISTS bug23760_log| +DROP PROCEDURE IF EXISTS bug23760_update_log| +DROP PROCEDURE IF EXISTS bug23760_test_row_count| +DROP FUNCTION IF EXISTS bug23760_rc_test| +--enable_warnings +CREATE TABLE bug23760 ( + id INT NOT NULL AUTO_INCREMENT , + num INT NOT NULL , + PRIMARY KEY ( id ) +)| + +CREATE TABLE bug23760_log ( + id INT NOT NULL AUTO_INCREMENT , + reason VARCHAR(50)NULL , + ammount INT NOT NULL , + PRIMARY KEY ( id ) +)| + +CREATE PROCEDURE bug23760_update_log(r Varchar(50), a INT) +BEGIN + INSERT INTO bug23760_log (reason, ammount) VALUES(r, a); +END| + +CREATE PROCEDURE bug23760_test_row_count() +BEGIN + UPDATE bug23760 SET num = num + 1; + CALL bug23760_update_log('Test is working', ROW_COUNT()); + UPDATE bug23760 SET num = num - 1; +END| + + +CREATE PROCEDURE bug23760_test_row_count2(level INT) +BEGIN + IF level THEN + UPDATE bug23760 SET num = num + 1; + CALL bug23760_update_log('Test2 is working', ROW_COUNT()); + CALL bug23760_test_row_count2(level - 1); + END IF; +END| + +CREATE FUNCTION bug23760_rc_test(in_var INT) RETURNS INT RETURN in_var| + +INSERT INTO bug23760 (num) VALUES (0), (1), (1), (2), (3), (5), (8)| +SELECT ROW_COUNT()| + +CALL bug23760_test_row_count()| +SELECT * FROM bug23760_log ORDER BY id| + +SET @save_max_sp_recursion= @@max_sp_recursion_depth| +SELECT @save_max_sp_recursion| +SET max_sp_recursion_depth= 5| +SELECT @@max_sp_recursion_depth| +CALL bug23760_test_row_count2(2)| +SELECT ROW_COUNT()| +SELECT * FROM bug23760_log ORDER BY id| +SELECT * FROM bug23760 ORDER by ID| +SET max_sp_recursion_depth= @save_max_sp_recursion| + +SELECT bug23760_rc_test(123)| +INSERT INTO bug23760 (num) VALUES (13), (21), (34), (55)| +SELECT bug23760_rc_test(ROW_COUNT())| + +DROP TABLE bug23760, bug23760_log| +DROP PROCEDURE bug23760_update_log| +DROP PROCEDURE bug23760_test_row_count| +DROP PROCEDURE bug23760_test_row_count2| +DROP FUNCTION bug23760_rc_test| + +# +# BUG#24117: server crash on a FETCH with a cursor on a table which is not in +# the table cache +# + +--disable_warnings +DROP PROCEDURE IF EXISTS bug24117| +DROP TABLE IF EXISTS t3| +--enable_warnings +CREATE TABLE t3(c1 ENUM('abc'))| +INSERT INTO t3 VALUES('abc')| +--error 1064 +CREATE PROCEDURE bug24117() +BEGIN + DECLARE t3c1 ENUM('abc'); + DECLARE mycursor CURSOR FOR SELECT c1 FROM t3; + OPEN mycursor; + FLUSH TABLES; + FETCH mycursor INTO t3c1; + CLOSE mycursor; +END| +CREATE PROCEDURE bug24117() +BEGIN + DECLARE t3c1 ENUM('abc'); + DECLARE mycursor CURSOR FOR SELECT c1 FROM t3; + OPEN mycursor; + FETCH mycursor INTO t3c1; + CLOSE mycursor; +END| +CALL bug24117()| +DROP PROCEDURE bug24117| +DROP TABLE t3| + +# +# Bug#8407(Stored functions/triggers ignore exception handler) +# + +--disable_warnings +drop function if exists func_8407_a| +drop function if exists func_8407_b| +--enable_warnings + +create function func_8407_a() returns int +begin + declare x int; + + declare continue handler for sqlexception + begin + end; + + select 1 from no_such_view limit 1 into x; + + return x; +end| + +create function func_8407_b() returns int +begin + declare x int default 0; + + declare continue handler for sqlstate '42S02' + begin + set x:= x+1000; + end; + + case (select 1 from no_such_view limit 1) + when 1 then set x:= x+1; + when 2 then set x:= x+2; + else set x:= x+100; + end case; + set x:=x + 500; + + return x; +end| + +select func_8407_a()| +select func_8407_b()| + +drop function func_8407_a| +drop function func_8407_b| + +# +# Bug#26503 (Illegal SQL exception handler code causes the server to crash) +# + +--disable_warnings +drop table if exists table_26503| +drop procedure if exists proc_26503_ok_1| +drop procedure if exists proc_26503_ok_2| +drop procedure if exists proc_26503_ok_3| +drop procedure if exists proc_26503_ok_4| +--enable_warnings + +create table table_26503(a int unique)| + +create procedure proc_26503_ok_1(v int) +begin + declare i int default 5; + + declare continue handler for sqlexception + begin + select 'caught something'; + retry: + while i > 0 do + begin + set i = i - 1; + select 'looping', i; + iterate retry; + select 'dead code'; + end; + end while retry; + select 'leaving handler'; + end; + + select 'do something'; + insert into table_26503 values (v); + select 'do something again'; + insert into table_26503 values (v); +end| + +create procedure proc_26503_ok_2(v int) +begin + declare i int default 5; + + declare continue handler for sqlexception + begin + select 'caught something'; + retry: + while i > 0 do + begin + set i = i - 1; + select 'looping', i; + leave retry; + select 'dead code'; + end; + end while; + select 'leaving handler'; + end; + + select 'do something'; + insert into table_26503 values (v); + select 'do something again'; + insert into table_26503 values (v); +end| + +## The outer retry label should not prevent using the inner label. + +create procedure proc_26503_ok_3(v int) +begin + declare i int default 5; + +retry: + begin + declare continue handler for sqlexception + begin + select 'caught something'; + retry: + while i > 0 do + begin + set i = i - 1; + select 'looping', i; + iterate retry; + select 'dead code'; + end; + end while retry; + select 'leaving handler'; + end; + + select 'do something'; + insert into table_26503 values (v); + select 'do something again'; + insert into table_26503 values (v); + end; +end| + +## The outer retry label should not prevent using the inner label. + +create procedure proc_26503_ok_4(v int) +begin + declare i int default 5; + +retry: + begin + declare continue handler for sqlexception + begin + select 'caught something'; + retry: + while i > 0 do + begin + set i = i - 1; + select 'looping', i; + leave retry; + select 'dead code'; + end; + end while; + select 'leaving handler'; + end; + + select 'do something'; + insert into table_26503 values (v); + select 'do something again'; + insert into table_26503 values (v); + end; +end| + +call proc_26503_ok_1(1)| +call proc_26503_ok_2(2)| +call proc_26503_ok_3(3)| +call proc_26503_ok_4(4)| + +drop table table_26503| +drop procedure proc_26503_ok_1| +drop procedure proc_26503_ok_2| +drop procedure proc_26503_ok_3| +drop procedure proc_26503_ok_4| + +# +# Bug#25373: Stored functions wasn't compared correctly which leads to a wrong +# result. +# +--disable_warnings +DROP FUNCTION IF EXISTS bug25373| +CREATE FUNCTION bug25373(p1 INTEGER) RETURNS INTEGER +LANGUAGE SQL DETERMINISTIC +RETURN p1;| +CREATE TABLE t3 (f1 INT, f2 FLOAT)| +INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)| +SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY f1 WITH ROLLUP| +DROP FUNCTION bug25373| +DROP TABLE t3| + +#todo: https://work.aone.alibaba-inc.com/task/24579977 +#这里等共享表达式提交之后再将这个case补上 +#SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP + +# +# BUG#25082: Default database change on trigger execution breaks replication. +# +# As it turned out, this bug has actually two bugs. So, here we have two test +# cases -- one in sp.test, the other in sp-security.test. +# + +# +# Test case 1: error on dropping the current database. +# + +# Prepare. + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1| +DROP DATABASE IF EXISTS mysqltest2| +--enable_warnings + +CREATE DATABASE mysqltest1| +CREATE DATABASE mysqltest2| + +# Test. + +CREATE PROCEDURE mysqltest1.p1() + DROP DATABASE mysqltest2| + +use mysqltest2| + +CALL mysqltest1.p1()| + +SELECT DATABASE()| + +# Cleanup. +drop procedure mysqltest1.p1| +DROP DATABASE mysqltest1| + +use test| + + +# +# Bug#20777: Function w BIGINT UNSIGNED shows diff. behaviour --ps-protocol +--disable_warnings +drop function if exists bug20777| +drop table if exists examplebug20777| +--enable_warnings +create function bug20777(f1 bigint unsigned) returns bigint unsigned +begin + set f1 = (f1 - 10); set f1 = (f1 + 10); +return f1; +end| +delimiter ;| +select bug20777(9223372036854775803) as '9223372036854775803 2**63-5'; +select bug20777(9223372036854775804) as '9223372036854775804 2**63-4'; +select bug20777(9223372036854775805) as '9223372036854775805 2**63-3'; +select bug20777(9223372036854775806) as '9223372036854775806 2**63-2'; +select bug20777(9223372036854775807) as '9223372036854775807 2**63-1'; +select bug20777(9223372036854775808) as '9223372036854775808 2**63+0'; +select bug20777(9223372036854775809) as '9223372036854775809 2**63+1'; +select bug20777(9223372036854775810) as '9223372036854775810 2**63+2'; +--error ER_DATA_OUT_OF_RANGE +select bug20777(-9223372036854775808) as 'lower bounds signed bigint'; +select bug20777(9223372036854775807) as 'upper bounds signed bigint'; +--error ER_DATA_OUT_OF_RANGE +select bug20777(0) as 'lower bounds unsigned bigint'; +select bug20777(18446744073709551615) as 'upper bounds unsigned bigint'; +select bug20777(18446744073709551616) as 'upper bounds unsigned bigint + 1'; +--error ER_DATA_OUT_OF_RANGE +select bug20777(-1) as 'lower bounds unsigned bigint - 1'; + +create table examplebug20777 as select + 0 as 'i', + bug20777(9223372036854775806) as '2**63-2', + bug20777(9223372036854775807) as '2**63-1', + bug20777(9223372036854775808) as '2**63', + bug20777(9223372036854775809) as '2**63+1', + bug20777(18446744073709551614) as '2**64-2', + bug20777(18446744073709551615) as '2**64-1', + bug20777(18446744073709551616) as '2**64'; + +insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616); +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create table examplebug20777; +select * from examplebug20777 order by i; + +drop table examplebug20777; +select bug20777(18446744073709551613)+1; +drop function bug20777; +delimiter |; + + +# +# BUG#5274: Stored procedure crash if length of CHAR variable too great. +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug5274_f1| +DROP FUNCTION IF EXISTS bug5274_f2| +--enable_warnings + +# Test. + +CREATE FUNCTION bug5274_f1(p1 CHAR) RETURNS CHAR + RETURN CONCAT(p1, p1)| + +CREATE FUNCTION bug5274_f2() RETURNS CHAR +BEGIN + DECLARE v1 INT DEFAULT 0; + DECLARE v2 CHAR DEFAULT 'x'; + + WHILE v1 < 30 DO + SET v1 = v1 + 1; + SET v2 = bug5274_f1(v2); + END WHILE; + + RETURN v2; +END| + +SELECT bug5274_f2()| + +# Cleanup. + +DROP FUNCTION bug5274_f1| +DROP FUNCTION bug5274_f2| + +# +# Bug#21513 (SP having body starting with quoted label rendered unusable) +# +--disable_warnings ONCE +drop procedure if exists proc_21513| + +create procedure proc_21513()`my_label`:BEGIN END| +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure proc_21513| + +drop procedure proc_21513| + +### +--echo End of 5.0 tests. + +# +# BUG#NNNN: New bug synopsis +# +#--disable_warnings ONCE +#drop procedure if exists bugNNNN| +##create procedure bugNNNN... +# +# Add bugs above this line. Use existing tables t1 and t2 when +# practical, or create table t3,t4 etc temporarily (and drop them). +# NOTE: The delimiter is `|`, and not `;`. It is changed to `;` +# at the end of the file! +# + +delimiter ;| +drop table t1,t2; + +# Disable warnings to allow test run without InnoDB +--disable_warnings +CREATE TABLE t1 (a int auto_increment primary key) engine=MyISAM; +CREATE TABLE t2 (a int auto_increment primary key, b int) engine=innodb; +--enable_warnings +set @a=0; + +--disable_warnings +drop function if exists bug27354; +--enable_warnings +delimiter |; +CREATE function bug27354() RETURNS int not deterministic +begin +insert into t1 values (null); +set @a=@a+1; +return @a; +end| + +delimiter ;| +update t2 set b=1 where a=bug27354(); +select count(t_1.a),count(t_2.a) from t1 as t_1, t2 as t_2 /* must be 0,0 */; +insert into t2 values (1,1),(2,2),(3,3); +update t2 set b=-b where a=bug27354(); +select * from t2 /* must return 1,-1 ... */; +select count(*) from t1 /* must be 3 */; + + +drop table t1,t2; +drop function bug27354; + +# +# Bug #28605: SHOW CREATE VIEW with views using stored_procedures no longer +# showing SP names. +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); + +CREATE FUNCTION metered(a INT) RETURNS INT RETURN 12; + +CREATE VIEW v1 AS SELECT test.metered(a) as metered FROM t1; + +SHOW CREATE VIEW v1; + +DROP VIEW v1; +DROP FUNCTION metered; +DROP TABLE t1; + +# +# Bug#29834: Accessing a view column by name in SP/PS causes a memory leak. +# +# This is leak test. Run with large number assigned to $execute_cnt, +# $p1_cnt, $p2_cnt, @p1_p2_cnt, $f1_normal_cnt or $f1_prep_cnt variables. +# + +let $execute_cnt= 2; +let $p1_cnt= 2; +let $p2_cnt= 2; +SET @p1_p2_cnt= 2; +let $f1_normal_cnt= 2; +let $f1_prep_cnt= 2; + +CREATE TABLE t1 (c1 INT); +CREATE VIEW v1 AS SELECT * FROM t1; + +PREPARE s1 FROM 'SELECT c1 FROM v1'; +while ($execute_cnt) +{ + --error 0,4038 + EXECUTE s1; + dec $execute_cnt; +} + +DELIMITER |; + +CREATE PROCEDURE p1(IN loops BIGINT(19) UNSIGNED) +BEGIN + WHILE loops > 0 DO + SELECT c1 FROM v1; + SET loops = loops - 1; + END WHILE; +END| + +CREATE PROCEDURE p2(IN loops BIGINT(19) UNSIGNED) +BEGIN + WHILE loops > 0 DO + SELECT c1 FROM v1; + CALL p1(@p1_p2_cnt); + SET loops = loops - 1; + END WHILE; +END| + +CREATE FUNCTION f1(loops INT UNSIGNED) + RETURNS INT +BEGIN + DECLARE tmp INT; + WHILE loops > 0 DO + SELECT c1 FROM v1 INTO tmp; + SET loops = loops - 1; + END WHILE; + RETURN loops; +END| + +DELIMITER ;| + +eval CALL p1($p1_cnt); +eval CALL p2($p2_cnt); + +eval SELECT f1($f1_normal_cnt); + +eval PREPARE s1 FROM 'SELECT f1($f1_prep_cnt)'; +EXECUTE s1; +EXECUTE s1; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP FUNCTION f1; +DROP VIEW v1; +DROP TABLE t1; + +# +# Bug#28551 "The warning 'No database selected' is reported when calling +# stored procedures" +# +--disable_warnings ONCE +drop database if exists mysqltest_db1; +create database mysqltest_db1; +create procedure mysqltest_db1.sp_bug28551() begin end; +call mysqltest_db1.sp_bug28551(); +show warnings; +drop database mysqltest_db1; +# +# Bug#29050 Creation of a legal stored procedure fails if a database is not +# selected prior +# +--disable_warnings +drop database if exists mysqltest_db1; +drop table if exists test.t1; +drop procedure if exists test.sp_bug29050; +--enable_warnings +create database mysqltest_db1; +use mysqltest_db1; +# For the sake of its side effect +drop database mysqltest_db1; +# Now we have no current database selected. +create table test.t1 (id int); +insert into test.t1 (id) values (1); +delimiter //; +create procedure test.sp_bug29050() begin select * from t1; end// +delimiter ;// +show warnings; +call test.sp_bug29050(); +show warnings; +# Restore the old current database +use test; +drop procedure sp_bug29050; +drop table t1; + +# +# Bug #30120 SP with local variables with non-ASCII names crashes server. +# +#SET NAMES latin1; + +#DELIMITER |; + +#CREATE PROCEDURE p1() +#BEGIN +# DECLARE ??? INT; +# SELECT ???; +#END| + +#DELIMITER ;| + +#CALL p1(); + +#SET NAMES default; +#DROP PROCEDURE p1; + +# +# Bug#25411 (trigger code truncated) +# + +--disable_warnings +drop procedure if exists proc_25411_a; +drop procedure if exists proc_25411_b; +drop procedure if exists proc_25411_c; +--enable_warnings + +delimiter $$; + +create procedure proc_25411_a() +begin + /* real comment */ + select 1; + /*! select 2; */ + select 3; + /*!00000 select 4; */ + /*!99999 select 5; */ +end +$$ + +create procedure proc_25411_b( +/* real comment */ +/*! p1 int, */ +/*!00000 p2 int */ +/*!99999 ,p3 int */ +) +begin + select p1, p2; +end +$$ + +create procedure proc_25411_c() +begin + select 1/*!,2*//*!00000,3*//*!99999,4*/; + select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/; + select 1/*!,2 *//*!00000,3 *//*!99999,4 */; + select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */; + select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ; +end +$$ + +delimiter ;$$ + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure proc_25411_a; +call proc_25411_a(); + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure proc_25411_b; +select name, param_list, body from mysql.proc where name like "%25411%"; +--error 1318 +call proc_25411_b(10, 20); + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure proc_25411_c; +call proc_25411_c(); + +drop procedure proc_25411_a; +drop procedure proc_25411_b; +drop procedure proc_25411_c; + + +# +# Bug#26302 (MySQL server cuts off trailing "*/" from comments in SP/func) +# + +--disable_warnings ONCE +drop procedure if exists proc_26302; + +create procedure proc_26302() +select 1 /* testing */; + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create procedure proc_26302; + +select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES +where ROUTINE_NAME = "proc_26302"; + +drop procedure proc_26302; + + +# Bug #29338: no optimization for stored functions with a trivial body +# always returning constant. +# + +CREATE FUNCTION f1() RETURNS INT DETERMINISTIC RETURN 2; +CREATE FUNCTION f2(I INT) RETURNS INT DETERMINISTIC RETURN 3; + +CREATE TABLE t1 (c1 INT, INDEX(c1)); + +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); + +CREATE VIEW v1 AS SELECT c1 FROM t1; + +#EXPLAIN SELECT * FROM t1 WHERE c1=1; +#EXPLAIN SELECT * FROM t1 WHERE c1=f1(); + +#EXPLAIN SELECT * FROM t1 WHERE c1=f2(10); +#EXPLAIN SELECT * FROM t1 WHERE c1=f2(c1); +#EXPLAIN SELECT * FROM t1 WHERE c1=f2(rand()); + + +DROP VIEW v1; +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP TABLE t1; + +# +# Bug#29408 Cannot find view in columns table if the selection contains a function +# +delimiter |; + +create function f1() + returns int(11) +not deterministic +contains sql +sql security definer +comment '' +begin + declare x int(11); + set x=-1; + return x; +end| + +delimiter ;| + +create view v1 as select 1 as one, f1() as days; + +connect (bug29408,$OBMYSQL_MS0,root@mysql, ,*NO-ONE*,$OBMYSQL_PORT); +connection bug29408; + +--source mysql_test/include/show_create_table_old_version_replica2.inc +show create view test.v1; +select column_name from information_schema.columns +where table_name='v1' and table_schema='test'; + +disconnect bug29408; +--source mysql_test/include/wait_until_disconnected.inc +connection default; + +drop view v1; +drop function f1; + +# +# Bug#13675: DATETIME/DATE type in store proc param seems to be converted as +# varbinary +# + +--echo +--echo # Bug#13675. +--echo + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; + +DROP TABLE IF EXISTS t1; +--enable_warnings + +--echo +CREATE PROCEDURE p1(v DATETIME) CREATE TABLE t1 SELECT v; + +CREATE PROCEDURE p2(v INT) CREATE TABLE t1 SELECT v; + +--echo +CALL p1(NOW()); +SHOW CREATE TABLE t1; + +--echo +DROP TABLE t1; + +--echo +CALL p1('text'); +SHOW CREATE TABLE t1; + +--echo +DROP TABLE t1; + +--echo +CALL p2(10); +SHOW CREATE TABLE t1; + +--echo +DROP TABLE t1; + +--echo +CALL p2('text'); +SHOW CREATE TABLE t1; + +--echo +DROP TABLE t1; + +--echo +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +########################################################################### + +# +# Bug#31035: select from function, group by result crasher. +# + +########################################################################### + +--echo + +--echo # +--echo # Bug#31035. +--echo # + +--echo + +--echo # +--echo # - Prepare. +--echo # + +--echo + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +--enable_warnings + +--echo + +--echo # +--echo # - Create required objects. +--echo # + +--echo + +CREATE TABLE t1(c1 INT); + +--echo + +INSERT INTO t1 VALUES (1), (2), (3); + +--echo + +CREATE FUNCTION f1() + RETURNS INT + NOT DETERMINISTIC + RETURN 1; + +--echo + +CREATE FUNCTION f2(p INT) + RETURNS INT + NOT DETERMINISTIC + RETURN 1; + +--echo + +CREATE FUNCTION f3() + RETURNS INT + DETERMINISTIC + RETURN 1; + +--echo + +CREATE FUNCTION f4(p INT) + RETURNS INT + DETERMINISTIC + RETURN 1; + +--echo + +--echo # +--echo # - Check. +--echo # + +--echo + +# Not deterministic function, no arguments. + +SELECT f1() AS a FROM t1 GROUP BY a; + +--echo + +# Not deterministic function, non-constant argument. + +SELECT f2(@a) AS a FROM t1 GROUP BY a; + +--echo + +# Deterministic function, no arguments. + +SELECT f3() AS a FROM t1 GROUP BY a; + +--echo + +# Deterministic function, constant argument. + +SELECT f4(0) AS a FROM t1 GROUP BY a; + +--echo + +# Deterministic function, non-constant argument. + +SELECT f4(@a) AS a FROM t1 GROUP BY a; + +--echo + +--echo # +--echo # - Cleanup. +--echo # + +--echo + +DROP TABLE t1; +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; + +--echo + +########################################################################### + +# +# Bug#31191: JOIN in combination with stored function crashes the server. +# + +########################################################################### + +--echo # +--echo # Bug#31191. +--echo # + +--echo + +--echo # +--echo # - Prepare. +--echo # + +--echo + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +--echo + +--echo # +--echo # - Create required objects. +--echo # + +--echo + +CREATE TABLE t1 ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + barcode INT(8) UNSIGNED ZEROFILL nOT NULL, + PRIMARY KEY (id), + UNIQUE KEY barcode (barcode) +); + +--echo + +INSERT INTO t1 (id, barcode) VALUES (1, 12345678); +INSERT INTO t1 (id, barcode) VALUES (2, 12345679); + +--echo + +CREATE TABLE test.t2 ( + id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + barcode BIGINT(11) UNSIGNED ZEROFILL NOT NULL, + PRIMARY KEY (id) +); + +--echo + +INSERT INTO test.t2 (id, barcode) VALUES (1, 12345106708); +INSERT INTO test.t2 (id, barcode) VALUES (2, 12345106709); + +--echo + +CREATE FUNCTION f1(p INT(8)) + RETURNS BIGINT(11) UNSIGNED + READS SQL DATA + RETURN FLOOR(p/1000)*1000000 + 100000 + FLOOR((p MOD 1000)/10)*100 + (p MOD 10); + +--echo + +--echo # +--echo # - Check. +--echo # + +--echo + +SELECT DISTINCT t1.barcode, f1(t1.barcode) +FROM t1 +INNER JOIN t2 +ON f1(t1.barcode) = t2.barcode +WHERE t1.barcode=12345678; + +--echo + +--echo # +--echo # - Cleanup. +--echo # + +--echo + +DROP TABLE t1; +DROP TABLE t2; +DROP FUNCTION f1; + +--echo + +########################################################################### + +# +# Bug#31226: Group by function crashes mysql. +# + +########################################################################### + +--echo # +--echo # Bug#31226. +--echo # + +--echo + +--echo # +--echo # - Prepare. +--echo # + +--echo + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP FUNCTION IF EXISTS f1; +--enable_warnings + +--echo + +--echo # +--echo # - Create required objects. +--echo # + +--echo + +CREATE TABLE t1(id INT); + +--echo + +INSERT INTO t1 VALUES (1), (2), (3); + +--echo + +CREATE FUNCTION f1() + RETURNS DATETIME + NOT DETERMINISTIC NO SQL + RETURN NOW(); + +--echo + +--echo # +--echo # - Check. +--echo # + +--echo + +--replace_column 1 +SELECT f1() FROM t1 GROUP BY 1; + +--echo + +--echo # +--echo # - Cleanup. +--echo # + +--echo + +DROP TABLE t1; +DROP FUNCTION f1; + +--echo + +########################################################################### + +# +# Bug#28318 (CREATE FUNCTION (UDF) requires a schema) +# + +--disable_warnings +--error 1049 +DROP PROCEDURE IF EXISTS db28318_a.t1; +--error 1049 +DROP PROCEDURE IF EXISTS db28318_b.t2; +DROP DATABASE IF EXISTS db28318_a; +DROP DATABASE IF EXISTS db28318_b; +--enable_warnings + +CREATE DATABASE db28318_a; +CREATE DATABASE db28318_b; + +CREATE PROCEDURE db28318_a.t1() SELECT "db28318_a.t1"; +CREATE PROCEDURE db28318_b.t2() CALL t1(); + +use db28318_a; + +# In db28318_b.t2, t1 refers to db28318_b.t1 +--error ER_SP_DOES_NOT_EXIST,1644 +CALL db28318_b.t2(); + +DROP PROCEDURE db28318_a.t1; +DROP PROCEDURE db28318_b.t2; +DROP DATABASE db28318_a; +DROP DATABASE db28318_b; +use test; + +########################################################################### + +# +# Bug#29770 Two handlers are allowed to catch an error in an stored procedure. +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS bug29770; +--enable_warnings + +CREATE TABLE t1(a int); +delimiter |; +CREATE PROCEDURE bug29770() +BEGIN + DECLARE CONTINUE HANDLER FOR SQLSTATE '42S22' SET @state:= 'run'; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @exception:= 'run'; + SELECT x FROM t1; +END| +delimiter ;| +CALL bug29770(); +SELECT @state, @exception; +DROP TABLE t1; +DROP PROCEDURE bug29770; + +# +# Bug#33618 Crash in sp_rcontext +# + +use test; + +--disable_warnings +drop table if exists t_33618; +drop procedure if exists proc_33618; +--enable_warnings + +create table t_33618 (`a` int, unique(`a`), `b` varchar(30)) engine=myisam; +insert into t_33618 (`a`,`b`) values (1,'1'),(2,'2'); + +delimiter //; + +create procedure proc_33618(num int) +begin + declare count1 int default '0'; + declare vb varchar(30); + declare last_row int; + + while(num>=1) do + set num=num-1; + begin + declare cur1 cursor for select `a` from t_33618; + declare continue handler for not found set last_row = 1; + set last_row:=0; + open cur1; + rep1: + repeat + begin + declare exit handler for 1062 begin end; + fetch cur1 into vb; + if (last_row = 1) then + leave rep1; + end if; + end; + until last_row=1 + end repeat; + close cur1; + end; + end while; +end// + +delimiter ;// + +call proc_33618(20); + +drop table t_33618; +drop procedure proc_33618; + +--echo # +--echo # Bug#30787: Stored function ignores user defined alias. +--echo # +use test; +--disable_warnings ONCE +drop function if exists func30787; +create table t1(f1 int); +insert into t1 values(1),(2); +delimiter |; +create function func30787(p1 int) returns int +begin + return p1; +end | +delimiter ;| +select (select func30787(f1)) as ttt from t1; +drop function func30787; +drop table t1; + +# +# Bug #33811: Call to stored procedure with SELECT * / RIGHT JOIN fails +# after the first time +# +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1),(2),(3),(4); + +CREATE PROCEDURE test_sp() + SELECT t1.* FROM t1 RIGHT JOIN t1 t2 ON t1.id=t2.id; + +CALL test_sp(); +CALL test_sp(); + +DROP PROCEDURE test_sp; +DROP TABLE t1; + + +########################################################################### +# +# Bug#38291 memory corruption and server crash with view/sp/function +# + +create table t1(c1 INT); +create function f1(p1 int) returns varchar(32) + return 'aaa'; +create view v1 as select f1(c1) as parent_control_name from t1; + +delimiter //; +create procedure p1() +begin + select parent_control_name as c1 from v1; +end // +delimiter ;// + +call p1(); +call p1(); + +drop procedure p1; +drop function f1; +drop view v1; +drop table t1; + +# +# Bug#38469 invalid memory read and/or crash with utf8 text field, stored procedure, uservar +# +delimiter $; +--disable_warnings ONCE +drop procedure if exists `p2` $ +create procedure `p2`(in `a` varchar(1024) charset utf8) +begin + declare `pos` int default 1; + declare `str` varchar(1024) charset utf8; + set `str` := `a`; + select substr(`str`, `pos`+ 1 ) into `str`; +end $ +delimiter ;$ +call `p2`('s s s s s s'); +drop procedure `p2`; + +# +# Bug#38823: Invalid memory access when a SP statement does wildcard expansion +# + +--disable_warnings +drop table if exists t1; +drop procedure if exists p1; +--enable_warnings + +delimiter $; +create procedure p1() begin select * from t1; end$ +--error ER_NO_SUCH_TABLE +call p1$ +create table t1 (a integer)$ +call p1$ +alter table t1 add b integer; +call p1$ +delimiter ;$ + +drop table t1; +drop procedure p1; + +--echo # ------------------------------------------------------------------ +--echo # -- End of 5.0 tests +--echo # ------------------------------------------------------------------ + +########################################################################### + +# +# Bug#20550: Stored function: wrong RETURN type metadata when used in a VIEW. +# + +########################################################################### + +--echo + +--echo # +--echo # Bug#20550. +--echo # + +--echo + +--echo # +--echo # - Prepare. +--echo # + +--echo + +--disable_warnings +DROP VIEW IF EXISTS v1; +DROP VIEW IF EXISTS v2; +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +--enable_warnings + +--echo + +--echo # +--echo # - Create required objects. +--echo # + +--echo + +CREATE FUNCTION f1() RETURNS VARCHAR(65525) RETURN 'Hello'; + +--echo + +CREATE FUNCTION f2() RETURNS TINYINT RETURN 1; + +--echo + +CREATE VIEW v1 AS SELECT f1(); + +--echo + +CREATE VIEW v2 AS SELECT f2(); + +--echo + +--echo # +--echo # - Check. +--echo # + +--echo +SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'v1'; + +--echo +SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'v2'; + +--echo + +--echo # +--echo # - Cleanup. +--echo # + +--echo + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP VIEW v1; +DROP VIEW v2; + +--echo + +########################################################################### + +# +# Bug#24923: Functions with ENUM issues. +# + +########################################################################### + +--echo # +--echo # - Bug#24923: prepare. +--echo # + +--echo + +--disable_warnings ONCE +DROP FUNCTION IF EXISTS f1; + +--echo + +--echo # +--echo # - Bug#24923: create required objects. +--echo # + +--echo + +delimiter |; + +CREATE FUNCTION f1(p INT) + RETURNS ENUM ('Very_long_enum_element_identifier', + 'Another_very_long_enum_element_identifier') + BEGIN + CASE p + WHEN 1 THEN + RETURN 'Very_long_enum_element_identifier'; + ELSE + RETURN 'Another_very_long_enum_element_identifier'; + END CASE; + END| + +delimiter ;| + +--echo + +--echo # +--echo # - Bug#24923: check. +--echo # + +--echo + +SELECT f1(1); + +--echo +SELECT f1(2); + +--echo + +SHOW CREATE FUNCTION f1; + +--echo # +--echo # - Bug#24923: cleanup. +--echo # + +--echo + +DROP FUNCTION f1; + +--echo + +########################################################################### + +# +# Bug#32633 Can not create any routine if SQL_MODE=no_engine_substitution +# +# Ensure that when new SQL modes are introduced, they are also added to +# the mysql.proc table. +# + +--disable_warnings ONCE +drop procedure if exists p; +set @old_mode= @@sql_mode; +--error 1235 +set @@sql_mode= cast(pow(2,32)-1 as unsigned integer); +select @@sql_mode into @full_mode; +create procedure p() begin end; +call p(); +set @@sql_mode= @old_mode; +# Rename SQL modes that differ in name between the server and the table definition. +select replace(@full_mode, ',,,', ',NOT_USED,') into @full_mode; +select replace(@full_mode, 'ALLOW_INVALID_DATES', 'INVALID_DATES') into @full_mode; +select name from mysql.proc where name = 'p' and sql_mode = @full_mode; +drop procedure p; + +# +# Bug#43962 "Packets out of order" calling a SHOW TABLE STATUS +# +DELIMITER //; +CREATE DEFINER = 'root'@'localhost' PROCEDURE p1() +NOT DETERMINISTIC +CONTAINS SQL +SQL SECURITY DEFINER +COMMENT '' +BEGIN + SHOW TABLE STATUS like 't1'; +END;// +drop procedure p1// +CREATE DEFINER = root PROCEDURE p1() +NOT DETERMINISTIC +CONTAINS SQL +SQL SECURITY DEFINER +COMMENT '' +BEGIN + SHOW TABLE STATUS like 't1'; +END;// +DELIMITER ;// + + +CREATE TABLE t1 (f1 INT); +--disable_result_log +let $tab_count= 4; +while ($tab_count) +{ + EVAL CALL p1(); + dec $tab_count ; +} +--enable_result_log +DROP PROCEDURE p1; +DROP TABLE t1; + +# +# Bug#47649 crash during CALL procedure +# + +CREATE TABLE t1 ( f1 integer, primary key (f1)); +CREATE TABLE t2 LIKE t1; +CREATE TEMPORARY TABLE t3 LIKE t1; +delimiter |; +CREATE PROCEDURE p1 () BEGIN SELECT f1 FROM t3 AS A WHERE A.f1 IN ( SELECT f1 FROM t3 ) ; +END| +delimiter ;| +#--error ER_CANT_REOPEN_TABLE +CALL p1; +DROP TABLE t3; +CREATE VIEW t3 AS SELECT f1 FROM t2 A WHERE A.f1 IN ( SELECT f1 FROM t2 ); +CALL p1; +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1, t2; +DROP VIEW t3; + +--echo # +--echo # Bug #46629: Item_in_subselect::val_int(): Assertion `0' +--echo # on subquery inside a SP +--echo # +CREATE TABLE t1(a INT); +CREATE TABLE t2(a INT, b INT PRIMARY KEY); + +DELIMITER |; +CREATE PROCEDURE p1 () +BEGIN + SELECT a FROM t1 A WHERE A.b IN (SELECT b FROM t2 AS B); +END| +DELIMITER ;| +--error ER_BAD_FIELD_ERROR +CALL p1; +--error ER_BAD_FIELD_ERROR +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1, t2; + +--echo # +--echo # Bug#47627: SET @@{global.session}.local_variable in stored routine causes crash +--echo # Bug#48626: Crash or lost connection using SET for declared variables with @@ +--echo # + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +--enable_warnings + +delimiter //; + +--error 1327 +CREATE PROCEDURE p1() +BEGIN + DECLARE v INT DEFAULT 0; + SET @@SESSION.v= 10; +END// + +CREATE PROCEDURE p2() +BEGIN + DECLARE v INT DEFAULT 0; + SET v= 10; +END// +call p2()// + +CREATE PROCEDURE p3() +BEGIN + DECLARE v INT DEFAULT 0; + SELECT @@SESSION.v; +END// +--error 1193 +call p3()// + +--error 1327 +CREATE PROCEDURE p4() +BEGIN + DECLARE v INT DEFAULT 0; + SET @@GLOBAL.v= 10; +END// + +CREATE PROCEDURE p5() +BEGIN + DECLARE init_connect INT DEFAULT 0; + SET init_connect= 10; + SET @@GLOBAL.init_connect= 'SELECT 1'; + SET @@SESSION.IDENTITY= 1; + SELECT @@SESSION.IDENTITY; + SELECT @@GLOBAL.init_connect; + SELECT init_connect; +END// + +--error 1327 +CREATE PROCEDURE p6() +BEGIN + DECLARE v INT DEFAULT 0; + SET @@v= 0; +END// + +delimiter ;// + +SET @old_init_connect= @@GLOBAL.init_connect; +CALL p5(); +SET @@GLOBAL.init_connect= @old_init_connect; + +DROP PROCEDURE p2; +DROP PROCEDURE p3; +DROP PROCEDURE p5; + + +--echo # +--echo # Bug#11840395 (formerly known as bug#60347): +--echo # The string "versiondata" seems +--echo # to be 'leaking' into the schema name space +--echo # +--disable_warnings ONCE +DROP DATABASE IF EXISTS mixedCaseDbName; +CREATE DATABASE mixedCaseDbName; +DELIMITER |; +CREATE PROCEDURE mixedCaseDbName.tryMyProc() begin end| +CREATE FUNCTION mixedCaseDbName.tryMyFunc() returns varchar(1024) begin return 'IT WORKS'; end +| +DELIMITER ;| +call mixedCaseDbName.tryMyProc(); +select mixedCaseDbName.tryMyFunc(); +DROP DATABASE mixedCaseDbName; + + +--echo # +--echo # Bug#11766594 59736: SELECT DISTINCT.. INCORRECT RESULT WITH DETERMINISTIC FUNCTION IN WHERE C +--echo # + +CREATE TABLE t1 (a INT, b INT, KEY(b)); +CREATE TABLE t2 (c INT, d INT, KEY(c)); +INSERT INTO t1 VALUES (1,1),(1,1),(1,2); +INSERT INTO t2 VALUES (1,1),(1,2); + +DELIMITER $; + +CREATE FUNCTION f1() RETURNS INT DETERMINISTIC +BEGIN + DECLARE a int; + -- SQL statement inside + SELECT 1 INTO a; + RETURN a; +END $ + +DELIMITER ;$ + +SELECT COUNT(DISTINCT d) FROM t1, t2 WHERE a = c AND b = f1(); + +DROP FUNCTION f1; +DROP TABLE t1, t2; + + +--echo # ------------------------------------------------------------------ +--echo # -- End of 5.1 tests +--echo # ------------------------------------------------------------------ + +# +# Bug#39255: Stored procedures: crash if function references nonexistent table +# + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP TABLE IF EXISTS t_non_existing; +DROP TABLE IF EXISTS t1; +--enable_warnings + +delimiter |; +CREATE FUNCTION f1() RETURNS INT +BEGIN + DECLARE v INT; + SELECT a FROM t_non_existing INTO v; + RETURN 1; +END| +delimiter ;| + +CREATE TABLE t1 (a INT) ENGINE = myisam; +INSERT INTO t1 VALUES (1); + +--error ER_NO_SUCH_TABLE +SELECT * FROM t1 WHERE a = f1(); + +DROP FUNCTION f1; +DROP TABLE t1; + +# +# Bug#36649: Condition area is not properly cleaned up after stored routine invocation +# + +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS p1; + +delimiter |; +CREATE PROCEDURE p1(a INT, b CHAR) +BEGIN + IF a > 0 THEN + CALL p1(a-1, 'ab'); + ELSE + SELECT 1; + END IF; +END| +delimiter ;| + +SET @save_max_sp_recursion= @@max_sp_recursion_depth; +SET @@max_sp_recursion_depth= 5; +CALL p1(4, 'a'); +SET @@max_sp_recursion_depth= @save_max_sp_recursion; + +DROP PROCEDURE p1; + +# +# Ensure that rules for message list clean up are being respected. +# + +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS p1; + +delimiter |; +CREATE PROCEDURE p1(a CHAR) +BEGIN + SELECT 1; + SELECT CAST('10 ' as UNSIGNED INTEGER); + SELECT 1; +END| +delimiter ;| + +CALL p1('data truncated parameter'); + +DROP PROCEDURE p1; + +# +# Cascading stored procedure/function calls. +# + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +DROP PROCEDURE IF EXISTS p3; +DROP PROCEDURE IF EXISTS p4; +--enable_warnings + +delimiter |; +CREATE PROCEDURE p1() + CALL p2()| +CREATE PROCEDURE p2() + CALL p3()| +CREATE PROCEDURE p3() + CALL p4()| +CREATE PROCEDURE p4() +BEGIN + SELECT 1; + SELECT CAST('10 ' as UNSIGNED INTEGER); + SELECT 2; +END| +delimiter ;| + +CALL p1(); + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP PROCEDURE p3; +DROP PROCEDURE p4; + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (a CHAR(2)); + +INSERT INTO t1 VALUES ('aa'); + +delimiter |; +CREATE FUNCTION f1() RETURNS CHAR + RETURN (SELECT f2())| +CREATE FUNCTION f2() RETURNS CHAR + RETURN (SELECT f3())| +CREATE FUNCTION f3() RETURNS CHAR + RETURN (SELECT f4())| +CREATE FUNCTION f4() RETURNS CHAR +BEGIN + RETURN (SELECT a FROM t1); +END| +delimiter ;| + +SELECT f1(); + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; +DROP TABLE t1; + +--echo # +--echo # Bug#34197: CREATE PROCEDURE fails when COMMENT truncated in non +--echo # strict SQL mode +--echo # + +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS p1; + +CREATE PROCEDURE p1 () +COMMENT +'12345678901234567890123456789012345678901234567890123456789012345678901234567890' +BEGIN +END; + +SELECT comment FROM mysql.proc WHERE name = "p1" and db = database(); + +# SELECT routine_comment FROM information_schema.routines WHERE routine_name = "p1"; + +DROP PROCEDURE p1; + + +--echo # +--echo # Bug #47313 assert in check_key_in_view during CALL procedure +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP VIEW IF EXISTS t1, t2_unrelated; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); +CREATE VIEW t1 AS SELECT 10 AS f1; + +--echo # t1 refers to the view +--error ER_NON_INSERTABLE_TABLE +CALL p1(1); +#--error 1050 +CREATE TEMPORARY TABLE t1 (f1 INT); + +--echo # t1 still refers to the view since it was inlined +--echo # https://work.aone.alibaba-inc.com/issue/32172786 +#--error ER_NON_INSERTABLE_TABLE +CALL p1(2); + +#--error 1347 +DROP VIEW t1; + +--echo # t1 now refers to the temporary table +#--error 1146 +CALL p1(3); + +--echo # Check which values were inserted into the temp table. +#--error 1146 +SELECT * FROM t1; + +#--error 1051 +DROP TEMPORARY TABLE t1; +--error 1051 +DROP VIEW t1; +DROP PROCEDURE p1; + +--echo # Now test what happens if the sp cache is invalidated. + +--disable_warnings +DROP VIEW IF EXISTS v2_unrelated; +CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); +CREATE VIEW t1 AS SELECT 10 AS f1; +CREATE VIEW v2_unrelated AS SELECT 1 AS r1; + +--echo # Load the procedure into the sp cache +--error ER_NON_INSERTABLE_TABLE +CALL p1(4); + +#--error 1050 +CREATE TEMPORARY TABLE t1 (f1 int); + +ALTER VIEW v2_unrelated AS SELECT 2 AS r1; + +--echo # Alter view causes the sp cache to be invalidated. +--echo # Now t1 refers to the temporary table, not the view. +#--error ER_NON_INSERTABLE_TABLE +CALL p1(5); + +--echo # Check which values were inserted into the temp table. +SELECT * FROM t1; + +#--error 1051 +DROP TEMPORARY TABLE t1; +DROP VIEW t1, v2_unrelated; +DROP PROCEDURE p1; + +CREATE PROCEDURE p1(IN x INT) INSERT INTO t1 VALUES (x); +CREATE TEMPORARY TABLE t1 (f1 INT); + +--echo # t1 refers to the temporary table +CALL p1(6); + +CREATE VIEW t1 AS SELECT 10 AS f1; + +--echo # Create view causes the sp cache to be invalidated. +--echo # t1 still refers to the temporary table since it shadows the view. +CALL p1(7); + +#--error 1347 +DROP VIEW t1; + +--echo # Check which values were inserted into the temp table. +SELECT * FROM t1; + +DROP TEMPORARY TABLE t1; +DROP PROCEDURE p1; + +--echo # +--echo # Bug #11918 Can't use a declared variable in LIMIT clause +--echo # +--disable_warnings +drop table if exists t1; +drop procedure if exists p1; +--enable_warnings +create table t1 (c1 int); +insert into t1 (c1) values (1), (2), (3), (4), (5); + +delimiter |; + +create procedure p1() +begin + declare a integer; + declare b integer; + select * from t1 limit a, b; +end| +delimiter ;| +--echo # How do we handle NULL limit values? + +call p1(); +drop table t1; +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4), (5); +--echo # +--echo # Do we correctly resolve identifiers in LIMIT? +--echo # + +call p1(); +drop table t1; +create table t1 (c1 int); +insert into t1 (c1) values (1), (2), (3), (4), (5); + +drop procedure p1; +--echo # Try to create a procedure that +--echo # refers to non-existing variables. +#--error ER_SP_UNDECLARED_VAR + +create procedure p1(p1 integer, p2 integer) + select * from t1 limit a, b; +--echo # +--echo # Try to use data types not allowed in LIMIT +--echo # +#--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +drop procedure p1; + +create procedure p1(p1 date, p2 date) select * from t1 limit p1, p2; +#--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +drop procedure p1; + +create procedure p1(p1 integer, p2 float) select * from t1 limit p1, p2; +#--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +drop procedure p1; +create procedure p1(p1 integer, p2 char(1)) select * from t1 limit p1, p2; +#--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +drop procedure p1; +create procedure p1(p1 varchar(5), p2 char(1)) select * from t1 limit p1, p2; +#--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +drop procedure p1; +create procedure p1(p1 decimal, p2 decimal) select * from t1 limit p1, p2; +#--error ER_WRONG_SPVAR_TYPE_IN_LIMIT +drop procedure p1; +create procedure p1(p1 double, p2 double) select * from t1 limit p1, p2; + +--echo # +--echo # Finally, test the valid case. +--echo # +drop procedure p1; +create procedure p1(p1 integer, p2 integer) + select * from t1 limit p1, p2; + +call p1(NULL, NULL); +call p1(0, 0); +call p1(0, -1); +call p1(-1, 0); +call p1(-1, -1); +call p1(0, 1); +call p1(1, 0); +call p1(1, 5); +call p1(3, 2); + +delimiter |; +--echo # Try to create a function that +--echo # refers to non-existing variables. +create function f1(p1 integer, p2 integer) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit a, b); + return a; +end| + +drop function f1| + +create function f1() + returns int +begin + declare a, b, c int; + set a = (select count(*) from t1 limit b, c); + return a; +end| + +delimiter ;| +--echo # How do we handle NULL limit values? + +select f1(); + +drop function f1; + +delimiter |; +--echo # +--echo # Try to use data types not allowed in LIMIT +--echo # +create function f1(p1 date, p2 date) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit p1, p2); + return a; +end| + +drop function f1| + +create function f1(p1 integer, p2 float) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit p1, p2); + return a; +end| + +drop function f1| + +create function f1(p1 integer, p2 char(1)) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit p1, p2); + return a; +end| + +drop function f1| + +create function f1(p1 varchar(5), p2 char(1)) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit p1, p2); + return a; +end| + +drop function f1| + +create function f1(p1 decimal, p2 decimal) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit p1, p2); + return a; +end| + +drop function f1| + +create function f1(p1 double, p2 double) + returns int +begin + declare a int; + set a = (select count(*) from t1 limit p1, p2); + return a; +end| + +--echo # +--echo # Finally, test the valid case. +--echo # +drop function f1| + +create function f1(p1 integer, p2 integer) +returns int +begin + declare count int; + set count= (select count(*) from (select * from t1 limit p1, p2) t_1); + return count; +end| + +delimiter ;| + +select f1(0, 0); +select f1(0, -1); +select f1(-1, 0); +select f1(-1, -1); +select f1(0, 1); +select f1(1, 0); +select f1(1, 5); +select f1(3, 2); + +--echo # Cleanup +drop table t1; +drop procedure p1; +drop function f1; + +--echo # +--echo # BUG#11766234: 59299: ASSERT (TABLE_REF->TABLE || TABLE_REF->VIEW) +--echo # FAILS IN SET_FIELD_ITERATOR +--echo # + +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +CREATE VIEW v1 AS SELECT a FROM t2; +--disable_warnings ONCE +DROP PROCEDURE IF EXISTS proc; +CREATE PROCEDURE proc() SELECT * FROM t1 NATURAL JOIN v1; +ALTER TABLE t2 CHANGE COLUMN a b CHAR; + +--echo +--error ER_VIEW_INVALID +CALL proc(); +--error ER_VIEW_INVALID +CALL proc(); + +--echo +DROP TABLE t1,t2; +DROP VIEW v1; +DROP PROCEDURE proc; + + +--echo +--echo # -- +--echo # -- Bug 11765684 - 58674: SP-cache does not detect changes in +--echo # -- pre-locking list caused by triggers +--echo # --- + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE TABLE t1(a INT); +CREATE TABLE t2(a INT); +CREATE TABLE t3(a INT); + +CREATE PROCEDURE p1() + INSERT INTO t1(a) VALUES (1); + +--echo +CREATE TRIGGER t1_ai AFTER INSERT ON t1 + FOR EACH ROW + INSERT INTO t2(a) VALUES (NEW.a); + +--echo +CALL p1(); + +--echo +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 + FOR EACH ROW + INSERT INTO t3(a) VALUES (NEW.a); + +--echo +CALL p1(); + +--echo +DROP TABLE t1, t2, t3; +DROP PROCEDURE p1; +--echo + + +--echo +--echo # -- +--echo # -- Bug#12652769 - 61470: case operator in stored routine retains old +--echo # -- value of input parameter +--echo # --- + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE TABLE t1 (s1 CHAR(5) CHARACTER SET utf8); +INSERT INTO t1 VALUES ('a'); + +delimiter |; + +CREATE PROCEDURE p1(dt DATETIME, i INT) +BEGIN + SELECT + CASE + WHEN i = 1 THEN 2 + ELSE dt + END AS x1; + + SELECT + CASE _binary'a' + WHEN _utf8'a' THEN 'A' + END AS x2; + + SELECT + CASE _utf8'a' + WHEN _binary'a' THEN _utf8'A' + END AS x3; + + SELECT + CASE s1 + WHEN _binary'a' THEN _binary'b' + ELSE _binary'c' + END AS x4 + FROM t1; +END| + +delimiter ;| + +--echo +CALL p1('2011-04-03 05:14:10', 1); +CALL p1('2011-04-03 05:14:11', 2); +CALL p1('2011-04-03 05:14:12', 2); +CALL p1('2011-04-03 05:14:13', 2); + +--echo +DROP TABLE t1; +DROP PROCEDURE p1; +--echo + +--echo # +--echo # Bug#12621017 - Crash if a sp variable is used in the +--echo # limit clause of a set statement +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP PROCEDURE IF EXISTS p1; +DROP PROCEDURE IF EXISTS p2; +--enable_warnings + +CREATE TABLE t1 (c1 INT); +INSERT INTO t1 VALUES (1); + +delimiter |; + +CREATE PROCEDURE p1() +BEGIN + DECLARE foo, cnt INT UNSIGNED DEFAULT 1; + SET foo = (SELECT MIN(c1) FROM t1 LIMIT cnt); +END| + +CREATE PROCEDURE p2() +BEGIN + +DECLARE iLimit INT; +DECLARE iVal INT; + +DECLARE cur1 CURSOR FOR + SELECT c1 FROM t1 + LIMIT iLimit; + +SET iLimit=1; + +OPEN cur1; +FETCH cur1 INTO iVal; + +END| + +delimiter ;| + +CALL p1(); +CALL p2(); + +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; + +--echo +--echo # Bug#13805127: Stored program cache produces wrong result in same THD +--echo + +delimiter |; + +CREATE PROCEDURE p1(x INT UNSIGNED) +BEGIN + SELECT c1, t2.c2, count(c3) + FROM + ( + SELECT 3 as c2 FROM dual WHERE x = 1 + UNION + SELECT 2 FROM dual WHERE x = 1 OR x = 2 + ) AS t1, + ( + SELECT '2012-03-01 01:00:00' AS c1, 3 as c2, 1 as c3 FROM dual + UNION + SELECT '2012-03-01 02:00:00', 3, 2 FROM dual + UNION + SELECT '2012-03-01 01:00:00', 2, 1 FROM dual + ) AS t2 + WHERE t2.c2 = t1.c2 + GROUP BY c1, t2.c2 + ; +END| + +delimiter ;| + +--echo +CALL p1(1); +CALL p1(2); +CALL p1(1); + +DROP PROCEDURE p1; + +--echo # End of 5.5 test + + +--echo # +--echo # Bug#12663165 SP DEAD CODE REMOVAL DOESN'T UNDERSTAND CONTINUE HANDLERS +--echo # + +--disable_warnings ONCE +DROP FUNCTION IF EXISTS f1; + +delimiter $; +CREATE FUNCTION f1() RETURNS INT +BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; + BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f1(); + BEGIN + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION RETURN f1(); + RETURN f1(); + END; + END; +RETURN 1; +END $ +delimiter ;$ + +# This used to cause an assertion. +SELECT f1(); + +DROP FUNCTION f1; + +--echo # +--echo # Bug#12577230 +--echo # RERUN OF STORED FUNCTION CAUSES SEGFAULT IN MAKE_JOIN_SELECT +--echo # + +CREATE TABLE t1 (a INT) ENGINE=myisam; +INSERT INTO t1 VALUES (1); +CREATE VIEW v1 AS SELECT a FROM t1; + +CREATE PROCEDURE p1() +SELECT 1 FROM v1 JOIN t1 ON v1.a +WHERE (SELECT 1 FROM t1 WHERE v1.a) +; + +CALL p1(); +CALL p1(); +DROP PROCEDURE p1; + +DROP TABLE t1; +DROP VIEW v1; + +--echo # +--echo # WL#2111: Add non-reserved ROW_COUNT keyword. +--echo # + +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +DELIMITER |; + +CREATE PROCEDURE p1() +BEGIN + DECLARE row_count INT DEFAULT 1; + SELECT row_count; + SELECT row_count(); + ROW_COUNT: WHILE row_count > 0 DO + SET row_count = row_count - 1; + END WHILE ROW_COUNT; + SELECT ROW_COUNT; +END| + +DELIMITER ;| + +CALL p1(); + +DROP PROCEDURE p1; + +--echo # +--echo # BUG #11748187 - 35410: STORED FUNCTION: CONFUSING 'ORDER CLAUSE' IN ERROR MESSAGE +--echo # + +--disable_warnings +DROP FUNCTION if exists f1; +--enable_warnings +--error 1327 +CREATE FUNCTION f1 (p_value INT) RETURNS INT DETERMINISTIC RETURN x; + +--echo # +--echo # BUG #12872824 (formerly known as 62125): testing stored function +--echo # result for null incorrectly yields 1292 warning. + +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP FUNCTION IF EXISTS f2; +DROP FUNCTION IF EXISTS f3; +DROP FUNCTION IF EXISTS f4; +--enable_warnings + +delimiter /; + +CREATE FUNCTION f1() RETURNS VARCHAR(1) +BEGIN RETURN 'X'; END;/ + +CREATE FUNCTION f2() RETURNS CHAR(1) +BEGIN RETURN 'X'; END;/ + +CREATE FUNCTION f3() RETURNS VARCHAR(1) +BEGIN RETURN NULL; END;/ + +CREATE FUNCTION f4() RETURNS CHAR(1) +BEGIN RETURN NULL; END;/ + +delimiter ;/ + +SELECT f1() IS NULL; +SELECT f2() IS NULL; +SELECT f3() IS NULL; +SELECT f4() IS NULL; + +DROP FUNCTION f1; +DROP FUNCTION f2; +DROP FUNCTION f3; +DROP FUNCTION f4; + +--echo # + +--echo # +--echo # WL#6230: Remove 'SET = DEFAULT' +--echo # + +CREATE TABLE t1(a INT); + +delimiter |; + +#--error ER_PARSE_ERROR +CREATE PROCEDURE p(p INT) + SET p = DEFAULT| +drop procedure p| + +#--error ER_PARSE_ERROR +CREATE PROCEDURE p() +BEGIN + DECLARE v INT; + SET v = DEFAULT; +END| +drop procedure p| + +#--error ER_PARSE_ERROR +CREATE PROCEDURE p() +BEGIN + DECLARE v INT DEFAULT 1; + SET v = DEFAULT; +END| +drop procedure p| + +#--error ER_PARSE_ERROR +CREATE PROCEDURE p() +BEGIN + DECLARE v INT DEFAULT (SELECT * FROM t1); + SET v = DEFAULT; +END| +drop procedure p| + +CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW +BEGIN + SET NEW.a = DEFAULT; +END| + +delimiter ;| + +--echo +--echo # Check that setting system variables to DEFAULT still works in SP. +--echo + +CREATE PROCEDURE p1() + SET @@ob_bnl_join_cache_size = DEFAULT; + +SET @ob_bnl_join_cache_size_saved = @@ob_bnl_join_cache_size; + +SELECT @@ob_bnl_join_cache_size; +SET @@ob_bnl_join_cache_size = 1; +SELECT @@ob_bnl_join_cache_size; + +CALL p1(); + +SELECT @@ob_bnl_join_cache_size; + +SET @@ob_bnl_join_cache_size = @ob_bnl_join_cache_size_saved; + +DROP PROCEDURE p1; + +DROP TABLE t1; + +--echo # End of 5.6 tests +set @@sql_mode=STRICT_ALL_TABLES;