summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2005-12-10 23:31:03 -0800
committerunknown <igor@rurik.mysql.com>2005-12-10 23:31:03 -0800
commit53f8fed437919b82857d4518c43e6e17065786b5 (patch)
tree6b4057c32ab656cc8492feed92caa812a84d4f76 /mysql-test
parente324da302f39998d654b5b112a0342cad0427e35 (diff)
parentf81ed05cdcad5723c986c580cfcf3ee5e22a385c (diff)
downloadmariadb-git-53f8fed437919b82857d4518c43e6e17065786b5.tar.gz
Merge rurik.mysql.com:/home/igor/mysql-5.0
into rurik.mysql.com:/home/igor/dev/mysql-5.0-2 sql/item.cc: Auto merged sql/item.h: Auto merged sql/item_func.cc: Auto merged sql/mysql_priv.h: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_yacc.yy: Auto merged
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/include/sp-vars.inc122
-rw-r--r--mysql-test/r/ctype_ujis.result2
-rw-r--r--mysql-test/r/innodb.result83
-rw-r--r--mysql-test/r/mysqltest.result2
-rw-r--r--mysql-test/r/rpl_deadlock.result2
-rw-r--r--mysql-test/r/rpl_relayrotate.result3
-rw-r--r--mysql-test/r/rpl_until.result2
-rw-r--r--mysql-test/r/schema.result1
-rw-r--r--mysql-test/r/show_check.result1
-rw-r--r--mysql-test/r/skip_name_resolve.result4
-rw-r--r--mysql-test/r/sp-big.result1
-rw-r--r--mysql-test/r/sp-destruct.result77
-rw-r--r--mysql-test/r/sp-dynamic.result2
-rw-r--r--mysql-test/r/sp-error.result77
-rw-r--r--mysql-test/r/sp-vars.result1077
-rw-r--r--mysql-test/r/sp.result223
-rw-r--r--mysql-test/r/sum_distinct-big.result29
-rw-r--r--mysql-test/r/type_binary.result23
-rw-r--r--mysql-test/r/type_newdecimal-big.result31
-rw-r--r--mysql-test/r/view.result23
-rw-r--r--mysql-test/t/alter_table.test2
-rw-r--r--mysql-test/t/backup.test1
-rw-r--r--mysql-test/t/ctype_ujis.test2
-rw-r--r--mysql-test/t/disabled.def3
-rw-r--r--mysql-test/t/innodb.test88
-rw-r--r--mysql-test/t/mysqltest.test8
-rw-r--r--mysql-test/t/rpl_deadlock.test2
-rw-r--r--mysql-test/t/rpl_relayrotate.test3
-rw-r--r--mysql-test/t/rpl_until.test2
-rw-r--r--mysql-test/t/schema.test6
-rw-r--r--mysql-test/t/show_check.test1
-rw-r--r--mysql-test/t/skip_name_resolve.test2
-rw-r--r--mysql-test/t/sp-big.test3
-rw-r--r--mysql-test/t/sp-destruct.test124
-rw-r--r--mysql-test/t/sp-dynamic.test6
-rw-r--r--mysql-test/t/sp-error.test102
-rw-r--r--mysql-test/t/sp-vars.test1273
-rw-r--r--mysql-test/t/sp.test161
-rw-r--r--mysql-test/t/type_binary.test24
-rw-r--r--mysql-test/t/type_newdecimal-big.test31
-rw-r--r--mysql-test/t/view.test1
41 files changed, 3501 insertions, 129 deletions
diff --git a/mysql-test/include/sp-vars.inc b/mysql-test/include/sp-vars.inc
new file mode 100644
index 00000000000..3e02c9d1709
--- /dev/null
+++ b/mysql-test/include/sp-vars.inc
@@ -0,0 +1,122 @@
+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|
+
+---------------------------------------------------------------------------
+
+delimiter ;|
diff --git a/mysql-test/r/ctype_ujis.result b/mysql-test/r/ctype_ujis.result
index 15de93440fc..2e14fe34430 100644
--- a/mysql-test/r/ctype_ujis.result
+++ b/mysql-test/r/ctype_ujis.result
@@ -2317,7 +2317,7 @@ CREATE TABLE t2(c2 char(2)) default charset = ujis;
INSERT INTO t1 VALUES(_ujis 0xA4A2);
CREATE PROCEDURE sp1()
BEGIN
-DECLARE a CHAR(1);
+DECLARE a CHAR(2) CHARSET ujis;
DECLARE cur1 CURSOR FOR SELECT c1 FROM t1;
OPEN cur1;
FETCH cur1 INTO a;
diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result
index aabc83a71b8..0e0e6a20770 100644
--- a/mysql-test/r/innodb.result
+++ b/mysql-test/r/innodb.result
@@ -2437,7 +2437,9 @@ a b
20 NULL
drop table t1;
create table t1 (v varchar(65530), key(v));
-ERROR HY000: Can't create table './test/t1' (errno: 139)
+Warnings:
+Warning 1071 Specified key was too long; max key length is 767 bytes
+drop table t1;
create table t1 (v varchar(65536));
Warnings:
Note 1246 Converting column 'v' from VARCHAR to TEXT
@@ -2577,22 +2579,49 @@ create table t8 (col1 blob, index(col1(767)))
character set = latin1 engine = innodb;
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
character set = latin1 engine = innodb;
+show create table t9;
+Table Create Table
+t9 CREATE TABLE `t9` (
+ `col1` varchar(512) default NULL,
+ `col2` varchar(512) default NULL,
+ KEY `col1` (`col1`,`col2`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
-create table t1 (col1 varchar(768), index (col1))
+create table t1 (col1 varchar(768), index(col1))
character set = latin1 engine = innodb;
-ERROR HY000: Can't create table './test/t1.frm' (errno: 139)
-create table t2 (col1 varchar(768) primary key)
+Warnings:
+Warning 1071 Specified key was too long; max key length is 767 bytes
+create table t2 (col1 varbinary(768), index(col1))
character set = latin1 engine = innodb;
-ERROR HY000: Can't create table './test/t2.frm' (errno: 139)
-create table t3 (col1 varbinary(768) primary key)
+Warnings:
+Warning 1071 Specified key was too long; max key length is 767 bytes
+create table t3 (col1 text, index(col1(768)))
character set = latin1 engine = innodb;
-ERROR HY000: Can't create table './test/t3.frm' (errno: 139)
-create table t4 (col1 text, index(col1(768)))
+Warnings:
+Warning 1071 Specified key was too long; max key length is 767 bytes
+create table t4 (col1 blob, index(col1(768)))
character set = latin1 engine = innodb;
-ERROR HY000: Can't create table './test/t4.frm' (errno: 139)
-create table t5 (col1 blob, index(col1(768)))
+Warnings:
+Warning 1071 Specified key was too long; max key length is 767 bytes
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `col1` varchar(768) default NULL,
+ KEY `col1` (`col1`(767))
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+drop table t1, t2, t3, t4;
+create table t1 (col1 varchar(768) primary key)
+character set = latin1 engine = innodb;
+ERROR 42000: Specified key was too long; max key length is 767 bytes
+create table t2 (col1 varbinary(768) primary key)
+character set = latin1 engine = innodb;
+ERROR 42000: Specified key was too long; max key length is 767 bytes
+create table t3 (col1 text, primary key(col1(768)))
+character set = latin1 engine = innodb;
+ERROR 42000: Specified key was too long; max key length is 767 bytes
+create table t4 (col1 blob, primary key(col1(768)))
character set = latin1 engine = innodb;
-ERROR HY000: Can't create table './test/t5.frm' (errno: 139)
+ERROR 42000: Specified key was too long; max key length is 767 bytes
CREATE TABLE t1
(
id INT PRIMARY KEY
@@ -2772,6 +2801,38 @@ insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
drop table t1;
drop table t2;
commit;
+set foreign_key_checks=0;
+create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
+create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
+ERROR HY000: Can't create table './test/t1.frm' (errno: 150)
+set foreign_key_checks=1;
+drop table t2;
+set foreign_key_checks=0;
+create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
+ERROR HY000: Can't create table './test/t2.frm' (errno: 150)
+set foreign_key_checks=1;
+drop table t1;
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
+create table t1(a varchar(10) primary key) engine = innodb;
+alter table t1 modify column a int;
+Got one of the listed errors
+set foreign_key_checks=1;
+drop table t2,t1;
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
+create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
+alter table t1 convert to character set utf8;
+set foreign_key_checks=1;
+drop table t2,t1;
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
+create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
+rename table t3 to t1;
+ERROR HY000: Error on rename of './test/t3' to './test/t1' (errno: 150)
+set foreign_key_checks=1;
+drop table t2,t3;
create table t1 (a varchar(255) character set utf8,
b varchar(255) character set utf8,
c varchar(255) character set utf8,
diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result
index 56ee329fb28..5ff931dafb5 100644
--- a/mysql-test/r/mysqltest.result
+++ b/mysql-test/r/mysqltest.result
@@ -391,7 +391,7 @@ root@localhost
--------------------------------------------------------------------------------
this will be executed
this will be executed
-mysqltest: At line 2: query 'create table t1 (a int primary key);
+mysqltest: At line 3: query 'create table t1 (a int primary key);
insert into t1 values (1);
select 'select-me';
insertz 'error query'' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insertz 'error query'' at line 1
diff --git a/mysql-test/r/rpl_deadlock.result b/mysql-test/r/rpl_deadlock.result
index b112a51a145..c25cb1e6a53 100644
--- a/mysql-test/r/rpl_deadlock.result
+++ b/mysql-test/r/rpl_deadlock.result
@@ -83,5 +83,5 @@ a
22
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 18911 # # master-bin.000001 Yes Yes 0 0 18911 # None 0 No #
+# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 18911 # # master-bin.000001 # Yes 0 0 18911 # None 0 No #
drop table t1,t2,t3,t4;
diff --git a/mysql-test/r/rpl_relayrotate.result b/mysql-test/r/rpl_relayrotate.result
index c79187e12d0..b038e7b6a3e 100644
--- a/mysql-test/r/rpl_relayrotate.result
+++ b/mysql-test/r/rpl_relayrotate.result
@@ -16,7 +16,4 @@ master_pos_wait('master-bin.001',3000)>=0
select max(a) from t1;
max(a)
8000
-show slave status;
-Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 735186 # # master-bin.000001 Yes Yes 0 0 735186 # None 0 No #
drop table t1;
diff --git a/mysql-test/r/rpl_until.result b/mysql-test/r/rpl_until.result
index 64efeab0145..4a4dcdbb1c0 100644
--- a/mysql-test/r/rpl_until.result
+++ b/mysql-test/r/rpl_until.result
@@ -49,7 +49,7 @@ n
2
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 776 slave-relay-bin.000004 # master-bin.000001 Yes No 0 0 608 # Relay slave-relay-bin.000004 746 No #
+# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 776 slave-relay-bin.000004 # master-bin.000001 # No 0 0 608 # Relay slave-relay-bin.000004 746 No #
start slave;
stop slave;
start slave until master_log_file='master-bin.000001', master_log_pos=776;
diff --git a/mysql-test/r/schema.result b/mysql-test/r/schema.result
index 48e6ebcfad2..538abd8d039 100644
--- a/mysql-test/r/schema.result
+++ b/mysql-test/r/schema.result
@@ -1,3 +1,4 @@
+drop database if exists mysqltest1;
create schema foo;
show create schema foo;
Database Create Database
diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result
index fdb0db602ff..61a820b4469 100644
--- a/mysql-test/r/show_check.result
+++ b/mysql-test/r/show_check.result
@@ -1,6 +1,7 @@
drop table if exists t1,t2;
drop table if exists t1aa,t2aa;
drop database if exists mysqltest;
+drop database if exists mysqltest1;
delete from mysql.user where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3';
delete from mysql.db where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3';
flush privileges;
diff --git a/mysql-test/r/skip_name_resolve.result b/mysql-test/r/skip_name_resolve.result
index a969c5c9ae0..8ef52e75238 100644
--- a/mysql-test/r/skip_name_resolve.result
+++ b/mysql-test/r/skip_name_resolve.result
@@ -10,5 +10,5 @@ user()
#
show processlist;
Id User Host db Command Time State Info
-# root # test Sleep # NULL
-# root # test Query # NULL show processlist
+<id> root <host> test <command> <time> <state> <info>
+<id> root <host> test <command> <time> <state> <info>
diff --git a/mysql-test/r/sp-big.result b/mysql-test/r/sp-big.result
index 1f0b6b34651..9765508859c 100644
--- a/mysql-test/r/sp-big.result
+++ b/mysql-test/r/sp-big.result
@@ -25,6 +25,7 @@ count(*)
select count(*) from t2;
count(*)
0
+drop procedure if exists p1;
create procedure p1()
begin
declare done integer default 0;
diff --git a/mysql-test/r/sp-destruct.result b/mysql-test/r/sp-destruct.result
new file mode 100644
index 00000000000..1b720be9403
--- /dev/null
+++ b/mysql-test/r/sp-destruct.result
@@ -0,0 +1,77 @@
+use test;
+drop procedure if exists bug14233;
+drop function if exists bug14233;
+drop table if exists t1;
+drop view if exists v1;
+create procedure bug14233()
+set @x = 42;
+create function bug14233_f() returns int
+return 42;
+create table t1 (id int);
+create trigger t1_ai after insert on t1 for each row call bug14233();
+alter table mysql.proc drop type;
+call bug14233();
+ERROR HY000: Failed to load routine test.bug14233. The table mysql.proc is missing, corrupt, or contains bad data (internal code -5)
+create view v1 as select bug14233_f();
+ERROR HY000: Failed to load routine test.bug14233_f. The table mysql.proc is missing, corrupt, or contains bad data (internal code -5)
+insert into t1 values (0);
+ERROR HY000: Failed to load routine test.bug14233. The table mysql.proc is missing, corrupt, or contains bad data (internal code -5)
+flush table mysql.proc;
+call bug14233();
+ERROR HY000: Incorrect information in file: './mysql/proc.frm'
+create view v1 as select bug14233_f();
+ERROR HY000: Incorrect information in file: './mysql/proc.frm'
+insert into t1 values (0);
+ERROR HY000: Incorrect information in file: './mysql/proc.frm'
+flush table mysql.proc;
+call bug14233();
+ERROR 42S02: Table 'mysql.proc' doesn't exist
+create view v1 as select bug14233_f();
+ERROR 42S02: Table 'mysql.proc' doesn't exist
+insert into t1 values (0);
+ERROR 42S02: Table 'mysql.proc' doesn't exist
+flush table mysql.proc;
+flush privileges;
+delete from mysql.proc where name like 'bug14233%';
+insert into mysql.proc
+(
+db, name, type, specific_name, language, sql_data_access, is_deterministic,
+security_type, param_list, returns, body, definer, created, modified,
+sql_mode, comment
+)
+values
+(
+'test', 'bug14233_1', 'FUNCTION', 'bug14233_1', 'SQL', 'READS_SQL_DATA', 'NO',
+'DEFINER', '', 'int(10)',
+'select count(*) from mysql.user',
+'root@localhost', NOW() , '0000-00-00 00:00:00', '', ''
+),
+(
+'test', 'bug14233_2', 'FUNCTION', 'bug14233_2', 'SQL', 'READS_SQL_DATA', 'NO',
+'DEFINER', '', 'int(10)',
+'begin declare x int; select count(*) into x from mysql.user; end',
+'root@localhost', NOW() , '0000-00-00 00:00:00', '', ''
+),
+(
+'test', 'bug14233_3', 'PROCEDURE', 'bug14233_3', 'SQL', 'READS_SQL_DATA','NO',
+'DEFINER', '', '',
+'alksj wpsj sa ^#!@ ',
+'root@localhost', NOW() , '0000-00-00 00:00:00', '', ''
+);
+select bug14233_1();
+ERROR HY000: Failed to load routine test.bug14233_1. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+create view v1 as select bug14233_1();
+ERROR HY000: Failed to load routine test.bug14233_1. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+select bug14233_2();
+ERROR HY000: Failed to load routine test.bug14233_2. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+create view v1 as select bug14233_2();
+ERROR HY000: Failed to load routine test.bug14233_2. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+call bug14233_3();
+ERROR HY000: Failed to load routine test.bug14233_3. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+drop trigger t1_ai;
+create trigger t1_ai after insert on t1 for each row call bug14233_3();
+insert into t1 values (0);
+ERROR HY000: Failed to load routine test.bug14233_3. The table mysql.proc is missing, corrupt, or contains bad data (internal code -6)
+delete from mysql.proc where name like 'bug14233%';
+drop trigger t1_ai;
+drop table t1;
diff --git a/mysql-test/r/sp-dynamic.result b/mysql-test/r/sp-dynamic.result
index cf07f540608..c00b09f90e1 100644
--- a/mysql-test/r/sp-dynamic.result
+++ b/mysql-test/r/sp-dynamic.result
@@ -1,3 +1,5 @@
+drop procedure if exists p1|
+drop procedure if exists p2|
create procedure p1()
begin
prepare stmt from "select 1";
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index 963f14820be..d7bed7e88a7 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -124,7 +124,7 @@ begin
declare x int;
set x = val+3;
end|
-ERROR 42000: No RETURN found in FUNCTION f
+ERROR 42000: No RETURN found in FUNCTION test.f
create function f(val int) returns int
begin
declare x int;
@@ -768,7 +768,7 @@ BEGIN
OPTIMIZE TABLE t1;
RETURN 1;
END|
-ERROR 0A000: OPTIMIZE TABLE is not allowed in stored procedures
+ERROR 0A000: Not allowed to return a result set from a function
DROP FUNCTION IF EXISTS bug12995|
CREATE FUNCTION bug12995() RETURNS INT
BEGIN
@@ -981,6 +981,8 @@ END |
drop table t1|
drop function bug_13627_f|
drop function if exists bug12329;
+Warnings:
+Note 1305 FUNCTION bug12329 does not exist
create table t1 as select 1 a;
create table t2 as select 1 a;
create function bug12329() returns int return (select a from t1);
@@ -1055,3 +1057,74 @@ Db Name Type Definer Modified Created Security_type Comment
mysqltest2 p1 PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
drop database mysqltest2;
use test;
+DROP FUNCTION IF EXISTS bug13012|
+CREATE FUNCTION bug13012() RETURNS INT
+BEGIN
+REPAIR TABLE t1;
+RETURN 1;
+END|
+ERROR 0A000: Not allowed to return a result set from a function
+CREATE FUNCTION bug13012() RETURNS INT
+BEGIN
+BACKUP TABLE t1 TO '/tmp';
+RETURN 1;
+END|
+ERROR 0A000: Not allowed to return a result set from a function
+CREATE FUNCTION bug13012() RETURNS INT
+BEGIN
+RESTORE TABLE t1 FROM '/tmp';
+RETURN 1;
+END|
+ERROR 0A000: Not allowed to return a result set from a function
+create table t1 (a int)|
+CREATE PROCEDURE bug13012_1() REPAIR TABLE t1|
+CREATE FUNCTION bug13012_2() RETURNS INT
+BEGIN
+CALL bug13012_1();
+RETURN 1;
+END|
+SELECT bug13012_2()|
+ERROR 0A000: Not allowed to return a result set from a function
+drop table t1|
+drop procedure bug13012_1|
+drop function bug13012_2|
+drop function if exists bug11555_1;
+drop function if exists bug11555_2;
+drop view if exists v1, v2, v3, v4;
+create function bug11555_1() returns int return (select max(i) from t1);
+create function bug11555_2() returns int return bug11555_1();
+create view v1 as select bug11555_1();
+ERROR 42S02: Table 'test.t1' doesn't exist
+create view v2 as select bug11555_2();
+ERROR 42S02: Table 'test.t1' doesn't exist
+create table t1 (i int);
+create view v1 as select bug11555_1();
+create view v2 as select bug11555_2();
+create view v3 as select * from v1;
+drop table t1;
+select * from v1;
+ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+select * from v2;
+ERROR HY000: View 'test.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+select * from v3;
+ERROR HY000: View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+create view v4 as select * from v1;
+ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+drop view v1, v2, v3;
+drop function bug11555_1;
+drop function bug11555_2;
+create table t1 (i int);
+create table t2 (i int);
+create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i);
+create view v1 as select * from t1;
+drop table t2;
+insert into v1 values (1);
+ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+drop trigger t1_ai;
+create function bug11555_1() returns int return (select max(i) from t2);
+create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1();
+insert into v1 values (2);
+ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+drop function bug11555_1;
+drop table t1;
+drop view v1;
diff --git a/mysql-test/r/sp-vars.result b/mysql-test/r/sp-vars.result
new file mode 100644
index 00000000000..6b4d7b1a6d3
--- /dev/null
+++ b/mysql-test/r/sp-vars.result
@@ -0,0 +1,1077 @@
+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;
+SET @@sql_mode = 'ansi';
+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|
+
+---------------------------------------------------------------
+Calling the routines, created in ANSI mode.
+---------------------------------------------------------------
+
+CALL sp_vars_check_dflt();
+v1 v1u v2 v2u v3 v3u v4 v4u
+127 255 -128 0 127 255 -128 0
+v5 v5u v6 v6u
+127 255 -128 0
+v7 v8 v9 v10 v11 v12 v13 v14 v15 v16
+10 10 10 0 0 10 10 10 10 0
+v17 v18 v19 v20
+12.00 12.12 12.00 12.12
+Warnings:
+Warning 1264 Out of range value adjusted for column 'v1' at row 1
+Warning 1264 Out of range value adjusted for column 'v1u' at row 1
+Warning 1264 Out of range value adjusted for column 'v2' at row 1
+Warning 1264 Out of range value adjusted for column 'v2u' at row 1
+Warning 1264 Out of range value adjusted for column 'v3' at row 1
+Warning 1264 Out of range value adjusted for column 'v3u' at row 1
+Warning 1264 Out of range value adjusted for column 'v4' at row 1
+Warning 1264 Out of range value adjusted for column 'v4u' at row 1
+Warning 1264 Out of range value adjusted for column 'v5' at row 1
+Warning 1264 Out of range value adjusted for column 'v5u' at row 1
+Warning 1264 Out of range value adjusted for column 'v6' at row 1
+Warning 1264 Out of range value adjusted for column 'v6u' at row 1
+Warning 1366 Incorrect integer value: 'String 10 ' for column 'v10' at row 1
+Warning 1366 Incorrect integer value: 'String10' for column 'v11' at row 1
+Warning 1265 Data truncated for column 'v12' at row 1
+Warning 1265 Data truncated for column 'v13' at row 1
+Warning 1366 Incorrect integer value: 'Hello, world' for column 'v16' at row 1
+Note 1265 Data truncated for column 'v18' at row 1
+Note 1265 Data truncated for column 'v20' at row 1
+CALL sp_vars_check_assignment();
+i1 i2 i3 i4
+127 -128 127 -128
+i1 i2 i3 i4
+127 -128 127 127
+u1 u2 u3 u4
+255 0 255 0
+u1 u2 u3 u4
+255 0 200 200
+d1 d2 d3
+1234.00 1234.12 1234.12
+d1 d2 d3
+1234.00 1234.12 1234.12
+Warnings:
+Warning 1264 Out of range value adjusted for column 'i1' at row 1
+Warning 1264 Out of range value adjusted for column 'i2' at row 1
+Warning 1264 Out of range value adjusted for column 'i3' at row 1
+Warning 1264 Out of range value adjusted for column 'i4' at row 1
+Warning 1264 Out of range value adjusted for column 'i1' at row 1
+Warning 1264 Out of range value adjusted for column 'i2' at row 1
+Warning 1264 Out of range value adjusted for column 'i3' at row 1
+Warning 1264 Out of range value adjusted for column 'i4' at row 1
+Warning 1264 Out of range value adjusted for column 'u1' at row 1
+Warning 1264 Out of range value adjusted for column 'u2' at row 1
+Warning 1264 Out of range value adjusted for column 'u3' at row 1
+Warning 1264 Out of range value adjusted for column 'u4' at row 1
+Warning 1264 Out of range value adjusted for column 'u1' at row 1
+Warning 1264 Out of range value adjusted for column 'u2' at row 1
+Note 1265 Data truncated for column 'd3' at row 1
+Note 1265 Data truncated for column 'd3' at row 1
+SELECT sp_vars_check_ret1();
+sp_vars_check_ret1()
+127
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sp_vars_check_ret1()' at row 1
+SELECT sp_vars_check_ret2();
+sp_vars_check_ret2()
+127
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sp_vars_check_ret2()' at row 1
+SELECT sp_vars_check_ret3();
+sp_vars_check_ret3()
+0
+Warnings:
+Warning 1366 Incorrect integer value: 'Hello, world' for column 'sp_vars_check_ret3()' at row 1
+SELECT sp_vars_check_ret4();
+sp_vars_check_ret4()
+154.12
+Warnings:
+Note 1265 Data truncated for column 'sp_vars_check_ret4()' at row 1
+SET @@sql_mode = 'traditional';
+
+---------------------------------------------------------------
+Calling in TRADITIONAL mode the routines, created in ANSI mode.
+---------------------------------------------------------------
+
+CALL sp_vars_check_dflt();
+v1 v1u v2 v2u v3 v3u v4 v4u
+127 255 -128 0 127 255 -128 0
+v5 v5u v6 v6u
+127 255 -128 0
+v7 v8 v9 v10 v11 v12 v13 v14 v15 v16
+10 10 10 0 0 10 10 10 10 0
+v17 v18 v19 v20
+12.00 12.12 12.00 12.12
+Warnings:
+Warning 1264 Out of range value adjusted for column 'v1' at row 1
+Warning 1264 Out of range value adjusted for column 'v1u' at row 1
+Warning 1264 Out of range value adjusted for column 'v2' at row 1
+Warning 1264 Out of range value adjusted for column 'v2u' at row 1
+Warning 1264 Out of range value adjusted for column 'v3' at row 1
+Warning 1264 Out of range value adjusted for column 'v3u' at row 1
+Warning 1264 Out of range value adjusted for column 'v4' at row 1
+Warning 1264 Out of range value adjusted for column 'v4u' at row 1
+Warning 1264 Out of range value adjusted for column 'v5' at row 1
+Warning 1264 Out of range value adjusted for column 'v5u' at row 1
+Warning 1264 Out of range value adjusted for column 'v6' at row 1
+Warning 1264 Out of range value adjusted for column 'v6u' at row 1
+Warning 1366 Incorrect integer value: 'String 10 ' for column 'v10' at row 1
+Warning 1366 Incorrect integer value: 'String10' for column 'v11' at row 1
+Warning 1265 Data truncated for column 'v12' at row 1
+Warning 1265 Data truncated for column 'v13' at row 1
+Warning 1366 Incorrect integer value: 'Hello, world' for column 'v16' at row 1
+Note 1265 Data truncated for column 'v18' at row 1
+Note 1265 Data truncated for column 'v20' at row 1
+CALL sp_vars_check_assignment();
+i1 i2 i3 i4
+127 -128 127 -128
+i1 i2 i3 i4
+127 -128 127 127
+u1 u2 u3 u4
+255 0 255 0
+u1 u2 u3 u4
+255 0 200 200
+d1 d2 d3
+1234.00 1234.12 1234.12
+d1 d2 d3
+1234.00 1234.12 1234.12
+Warnings:
+Warning 1264 Out of range value adjusted for column 'i1' at row 1
+Warning 1264 Out of range value adjusted for column 'i2' at row 1
+Warning 1264 Out of range value adjusted for column 'i3' at row 1
+Warning 1264 Out of range value adjusted for column 'i4' at row 1
+Warning 1264 Out of range value adjusted for column 'i1' at row 1
+Warning 1264 Out of range value adjusted for column 'i2' at row 1
+Warning 1264 Out of range value adjusted for column 'i3' at row 1
+Warning 1264 Out of range value adjusted for column 'i4' at row 1
+Warning 1264 Out of range value adjusted for column 'u1' at row 1
+Warning 1264 Out of range value adjusted for column 'u2' at row 1
+Warning 1264 Out of range value adjusted for column 'u3' at row 1
+Warning 1264 Out of range value adjusted for column 'u4' at row 1
+Warning 1264 Out of range value adjusted for column 'u1' at row 1
+Warning 1264 Out of range value adjusted for column 'u2' at row 1
+Note 1265 Data truncated for column 'd3' at row 1
+Note 1265 Data truncated for column 'd3' at row 1
+SELECT sp_vars_check_ret1();
+sp_vars_check_ret1()
+127
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sp_vars_check_ret1()' at row 1
+SELECT sp_vars_check_ret2();
+sp_vars_check_ret2()
+127
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sp_vars_check_ret2()' at row 1
+SELECT sp_vars_check_ret3();
+sp_vars_check_ret3()
+0
+Warnings:
+Warning 1366 Incorrect integer value: 'Hello, world' for column 'sp_vars_check_ret3()' at row 1
+SELECT sp_vars_check_ret4();
+sp_vars_check_ret4()
+154.12
+Warnings:
+Note 1265 Data truncated for column 'sp_vars_check_ret4()' at row 1
+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;
+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|
+
+---------------------------------------------------------------
+Calling the routines, created in TRADITIONAL mode.
+---------------------------------------------------------------
+
+CALL sp_vars_check_dflt();
+ERROR 22003: Out of range value adjusted for column 'v1' at row 1
+CALL sp_vars_check_assignment();
+ERROR 22003: Out of range value adjusted for column 'i1' at row 1
+SELECT sp_vars_check_ret1();
+ERROR 22003: Out of range value adjusted for column 'sp_vars_check_ret1()' at row 1
+SELECT sp_vars_check_ret2();
+ERROR 22003: Out of range value adjusted for column 'sp_vars_check_ret2()' at row 1
+SELECT sp_vars_check_ret3();
+ERROR HY000: Incorrect integer value: 'Hello, world' for column 'sp_vars_check_ret3()' at row 1
+SELECT sp_vars_check_ret4();
+sp_vars_check_ret4()
+154.12
+Warnings:
+Note 1265 Data truncated for column 'sp_vars_check_ret4()' at row 1
+SET @@sql_mode = 'ansi';
+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;
+
+---------------------------------------------------------------
+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)
+01
+HEX(v2)
+00
+HEX(v3)
+05
+HEX(v4)
+5555555555555555
+HEX(v5)
+07
+HEX(v6)
+0000000000000005
+HEX(v7)
+80
+HEX(v8)
+FF
+HEX(v9)
+FF
+HEX(v10)
+FF
+Warnings:
+Warning 1264 Out of range value adjusted for column 'v8' at row 1
+Warning 1264 Out of range value adjusted for column 'v9' at row 1
+Warning 1264 Out of range value adjusted for column 'v10' at row 1
+Warning 1264 Out of range value adjusted for column 'v1' at row 1
+Warning 1264 Out of range value adjusted for column 'v5' at row 1
+DROP PROCEDURE p1;
+
+---------------------------------------------------------------
+CASE expression tests.
+---------------------------------------------------------------
+
+DROP PROCEDURE IF EXISTS p1;
+Warnings:
+Note 1305 PROCEDURE p1 does not exist
+DROP PROCEDURE IF EXISTS p2;
+Warnings:
+Note 1305 PROCEDURE p2 does not exist
+DROP TABLE IF EXISTS t1;
+Warnings:
+Note 1051 Unknown table 't1'
+CREATE TABLE t1(log_msg VARCHAR(1024));
+CREATE PROCEDURE p1(arg VARCHAR(255))
+BEGIN
+INSERT INTO t1 VALUES('p1: step1');
+CASE arg * 10
+WHEN 10 * 10 THEN
+INSERT INTO t1 VALUES('p1: case1: on 10');
+WHEN 10 * 10 + 10 * 10 THEN
+BEGIN
+CASE arg / 10
+WHEN 1 THEN
+INSERT INTO t1 VALUES('p1: case1: case2: on 1');
+WHEN 2 THEN
+BEGIN
+DECLARE i TINYINT DEFAULT 10;
+WHILE i > 0 DO
+INSERT INTO t1 VALUES(CONCAT('p1: case1: case2: loop: i: ', i));
+CASE MOD(i, 2)
+WHEN 0 THEN
+INSERT INTO t1 VALUES('p1: case1: case2: loop: i is even');
+WHEN 1 THEN
+INSERT INTO t1 VALUES('p1: case1: case2: loop: i is odd');
+ELSE
+INSERT INTO t1 VALUES('p1: case1: case2: loop: ERROR');
+END CASE;
+SET i = i - 1;
+END WHILE;
+END;
+ELSE
+INSERT INTO t1 VALUES('p1: case1: case2: ERROR');
+END CASE;
+CASE arg
+WHEN 10 THEN
+INSERT INTO t1 VALUES('p1: case1: case3: on 10');
+WHEN 20 THEN
+INSERT INTO t1 VALUES('p1: case1: case3: on 20');
+ELSE
+INSERT INTO t1 VALUES('p1: case1: case3: ERROR');
+END CASE;
+END;
+ELSE
+INSERT INTO t1 VALUES('p1: case1: ERROR');
+END CASE;
+CASE arg * 10
+WHEN 10 * 10 THEN
+INSERT INTO t1 VALUES('p1: case4: on 10');
+WHEN 10 * 10 + 10 * 10 THEN
+BEGIN
+CASE arg / 10
+WHEN 1 THEN
+INSERT INTO t1 VALUES('p1: case4: case5: on 1');
+WHEN 2 THEN
+BEGIN
+DECLARE i TINYINT DEFAULT 10;
+WHILE i > 0 DO
+INSERT INTO t1 VALUES(CONCAT('p1: case4: case5: loop: i: ', i));
+CASE MOD(i, 2)
+WHEN 0 THEN
+INSERT INTO t1 VALUES('p1: case4: case5: loop: i is even');
+WHEN 1 THEN
+INSERT INTO t1 VALUES('p1: case4: case5: loop: i is odd');
+ELSE
+INSERT INTO t1 VALUES('p1: case4: case5: loop: ERROR');
+END CASE;
+SET i = i - 1;
+END WHILE;
+END;
+ELSE
+INSERT INTO t1 VALUES('p1: case4: case5: ERROR');
+END CASE;
+CASE arg
+WHEN 10 THEN
+INSERT INTO t1 VALUES('p1: case4: case6: on 10');
+WHEN 20 THEN
+INSERT INTO t1 VALUES('p1: case4: case6: on 20');
+ELSE
+INSERT INTO t1 VALUES('p1: case4: case6: ERROR');
+END CASE;
+END;
+ELSE
+INSERT INTO t1 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 VALUES('p2: case: numerical type');
+WHEN 'test' THEN
+INSERT INTO t1 VALUES('p2: case: string type');
+ELSE
+INSERT INTO t1 VALUES('p2: case: ERROR');
+END CASE;
+SET i = i - 1;
+END WHILE;
+END|
+CALL p1(10);
+CALL p1(20);
+CALL p2();
+SELECT * FROM t1;
+log_msg
+p1: step1
+p1: case1: on 10
+p1: case4: on 10
+p1: step1
+p1: case1: case2: loop: i: 10
+p1: case1: case2: loop: i is even
+p1: case1: case2: loop: i: 9
+p1: case1: case2: loop: i is odd
+p1: case1: case2: loop: i: 8
+p1: case1: case2: loop: i is even
+p1: case1: case2: loop: i: 7
+p1: case1: case2: loop: i is odd
+p1: case1: case2: loop: i: 6
+p1: case1: case2: loop: i is even
+p1: case1: case2: loop: i: 5
+p1: case1: case2: loop: i is odd
+p1: case1: case2: loop: i: 4
+p1: case1: case2: loop: i is even
+p1: case1: case2: loop: i: 3
+p1: case1: case2: loop: i is odd
+p1: case1: case2: loop: i: 2
+p1: case1: case2: loop: i is even
+p1: case1: case2: loop: i: 1
+p1: case1: case2: loop: i is odd
+p1: case1: case3: on 20
+p1: case4: case5: loop: i: 10
+p1: case4: case5: loop: i is even
+p1: case4: case5: loop: i: 9
+p1: case4: case5: loop: i is odd
+p1: case4: case5: loop: i: 8
+p1: case4: case5: loop: i is even
+p1: case4: case5: loop: i: 7
+p1: case4: case5: loop: i is odd
+p1: case4: case5: loop: i: 6
+p1: case4: case5: loop: i is even
+p1: case4: case5: loop: i: 5
+p1: case4: case5: loop: i is odd
+p1: case4: case5: loop: i: 4
+p1: case4: case5: loop: i is even
+p1: case4: case5: loop: i: 3
+p1: case4: case5: loop: i is odd
+p1: case4: case5: loop: i: 2
+p1: case4: case5: loop: i is even
+p1: case4: case5: loop: i: 1
+p1: case4: case5: loop: i is odd
+p1: case4: case6: on 20
+p2: case: string type
+p2: case: numerical type
+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
+18446744073709551614
+col
+18446744073709551614
+col
+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
+Warnings:
+Warning 1265 Data truncated for column 'y' at row 1
+DROP PROCEDURE p1;
+
+---------------------------------------------------------------
+BUG#13675
+---------------------------------------------------------------
+
+DROP PROCEDURE IF EXISTS p1;
+DROP TABLE IF EXISTS t1;
+CREATE PROCEDURE p1(x DATETIME)
+BEGIN
+CREATE TABLE t1 SELECT x;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+END|
+CALL p1(NOW());
+Table Create Table
+t1 CREATE TABLE "t1" (
+ "x" varbinary(19) default NULL
+)
+CALL p1('test');
+Table Create Table
+t1 CREATE TABLE "t1" (
+ "x" varbinary(19) default NULL
+)
+Warnings:
+Warning 1264 Out of range value adjusted for column 'x' at row 1
+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 INTO vb FROM t1 WHERE b = 0;
+SELECT HEX(vb),
+vb = 0,
+vb = FALSE,
+vb IS FALSE,
+vb = 1,
+vb = TRUE,
+vb IS TRUE;
+SELECT b INTO vb FROM t1 WHERE b = 1;
+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
+00 1 1 1 0 0 0
+HEX(vb) vb = 0 vb = FALSE vb IS FALSE vb = 1 vb = TRUE vb IS TRUE
+01 0 0 1 1 1 0
+DROP TABLE t1;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+
+---------------------------------------------------------------
+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';
+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 adjusted for column 'v' at row 1
+CALL p2();
+ERROR 22003: Out of range value adjusted for column 'v' at row 1
+CALL p3();
+ERROR 22001: Data too long for column 'v' at row 1
+CALL p4('aaa');
+ERROR 22001: Data too long for column 'arg' at row 1
+CALL p5('aa');
+ERROR 22001: Data too long for column 'var' at row 1
+CALL p6(10);
+ERROR 22003: Out of range value adjusted for column 'var' at row 1
+SET @@sql_mode = 'ansi';
+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
+Warnings:
+Note 1265 Data truncated for column 'arg' at row 1
+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
+Warnings:
+Warning 1264 Out of range value adjusted for column 'arg' at row 1
+SET @@sql_mode = 'traditional';
+SELECT f1(-2500);
+ERROR 22003: Out of range value adjusted for column 'arg' at row 1
+DROP FUNCTION f1;
+CREATE FUNCTION f1(arg TINYINT UNSIGNED) RETURNS TINYINT
+BEGIN
+RETURN arg;
+END|
+SELECT f1(-2500);
+ERROR 22003: Out of range value adjusted for column 'arg' at row 1
+SET @@sql_mode = 'ansi';
+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
+Warnings:
+Warning 1264 Out of range value adjusted for column 'arg' at row 1
+SET @@sql_mode = 'traditional';
+SELECT f1(8388699);
+ERROR 22003: Out of range value adjusted for column 'arg' at row 1
+DROP FUNCTION f1;
+CREATE FUNCTION f1(arg MEDIUMINT) RETURNS MEDIUMINT
+BEGIN
+RETURN arg;
+END|
+SELECT f1(8388699);
+ERROR 22003: Out of range value adjusted for column 'arg' at row 1
+SET @@sql_mode = 'ansi';
+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 INTO sp_var FROM t1 LIMIT 1;
+SET @user_var = sp_var;
+SELECT sp_var;
+SELECT @user_var;
+END|
+CALL p1();
+sp_var
+0
+@user_var
+0
+Warnings:
+Warning 1264 Out of range value adjusted for column 'sp_var' at row 1
+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;
+
+---------------------------------------------------------------
+BUG#13808
+---------------------------------------------------------------
+
+DROP PROCEDURE IF EXISTS p1;
+DROP PROCEDURE IF EXISTS p2;
+DROP FUNCTION IF EXISTS f1;
+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|
+CALL p1('c');
+arg
+
+Warnings:
+Warning 1265 Data truncated for column 'arg' at row 1
+CALL p2('a');
+arg var
+a
+Warnings:
+Warning 1265 Data truncated for column 'var' at row 1
+SELECT f1('a');
+f1('a')
+
+Warnings:
+Warning 1265 Data truncated for column 'f1('a')' at row 1
+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)
+latin1
+CALL p1(_UTF8 't');
+CHARSET(arg)
+latin1
+CALL p2('t');
+CHARSET(arg)
+utf8
+CALL p2(_LATIN1 't');
+CHARSET(arg)
+utf8
+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)
+4100 42
+HEX(var1) HEX(var2)
+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)
+CALL p1((SELECT * FROM t1 LIMIT 1));
+ERROR 21000: Operand should contain 1 column(s)
+CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));
+ERROR 21000: Operand should contain 1 column(s)
+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;
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index 6f0a8623a4c..ded9754f172 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -248,13 +248,13 @@ 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|
id data
sub1a 7
sub1b 3
-sub1c 1
sub1d 1
sub2 6
select sub3((select max(i) from t2))|
@@ -2686,7 +2686,7 @@ call bug8937()|
s x y z
16 3 1 6
a
-3.2000
+3.2
drop procedure bug8937|
delete from t1|
drop procedure if exists bug6900|
@@ -2890,21 +2890,30 @@ 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
+Warnings:
+Warning 1265 Data truncated for column 'bug9775('c')' at row 1
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
+Warnings:
+Warning 1265 Data truncated for column 'bug9775(3)' at row 1
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,b
+a b a
+Warnings:
+Warning 1265 Data truncated for column 'v1' at row 1
+Warning 1265 Data truncated for column 'bug9775('c')' at row 1
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
+Warnings:
+Warning 1265 Data truncated for column 'bug9775(4)' at row 1
drop function bug9775|
drop function if exists bug8861|
create function bug8861(v1 int) returns year return v1|
@@ -2927,12 +2936,10 @@ create procedure bug9004_2(x char(16))
call bug9004_1(x)|
call bug9004_1('12345678901234567')|
Warnings:
-Warning 1265 Data truncated for column 'id' at row 1
-Warning 1265 Data truncated for column 'id' at row 2
+Warning 1265 Data truncated for column 'x' at row 1
call bug9004_2('12345678901234567890')|
Warnings:
-Warning 1265 Data truncated for column 'id' at row 1
-Warning 1265 Data truncated for column 'id' at row 2
+Warning 1265 Data truncated for column 'x' at row 1
delete from t1|
drop procedure bug9004_1|
drop procedure bug9004_2|
@@ -3527,14 +3534,15 @@ end|
call bug12589_1()|
Table Create Table
tm1 CREATE TEMPORARY TABLE `tm1` (
- `spv1` decimal(1,0) unsigned default NULL
+ `spv1` decimal(3,3) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Warnings:
-Warning 1292 Truncated incorrect DECIMAL value: 'test'
+Warning 1264 Out of range value adjusted for column 'spv1' at row 1
+Warning 1366 Incorrect decimal value: 'test' for column 'spv1' at row 1
call bug12589_2()|
Table Create Table
tm1 CREATE TEMPORARY TABLE `tm1` (
- `spv1` decimal(6,3) unsigned default NULL
+ `spv1` decimal(6,3) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
call bug12589_3()|
Table Create Table
@@ -4016,34 +4024,37 @@ create procedure bug14643_1()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
begin
-declare v int default x;
+declare v int default undefined_var;
if v = 1 then
select 1;
else
-select 2;
+select v, isnull(v);
end if;
end;
end|
create procedure bug14643_2()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
-case x
+case undefined_var
when 1 then
select 1;
else
select 2;
end case;
+select undefined_var;
end|
call bug14643_1()|
Handler
boo
-2
-2
+v isnull(v)
+NULL 1
call bug14643_2()|
Handler
boo
2
2
+Handler
+boo
drop procedure bug14643_1|
drop procedure bug14643_2|
drop procedure if exists bug14304|
@@ -4099,25 +4110,23 @@ call bug14376(4711)|
x
4711
drop procedure bug14376|
-drop procedure if exists p1|
-Warnings:
-Note 1305 PROCEDURE p1 does not exist
-drop table if exists t1|
-create table t1 (a varchar(255))|
-insert into t1 (a) values ("a - table column")|
-create procedure p1(a varchar(255))
+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 t1;
+declare c cursor for select a from t3;
select a;
-select a from t1 into i;
+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 t1;
+declare c1 cursor for select a from t3;
select a as 'A local variable takes precedence over parameter';
open c1;
fetch c1 into i;
@@ -4125,9 +4134,9 @@ 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 t1;
+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 t1 into i;
+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;
@@ -4136,7 +4145,7 @@ select i as 'A local variable in a nested compound statement takes precedence o
end;
end;
end|
-call p1("a - stored procedure parameter")|
+call bug5967("a - stored procedure parameter")|
a
a - stored procedure parameter
Parameter takes precedence over table column
@@ -4153,4 +4162,162 @@ A local variable in a nested compound statement takes precedence over table colu
a - local variable in a nested compound statement
A local variable in a nested compound statement takes precedence over table column in cursors
a - local variable in a nested compound statement
+drop procedure bug5967|
+drop procedure if exists bug13012|
+create procedure bug13012()
+BEGIN
+REPAIR TABLE t1;
+BACKUP TABLE t1 to '../tmp';
+DROP TABLE t1;
+RESTORE TABLE t1 FROM '../tmp';
+END|
+call bug13012()|
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+Table Op Msg_type Msg_text
+test.t1 backup status OK
+Table Op Msg_type Msg_text
+test.t1 restore status OK
+drop procedure bug13012|
+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|
+call bug13012()|
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+test.t2 repair status OK
+test.t3 repair status OK
+test.v1 repair error 'test.v1' is not BASE TABLE
+Table Op Msg_type Msg_text
+test.t1 optimize status OK
+test.t2 optimize status OK
+test.t3 optimize status OK
+test.v1 optimize error 'test.v1' is not BASE TABLE
+Table Op Msg_type Msg_text
+test.t1 analyze status Table is already up to date
+test.t2 analyze status Table is already up to date
+test.t3 analyze status Table is already up to date
+test.v1 analyze error 'test.v1' is not BASE TABLE
+Warnings:
+Error 1347 'test.v1' is not BASE TABLE
+call bug13012()|
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+test.t2 repair status OK
+test.t3 repair status OK
+test.v1 repair error 'test.v1' is not BASE TABLE
+Table Op Msg_type Msg_text
+test.t1 optimize status OK
+test.t2 optimize status OK
+test.t3 optimize status OK
+test.v1 optimize error 'test.v1' is not BASE TABLE
+Table Op Msg_type Msg_text
+test.t1 analyze status Table is already up to date
+test.t2 analyze status Table is already up to date
+test.t3 analyze status Table is already up to date
+test.v1 analyze error 'test.v1' is not BASE TABLE
+Warnings:
+Error 1347 'test.v1' is not BASE TABLE
+call bug13012()|
+Table Op Msg_type Msg_text
+test.t1 repair status OK
+test.t2 repair status OK
+test.t3 repair status OK
+test.v1 repair error 'test.v1' is not BASE TABLE
+Table Op Msg_type Msg_text
+test.t1 optimize status OK
+test.t2 optimize status OK
+test.t3 optimize status OK
+test.v1 optimize error 'test.v1' is not BASE TABLE
+Table Op Msg_type Msg_text
+test.t1 analyze status Table is already up to date
+test.t2 analyze status Table is already up to date
+test.t3 analyze status Table is already up to date
+test.v1 analyze error 'test.v1' is not BASE TABLE
+Warnings:
+Error 1347 'test.v1' is not BASE TABLE
+drop procedure bug13012|
+drop view v1;
+select * from t1|
+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 text)
+begin
+declare lsql text;
+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 for PROCEDURE mysqltest3.p3; expected 1, got 2
+call mysqltest1.p1(@rs)|
+ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2
+call mysqltest1.p1(@rs)|
+ERROR 42000: Incorrect number of arguments for PROCEDURE mysqltest3.p3; expected 1, got 2
+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
+1 Yale
+id county
+2 NULL
+drop table t3|
+drop procedure bug15441|
drop table t1,t2;
diff --git a/mysql-test/r/sum_distinct-big.result b/mysql-test/r/sum_distinct-big.result
index 06bfc6b1f78..9b55d59ab91 100644
--- a/mysql-test/r/sum_distinct-big.result
+++ b/mysql-test/r/sum_distinct-big.result
@@ -1,5 +1,4 @@
-using_big_test
-0
+DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (id INTEGER);
CREATE TABLE t2 (id INTEGER);
INSERT INTO t1 (id) VALUES (1), (1), (1),(1);
@@ -40,19 +39,19 @@ AVG(DISTINCT id)
512.5000
SELECT SUM(DISTINCT id)/COUNT(DISTINCT id) FROM t1 GROUP BY id % 13;
SUM(DISTINCT id)/COUNT(DISTINCT id)
-513.50000
-508.00000
-509.00000
-510.00000
-511.00000
-512.00000
-513.00000
-514.00000
-515.00000
-516.00000
-517.00000
-511.50000
-512.50000
+513.5000
+508.0000
+509.0000
+510.0000
+511.0000
+512.0000
+513.0000
+514.0000
+515.0000
+516.0000
+517.0000
+511.5000
+512.5000
INSERT INTO t1 SELECT id+1024 FROM t1;
INSERT INTO t1 SELECT id+2048 FROM t1;
INSERT INTO t1 SELECT id+4096 FROM t1;
diff --git a/mysql-test/r/type_binary.result b/mysql-test/r/type_binary.result
index 1c60bf46608..597defb7a9b 100644
--- a/mysql-test/r/type_binary.result
+++ b/mysql-test/r/type_binary.result
@@ -114,3 +114,26 @@ drop table t1;
select hex(cast(0x10 as binary(2)));
hex(cast(0x10 as binary(2)))
1000
+create table t1 (b binary(2), vb varbinary(2));
+insert into t1 values(0x4120, 0x4120);
+insert into t1 values(0x412020, 0x412020);
+Warnings:
+Warning 1265 Data truncated for column 'b' at row 1
+Warning 1265 Data truncated for column 'vb' at row 1
+drop table t1;
+create table t1 (c char(2), vc varchar(2));
+insert into t1 values(0x4120, 0x4120);
+insert into t1 values(0x412020, 0x412020);
+Warnings:
+Note 1265 Data truncated for column 'vc' at row 1
+drop table t1;
+set @old_sql_mode= @@sql_mode, sql_mode= 'traditional';
+create table t1 (b binary(2), vb varbinary(2));
+insert into t1 values(0x4120, 0x4120);
+insert into t1 values(0x412020, NULL);
+ERROR 22001: Data too long for column 'b' at row 1
+insert into t1 values(NULL, 0x412020);
+ERROR 22001: Data too long for column 'vb' at row 1
+drop table t1;
+set @@sql_mode= @old_sql_mode;
+End of 5.0 tests
diff --git a/mysql-test/r/type_newdecimal-big.result b/mysql-test/r/type_newdecimal-big.result
index e95f2f3f781..4e694702d14 100644
--- a/mysql-test/r/type_newdecimal-big.result
+++ b/mysql-test/r/type_newdecimal-big.result
@@ -1,11 +1,26 @@
drop procedure if exists sp1;
-create procedure sp1 () begin
-declare v1, v2, v3, v4 decimal(16,12); declare v5 int;
-set v1 = 1; set v2 = 2; set v3 = 1000000000000; set v4 = 2000000000000; set v5 = 0;
-while v5 < 100000 do
-set v1 = v1 + 0.000000000001; set v2 = v2 - 0.000000000001; set v3 = v3 + 1; set v4 = v4 - 1; set v5 = v5 + 1;
-end while; select v1, v2, v3 * 0.000000000001, v4 * 0.000000000001; end;//
+CREATE PROCEDURE sp1()
+BEGIN
+DECLARE v1, v2, v3, v4 DECIMAL(28,12);
+DECLARE v3_2, v4_2 DECIMAL(28, 12);
+DECLARE counter INT;
+SET v1 = 1;
+SET v2 = 2;
+SET v3 = 1000000000000;
+SET v4 = 2000000000000;
+SET counter = 0;
+WHILE counter < 100000 DO
+SET v1 = v1 + 0.000000000001;
+SET v2 = v2 - 0.000000000001;
+SET v3 = v3 + 1;
+SET v4 = v4 - 1;
+SET counter = counter + 1;
+END WHILE;
+SET v3_2 = v3 * 0.000000000001;
+SET v4_2 = v4 * 0.000000000001;
+SELECT v1, v2, v3, v3_2, v4, v4_2;
+END//
call sp1()//
-v1 v2 v3 * 0.000000000001 v4 * 0.000000000001
-1.000000100000 1.999999900000 1.000000100000 1.999999900000
+v1 v2 v3 v3_2 v4 v4_2
+1.000000100000 1.999999900000 1000000100000.000000000000 1.000000100000 1999999900000.000000000000 1.999999900000
drop procedure sp1;
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 4385a23416d..e4f2671eb34 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -1933,11 +1933,11 @@ create function f1 () returns int return (select max(col1) from t1);
DROP TABLE t1;
CHECK TABLE v1, v2, v3, v4, v5, v6;
Table Op Msg_type Msg_text
-test.v1 check error Table 'test.t1' doesn't exist
+test.v1 check error View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
test.v2 check status OK
-test.v3 check error Table 'test.t1' doesn't exist
+test.v3 check error View 'test.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
test.v4 check status OK
-test.v5 check error Table 'test.t1' doesn't exist
+test.v5 check error View 'test.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
test.v6 check status OK
drop function f1;
drop function f2;
@@ -2383,20 +2383,25 @@ CREATE TABLE t1(id INT);
CREATE VIEW v1 AS SELECT id FROM t1;
OPTIMIZE TABLE v1;
Table Op Msg_type Msg_text
-test.v1 optimize note Unknown table 'test.v1'
+test.v1 optimize error 'test.v1' is not BASE TABLE
+Warnings:
+Error 1347 'test.v1' is not BASE TABLE
ANALYZE TABLE v1;
Table Op Msg_type Msg_text
-test.v1 analyze note Unknown table 'test.v1'
+test.v1 analyze error 'test.v1' is not BASE TABLE
+Warnings:
+Error 1347 'test.v1' is not BASE TABLE
REPAIR TABLE v1;
Table Op Msg_type Msg_text
-test.v1 repair note Unknown table 'test.v1'
+test.v1 repair error 'test.v1' is not BASE TABLE
+Warnings:
+Error 1347 'test.v1' is not BASE TABLE
DROP TABLE t1;
OPTIMIZE TABLE v1;
Table Op Msg_type Msg_text
-test.v1 optimize note Unknown table 'test.v1'
+test.v1 optimize error 'test.v1' is not BASE TABLE
Warnings:
-Error 1146 Table 'test.t1' doesn't exist
-Error 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
+Error 1347 'test.v1' is not BASE TABLE
DROP VIEW v1;
create definer = current_user() sql security invoker view v1 as select 1;
show create view v1;
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test
index 3878b55da11..f4245abfe86 100644
--- a/mysql-test/t/alter_table.test
+++ b/mysql-test/t/alter_table.test
@@ -340,7 +340,9 @@ drop table t1;
#
# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000)
#
+# Some platforms (Mac OS X, Windows) will send the error message using small letters.
CREATE TABLE T12207(a int) ENGINE=MYISAM;
+--replace_result t12207 T12207
--error 1031
ALTER TABLE T12207 DISCARD TABLESPACE;
DROP TABLE T12207;
diff --git a/mysql-test/t/backup.test b/mysql-test/t/backup.test
index 3034129ad4b..40a9fa73b60 100644
--- a/mysql-test/t/backup.test
+++ b/mysql-test/t/backup.test
@@ -52,5 +52,6 @@ unlock tables;
connection con1;
reap;
drop table t5;
+--system rm $MYSQL_TEST_DIR/var/tmp/t?.*
# End of 4.1 tests
diff --git a/mysql-test/t/ctype_ujis.test b/mysql-test/t/ctype_ujis.test
index c1d6c67387b..77d250b5c45 100644
--- a/mysql-test/t/ctype_ujis.test
+++ b/mysql-test/t/ctype_ujis.test
@@ -1170,7 +1170,7 @@ INSERT INTO t1 VALUES(_ujis 0xA4A2);
DELIMITER |;
CREATE PROCEDURE sp1()
BEGIN
- DECLARE a CHAR(1);
+ DECLARE a CHAR(2) CHARSET ujis;
DECLARE cur1 CURSOR FOR SELECT c1 FROM t1;
OPEN cur1;
FETCH cur1 INTO a;
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index fe95a543fb5..4f5e11e7fbd 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -11,7 +11,4 @@
##############################################################################
sp-goto : GOTO is currently is disabled - will be fixed in the future
-rpl_relayrotate : Unstable test case, bug#12429
-rpl_until : Unstable test case, bug#12429
-rpl_deadlock : Unstable test case, bug#12429
kill : Unstable test case, bug#9712
diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test
index a73ecf7c3eb..735deba2b05 100644
--- a/mysql-test/t/innodb.test
+++ b/mysql-test/t/innodb.test
@@ -1356,8 +1356,8 @@ source include/varchar.inc;
# Clean up filename -- embedded server reports whole path without .frm,
# regular server reports relative path with .frm (argh!)
--replace_result \\ / $MYSQL_TEST_DIR . /var/master-data/ / t1.frm t1
---error 1005
create table t1 (v varchar(65530), key(v));
+drop table t1;
create table t1 (v varchar(65536));
show create table t1;
drop table t1;
@@ -1485,7 +1485,7 @@ CREATE TEMPORARY TABLE t2
DROP TABLE t1;
#
-# Test that index column max sizes are checked (bug #13315)
+# Test that index column max sizes are honored (bug #13315)
#
# prefix index
@@ -1512,22 +1512,36 @@ create table t8 (col1 blob, index(col1(767)))
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
character set = latin1 engine = innodb;
+show create table t9;
+
drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
---error 1005
-create table t1 (col1 varchar(768), index (col1))
+# these should have their index length trimmed
+create table t1 (col1 varchar(768), index(col1))
character set = latin1 engine = innodb;
---error 1005
-create table t2 (col1 varchar(768) primary key)
+create table t2 (col1 varbinary(768), index(col1))
character set = latin1 engine = innodb;
---error 1005
-create table t3 (col1 varbinary(768) primary key)
+create table t3 (col1 text, index(col1(768)))
character set = latin1 engine = innodb;
---error 1005
-create table t4 (col1 text, index(col1(768)))
+create table t4 (col1 blob, index(col1(768)))
character set = latin1 engine = innodb;
---error 1005
-create table t5 (col1 blob, index(col1(768)))
+
+show create table t1;
+
+drop table t1, t2, t3, t4;
+
+# these should be refused
+--error 1071
+create table t1 (col1 varchar(768) primary key)
+ character set = latin1 engine = innodb;
+--error 1071
+create table t2 (col1 varbinary(768) primary key)
+ character set = latin1 engine = innodb;
+--error 1071
+create table t3 (col1 text, primary key(col1(768)))
+ character set = latin1 engine = innodb;
+--error 1071
+create table t4 (col1 blob, primary key(col1(768)))
character set = latin1 engine = innodb;
#
@@ -1752,6 +1766,56 @@ drop table t1;
drop table t2;
commit;
+# tests for bugs #9802 and #13778
+
+# test that FKs between invalid types are not accepted
+
+set foreign_key_checks=0;
+create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
+-- error 1005
+create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
+set foreign_key_checks=1;
+drop table t2;
+
+# test that FKs between different charsets are not accepted in CREATE even
+# when f_k_c is 0
+
+set foreign_key_checks=0;
+create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
+-- error 1005
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
+set foreign_key_checks=1;
+drop table t1;
+
+# test that invalid datatype conversions with ALTER are not allowed
+
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
+create table t1(a varchar(10) primary key) engine = innodb;
+-- error 1025,1025
+alter table t1 modify column a int;
+set foreign_key_checks=1;
+drop table t2,t1;
+
+# test that charset conversions with ALTER are allowed when f_k_c is 0
+
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
+create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
+alter table t1 convert to character set utf8;
+set foreign_key_checks=1;
+drop table t2,t1;
+
+# test that RENAME does not allow invalid charsets when f_k_c is 0
+
+set foreign_key_checks=0;
+create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
+create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
+-- error 1025
+rename table t3 to t1;
+set foreign_key_checks=1;
+drop table t2,t3;
+
#
# Test that we can create a large (>1K) key
#
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test
index 6e56fac2f86..8ccf2cb0c7a 100644
--- a/mysql-test/t/mysqltest.test
+++ b/mysql-test/t/mysqltest.test
@@ -953,7 +953,9 @@ select "this will be executed";
#
# Failing multi statement query
---exec echo "delimiter ||||;" > var/tmp/bug11731.sql
+# PS does not support multi statement
+--exec echo "--disable_ps_protocol" > var/tmp/bug11731.sql
+--exec echo "delimiter ||||;" >> var/tmp/bug11731.sql
--exec echo "create table t1 (a int primary key);" >> var/tmp/bug11731.sql
--exec echo "insert into t1 values (1);" >> var/tmp/bug11731.sql
--exec echo "select 'select-me';" >> var/tmp/bug11731.sql
@@ -973,7 +975,9 @@ drop table t1;
# Using expected error
---exec echo "delimiter ||||;" > var/tmp/bug11731.sql
+# PS does not support multi statement
+--exec echo "--disable_ps_protocol" > var/tmp/bug11731.sql
+--exec echo "delimiter ||||;" >> var/tmp/bug11731.sql
--exec echo "--error 1064" >> var/tmp/bug11731.sql
--exec echo "create table t1 (a int primary key);" >> var/tmp/bug11731.sql
--exec echo "insert into t1 values (1);" >> var/tmp/bug11731.sql
diff --git a/mysql-test/t/rpl_deadlock.test b/mysql-test/t/rpl_deadlock.test
index d2a8fc0c844..08921caf897 100644
--- a/mysql-test/t/rpl_deadlock.test
+++ b/mysql-test/t/rpl_deadlock.test
@@ -102,7 +102,7 @@ commit;
sync_with_master;
select * from t1;
select * from t2;
---replace_column 1 # 8 # 9 # 23 # 33 #
+--replace_column 1 # 8 # 9 # 11 # 23 # 33 #
--replace_result $MASTER_MYPORT MASTER_MYPORT
show slave status;
diff --git a/mysql-test/t/rpl_relayrotate.test b/mysql-test/t/rpl_relayrotate.test
index b66cf7a6e0d..e9a4cdd05c5 100644
--- a/mysql-test/t/rpl_relayrotate.test
+++ b/mysql-test/t/rpl_relayrotate.test
@@ -56,9 +56,6 @@ start slave;
# (the only statement with position>=3000 is COMMIT).
select master_pos_wait('master-bin.001',3000)>=0;
select max(a) from t1;
---replace_column 1 # 8 # 9 # 23 # 33 #
---replace_result $MASTER_MYPORT MASTER_MYPORT
-show slave status;
connection master;
# The following DROP is a very important cleaning task:
diff --git a/mysql-test/t/rpl_until.test b/mysql-test/t/rpl_until.test
index 5bc7a040b1b..708f44a1ab6 100644
--- a/mysql-test/t/rpl_until.test
+++ b/mysql-test/t/rpl_until.test
@@ -49,7 +49,7 @@ sleep 2;
wait_for_slave_to_stop;
select * from t2;
--replace_result $MASTER_MYPORT MASTER_MYPORT
---replace_column 1 # 9 # 23 # 33 #
+--replace_column 1 # 9 # 11 # 23 # 33 #
show slave status;
# clean up
diff --git a/mysql-test/t/schema.test b/mysql-test/t/schema.test
index d9bd607b2db..a08d9b38935 100644
--- a/mysql-test/t/schema.test
+++ b/mysql-test/t/schema.test
@@ -1,6 +1,12 @@
#
# Just a couple of tests to make sure that schema works.
#
+# Drop mysqltest1 database, as it can left from the previous tests.
+#
+
+--disable_warnings
+drop database if exists mysqltest1;
+--enable_warnings
create schema foo;
show create schema foo;
diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test
index 89d281a2c58..4d418303e6d 100644
--- a/mysql-test/t/show_check.test
+++ b/mysql-test/t/show_check.test
@@ -10,6 +10,7 @@
drop table if exists t1,t2;
drop table if exists t1aa,t2aa;
drop database if exists mysqltest;
+drop database if exists mysqltest1;
delete from mysql.user where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3';
delete from mysql.db where user='mysqltest_1' || user='mysqltest_2' || user='mysqltest_3';
diff --git a/mysql-test/t/skip_name_resolve.test b/mysql-test/t/skip_name_resolve.test
index b67869692d2..3f732c8912b 100644
--- a/mysql-test/t/skip_name_resolve.test
+++ b/mysql-test/t/skip_name_resolve.test
@@ -15,6 +15,6 @@ DROP USER mysqltest_1@'127.0.0.1/255.255.255.255';
connect (con1, 127.0.0.1, root, , test, $MASTER_MYPORT, );
--replace_column 1 #
select user();
---replace_column 1 # 6 # 3 #
+--replace_column 1 <id> 3 <host> 5 <command> 6 <time> 7 <state> 8 <info>
show processlist;
connection default;
diff --git a/mysql-test/t/sp-big.test b/mysql-test/t/sp-big.test
index 389a6f04504..90a3a79dd53 100644
--- a/mysql-test/t/sp-big.test
+++ b/mysql-test/t/sp-big.test
@@ -52,6 +52,9 @@ while ($1)
--enable_query_log
select count(*) from t1;
select count(*) from t2;
+--disable_warnings
+drop procedure if exists p1;
+--enable_warnings
delimiter |;
create procedure p1()
begin
diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test
new file mode 100644
index 00000000000..a2a66090866
--- /dev/null
+++ b/mysql-test/t/sp-destruct.test
@@ -0,0 +1,124 @@
+#
+# Destructive stored procedure tests
+#
+# We do horrible things to the mysql.proc table here, so any unexpected
+# failures here might leave it in an undetermined state.
+#
+# In the case of trouble you might want to skip this.
+#
+
+# We're using --system things that probably doesn't work on Windows.
+--source include/not_windows.inc
+
+# Backup proc table
+--system rm -rf var/master-data/mysql/backup
+--system mkdir var/master-data/mysql/backup
+--system cp var/master-data/mysql/proc.* var/master-data/mysql/backup/
+
+use test;
+
+--disable_warnings
+drop procedure if exists bug14233;
+drop function if exists bug14233;
+drop table if exists t1;
+drop view if exists v1;
+--enable_warnings
+
+create procedure bug14233()
+ set @x = 42;
+
+create function bug14233_f() returns int
+ return 42;
+
+create table t1 (id int);
+create trigger t1_ai after insert on t1 for each row call bug14233();
+
+# Unsupported tampering with the mysql.proc definition
+alter table mysql.proc drop type;
+--error ER_SP_PROC_TABLE_CORRUPT
+call bug14233();
+--error ER_SP_PROC_TABLE_CORRUPT
+create view v1 as select bug14233_f();
+--error ER_SP_PROC_TABLE_CORRUPT
+insert into t1 values (0);
+
+flush table mysql.proc;
+
+# Thrashing the .frm file
+--system echo 'saljdlfa' > var/master-data/mysql/proc.frm
+--error ER_NOT_FORM_FILE
+call bug14233();
+--error ER_NOT_FORM_FILE
+create view v1 as select bug14233_f();
+--error ER_NOT_FORM_FILE
+insert into t1 values (0);
+
+
+flush table mysql.proc;
+
+# Drop the mysql.proc table
+--system rm var/master-data/mysql/proc.*
+--error ER_NO_SUCH_TABLE
+call bug14233();
+--error ER_NO_SUCH_TABLE
+create view v1 as select bug14233_f();
+--error ER_NO_SUCH_TABLE
+insert into t1 values (0);
+
+# Restore mysql.proc
+--system mv var/master-data/mysql/backup/* var/master-data/mysql/
+--system rmdir var/master-data/mysql/backup
+
+flush table mysql.proc;
+flush privileges;
+
+delete from mysql.proc where name like 'bug14233%';
+
+# Unsupported editing of mysql.proc, circumventing checks in "create ..."
+insert into mysql.proc
+(
+ db, name, type, specific_name, language, sql_data_access, is_deterministic,
+ security_type, param_list, returns, body, definer, created, modified,
+ sql_mode, comment
+)
+values
+(
+ 'test', 'bug14233_1', 'FUNCTION', 'bug14233_1', 'SQL', 'READS_SQL_DATA', 'NO',
+ 'DEFINER', '', 'int(10)',
+ 'select count(*) from mysql.user',
+ 'root@localhost', NOW() , '0000-00-00 00:00:00', '', ''
+),
+(
+ 'test', 'bug14233_2', 'FUNCTION', 'bug14233_2', 'SQL', 'READS_SQL_DATA', 'NO',
+ 'DEFINER', '', 'int(10)',
+ 'begin declare x int; select count(*) into x from mysql.user; end',
+ 'root@localhost', NOW() , '0000-00-00 00:00:00', '', ''
+),
+(
+ 'test', 'bug14233_3', 'PROCEDURE', 'bug14233_3', 'SQL', 'READS_SQL_DATA','NO',
+ 'DEFINER', '', '',
+ 'alksj wpsj sa ^#!@ ',
+ 'root@localhost', NOW() , '0000-00-00 00:00:00', '', ''
+);
+
+--error ER_SP_PROC_TABLE_CORRUPT
+select bug14233_1();
+--error ER_SP_PROC_TABLE_CORRUPT
+create view v1 as select bug14233_1();
+
+--error ER_SP_PROC_TABLE_CORRUPT
+select bug14233_2();
+--error ER_SP_PROC_TABLE_CORRUPT
+create view v1 as select bug14233_2();
+
+--error ER_SP_PROC_TABLE_CORRUPT
+call bug14233_3();
+drop trigger t1_ai;
+create trigger t1_ai after insert on t1 for each row call bug14233_3();
+--error ER_SP_PROC_TABLE_CORRUPT
+insert into t1 values (0);
+
+# Clean-up
+delete from mysql.proc where name like 'bug14233%';
+drop trigger t1_ai;
+drop table t1;
diff --git a/mysql-test/t/sp-dynamic.test b/mysql-test/t/sp-dynamic.test
index 5416f5931ff..6546a5ab548 100644
--- a/mysql-test/t/sp-dynamic.test
+++ b/mysql-test/t/sp-dynamic.test
@@ -1,4 +1,10 @@
delimiter |;
+
+--disable_warnings
+drop procedure if exists p1|
+drop procedure if exists p2|
+--enable_warnings
+
######################################################################
# Test Dynamic SQL in stored procedures. #############################
######################################################################
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index 69e5f73817b..cf8f8dfc79c 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -1095,7 +1095,7 @@ delimiter |;
--disable_warnings
DROP FUNCTION IF EXISTS bug12953|
--enable_warnings
---error ER_SP_BADSTATEMENT
+--error ER_SP_NO_RETSET
CREATE FUNCTION bug12953() RETURNS INT
BEGIN
OPTIMIZE TABLE t1;
@@ -1410,7 +1410,6 @@ delimiter ;|
# BUG#12329: "Bogus error msg when executing PS with stored procedure after
# SP was re-created". See also test for related bug#13399 in trigger.test
---disable_warnings
drop function if exists bug12329;
--enable_warnings
create table t1 as select 1 a;
@@ -1518,6 +1517,105 @@ show procedure status;
drop database mysqltest2;
use test;
+#
+# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server"
+#
+delimiter |;
+--disable_warnings
+DROP FUNCTION IF EXISTS bug13012|
+--enable_warnings
+--error ER_SP_NO_RETSET
+CREATE FUNCTION bug13012() RETURNS INT
+BEGIN
+ REPAIR TABLE t1;
+ RETURN 1;
+END|
+--error ER_SP_NO_RETSET
+CREATE FUNCTION bug13012() RETURNS INT
+BEGIN
+ BACKUP TABLE t1 TO '/tmp';
+ RETURN 1;
+END|
+--error ER_SP_NO_RETSET
+CREATE FUNCTION bug13012() RETURNS INT
+BEGIN
+ RESTORE TABLE t1 FROM '/tmp';
+ RETURN 1;
+END|
+create table t1 (a int)|
+CREATE PROCEDURE bug13012_1() REPAIR TABLE t1|
+CREATE FUNCTION bug13012_2() RETURNS INT
+BEGIN
+ CALL bug13012_1();
+ RETURN 1;
+END|
+--error ER_SP_NO_RETSET
+SELECT bug13012_2()|
+drop table t1|
+drop procedure bug13012_1|
+drop function bug13012_2|
+delimiter ;|
+
+# BUG#11555 "Stored procedures: current SP tables locking make
+# impossible view security". We should not expose names of tables
+# which are implicitly used by view (via stored routines/triggers).
+#
+# Note that SQL standard assumes that you simply won't be able drop table
+# and leave some objects (routines/views/triggers) which were depending on
+# it. Such objects should be dropped in advance (by default) or will be
+# dropped simultaneously with table (DROP TABLE with CASCADE clause).
+# So these tests probably should go away once we will implement standard
+# behavior.
+--disable_warnings
+drop function if exists bug11555_1;
+drop function if exists bug11555_2;
+drop view if exists v1, v2, v3, v4;
+--enable_warnings
+create function bug11555_1() returns int return (select max(i) from t1);
+create function bug11555_2() returns int return bug11555_1();
+# It is OK to report name of implicitly used table which is missing
+# when we create view.
+--error ER_NO_SUCH_TABLE
+create view v1 as select bug11555_1();
+--error ER_NO_SUCH_TABLE
+create view v2 as select bug11555_2();
+# But we should hide name of missing implicitly used table when we use view
+create table t1 (i int);
+create view v1 as select bug11555_1();
+create view v2 as select bug11555_2();
+create view v3 as select * from v1;
+drop table t1;
+--error ER_VIEW_INVALID
+select * from v1;
+--error ER_VIEW_INVALID
+select * from v2;
+--error ER_VIEW_INVALID
+select * from v3;
+# Note that creation of view which depends on broken view is yet
+# another form of view usage.
+--error ER_VIEW_INVALID
+create view v4 as select * from v1;
+drop view v1, v2, v3;
+# We also should hide details about broken triggers which are
+# invoked for view.
+drop function bug11555_1;
+drop function bug11555_2;
+create table t1 (i int);
+create table t2 (i int);
+create trigger t1_ai after insert on t1 for each row insert into t2 values (new.i);
+create view v1 as select * from t1;
+drop table t2;
+--error ER_VIEW_INVALID
+insert into v1 values (1);
+drop trigger t1_ai;
+create function bug11555_1() returns int return (select max(i) from t2);
+create trigger t1_ai after insert on t1 for each row set @a:=bug11555_1();
+--error ER_VIEW_INVALID
+insert into v1 values (2);
+drop function bug11555_1;
+drop table t1;
+drop view v1;
+
# BUG#NNNN: New bug synopsis
#
diff --git a/mysql-test/t/sp-vars.test b/mysql-test/t/sp-vars.test
new file mode 100644
index 00000000000..81504904797
--- /dev/null
+++ b/mysql-test/t/sp-vars.test
@@ -0,0 +1,1273 @@
+###########################################################################
+#
+# 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;
+
+--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';
+
+--source 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();
+
+# Check that changing sql_mode after creating a store procedure does not
+# matter.
+
+SET @@sql_mode = 'traditional';
+
+--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();
+
+# 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;
+
+--source 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();
+
+SET @@sql_mode = 'ansi';
+
+#
+# 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;
+
+###########################################################################
+#
+# 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.
+#
+
+DROP PROCEDURE IF EXISTS p1;
+DROP PROCEDURE IF EXISTS p2;
+DROP TABLE IF EXISTS t1;
+
+#
+# Test case.
+#
+
+CREATE TABLE t1(log_msg VARCHAR(1024));
+
+delimiter |;
+
+CREATE PROCEDURE p1(arg VARCHAR(255))
+BEGIN
+ INSERT INTO t1 VALUES('p1: step1');
+
+ CASE arg * 10
+ WHEN 10 * 10 THEN
+ INSERT INTO t1 VALUES('p1: case1: on 10');
+ WHEN 10 * 10 + 10 * 10 THEN
+ BEGIN
+ CASE arg / 10
+ WHEN 1 THEN
+ INSERT INTO t1 VALUES('p1: case1: case2: on 1');
+ WHEN 2 THEN
+ BEGIN
+ DECLARE i TINYINT DEFAULT 10;
+
+ WHILE i > 0 DO
+ INSERT INTO t1 VALUES(CONCAT('p1: case1: case2: loop: i: ', i));
+
+ CASE MOD(i, 2)
+ WHEN 0 THEN
+ INSERT INTO t1 VALUES('p1: case1: case2: loop: i is even');
+ WHEN 1 THEN
+ INSERT INTO t1 VALUES('p1: case1: case2: loop: i is odd');
+ ELSE
+ INSERT INTO t1 VALUES('p1: case1: case2: loop: ERROR');
+ END CASE;
+
+ SET i = i - 1;
+ END WHILE;
+ END;
+ ELSE
+ INSERT INTO t1 VALUES('p1: case1: case2: ERROR');
+ END CASE;
+
+ CASE arg
+ WHEN 10 THEN
+ INSERT INTO t1 VALUES('p1: case1: case3: on 10');
+ WHEN 20 THEN
+ INSERT INTO t1 VALUES('p1: case1: case3: on 20');
+ ELSE
+ INSERT INTO t1 VALUES('p1: case1: case3: ERROR');
+ END CASE;
+ END;
+ ELSE
+ INSERT INTO t1 VALUES('p1: case1: ERROR');
+ END CASE;
+
+ CASE arg * 10
+ WHEN 10 * 10 THEN
+ INSERT INTO t1 VALUES('p1: case4: on 10');
+ WHEN 10 * 10 + 10 * 10 THEN
+ BEGIN
+ CASE arg / 10
+ WHEN 1 THEN
+ INSERT INTO t1 VALUES('p1: case4: case5: on 1');
+ WHEN 2 THEN
+ BEGIN
+ DECLARE i TINYINT DEFAULT 10;
+
+ WHILE i > 0 DO
+ INSERT INTO t1 VALUES(CONCAT('p1: case4: case5: loop: i: ', i));
+
+ CASE MOD(i, 2)
+ WHEN 0 THEN
+ INSERT INTO t1 VALUES('p1: case4: case5: loop: i is even');
+ WHEN 1 THEN
+ INSERT INTO t1 VALUES('p1: case4: case5: loop: i is odd');
+ ELSE
+ INSERT INTO t1 VALUES('p1: case4: case5: loop: ERROR');
+ END CASE;
+
+ SET i = i - 1;
+ END WHILE;
+ END;
+ ELSE
+ INSERT INTO t1 VALUES('p1: case4: case5: ERROR');
+ END CASE;
+
+ CASE arg
+ WHEN 10 THEN
+ INSERT INTO t1 VALUES('p1: case4: case6: on 10');
+ WHEN 20 THEN
+ INSERT INTO t1 VALUES('p1: case4: case6: on 20');
+ ELSE
+ INSERT INTO t1 VALUES('p1: case4: case6: ERROR');
+ END CASE;
+ END;
+ ELSE
+ INSERT INTO t1 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 VALUES('p2: case: numerical type');
+ WHEN 'test' THEN
+ INSERT INTO t1 VALUES('p2: case: string type');
+ ELSE
+ INSERT INTO t1 VALUES('p2: case: ERROR');
+ END CASE;
+
+ SET i = i - 1;
+ END WHILE;
+END|
+
+delimiter ;|
+
+CALL p1(10);
+CALL p1(20);
+
+CALL p2();
+
+SELECT * FROM t1;
+
+#
+# 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.
+#
+
+delimiter |;
+CREATE PROCEDURE p1(x DATETIME)
+BEGIN
+ CREATE TABLE t1 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?
+#
+# TODO: test case failed.
+#
+###########################################################################
+
+--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 INTO vb FROM t1 WHERE b = 0;
+
+ SELECT HEX(vb),
+ vb = 0,
+ vb = FALSE,
+ vb IS FALSE,
+ vb = 1,
+ vb = TRUE,
+ vb IS TRUE;
+
+ SELECT b INTO vb FROM t1 WHERE b = 1;
+
+ SELECT HEX(vb),
+ vb = 0,
+ vb = FALSE,
+ vb IS FALSE,
+ vb = 1,
+ vb = TRUE,
+ vb IS TRUE;
+END|
+delimiter ;|
+
+# The expected and correct result.
+
+call p1();
+
+# The wrong result. Note that only hex(vb) works, but is printed with two
+# digits for some reason in this case.
+
+call p2();
+
+#
+# Cleanup.
+#
+
+DROP TABLE t1;
+DROP PROCEDURE p1;
+DROP PROCEDURE p2;
+
+###########################################################################
+#
+# 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';
+
+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';
+
+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';
+
+# 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';
+
+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';
+
+# 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';
+
+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 INTO sp_var FROM t1 LIMIT 1;
+ 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
+CALL p1((SELECT * FROM t1 LIMIT 1));
+
+--error ER_OPERAND_COLUMNS
+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;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index 760110b0a64..f73288f04ba 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -13,6 +13,8 @@
# 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.
use test;
@@ -365,6 +367,7 @@ create function sub3(i int) returns int
call sub1("sub1a", (select 7))|
call sub1("sub1b", (select max(i) from t2))|
+--error ER_OPERAND_COLUMNS
call sub1("sub1c", (select i,d from t2 limit 1))|
call sub1("sub1d", (select 1 from (select 1) a))|
call sub2("sub2")|
@@ -4795,12 +4798,12 @@ begin
declare continue handler for sqlexception select 'boo' as 'Handler';
begin
- declare v int default x;
+ declare v int default undefined_var;
if v = 1 then
select 1;
else
- select 2;
+ select v, isnull(v);
end if;
end;
end|
@@ -4809,12 +4812,14 @@ create procedure bug14643_2()
begin
declare continue handler for sqlexception select 'boo' as 'Handler';
- case x
+ case undefined_var
when 1 then
select 1;
else
select 2;
end case;
+
+ select undefined_var;
end|
call bug14643_1()|
@@ -4908,23 +4913,25 @@ drop procedure bug14376|
# variable declarations. In MySQL 5.0 it's vice versa.
#
-drop procedure if exists p1|
-drop table if exists t1|
-create table t1 (a varchar(255))|
-insert into t1 (a) values ("a - table column")|
-create procedure p1(a varchar(255))
+--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 t1;
+ declare c cursor for select a from t3;
select a;
- select a from t1 into i;
+ 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 t1;
+ declare c1 cursor for select a from t3;
select a as 'A local variable takes precedence over parameter';
open c1;
fetch c1 into i;
@@ -4932,9 +4939,9 @@ begin
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 t1;
+ 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 t1 into i;
+ 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;
@@ -4943,7 +4950,133 @@ begin
end;
end;
end|
-call p1("a - stored procedure parameter")|
+call bug5967("a - stored procedure parameter")|
+drop procedure bug5967|
+
+#
+# Bug#13012 "SP: REPAIR/BACKUP/RESTORE TABLE crashes the server"
+#
+--disable_warnings
+drop procedure if exists bug13012|
+--enable_warnings
+create procedure bug13012()
+BEGIN
+ REPAIR TABLE t1;
+ BACKUP TABLE t1 to '../tmp';
+ DROP TABLE t1;
+ RESTORE TABLE t1 FROM '../tmp';
+END|
+call bug13012()|
+drop procedure bug13012|
+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|
+call bug13012()|
+call bug13012()|
+call bug13012()|
+drop procedure bug13012|
+drop view v1;
+select * from t1|
+
+#
+# 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 text)
+begin
+ declare lsql text;
+ 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 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#NNNN: New bug synopsis
diff --git a/mysql-test/t/type_binary.test b/mysql-test/t/type_binary.test
index 451363c1ae4..1639aff4711 100644
--- a/mysql-test/t/type_binary.test
+++ b/mysql-test/t/type_binary.test
@@ -68,3 +68,27 @@ drop table t1;
# check that cast appends trailing zeros
select hex(cast(0x10 as binary(2)));
+
+#
+# Bug #14299: BINARY space truncation should cause warning or error
+#
+create table t1 (b binary(2), vb varbinary(2));
+insert into t1 values(0x4120, 0x4120);
+insert into t1 values(0x412020, 0x412020);
+drop table t1;
+create table t1 (c char(2), vc varchar(2));
+insert into t1 values(0x4120, 0x4120);
+insert into t1 values(0x412020, 0x412020);
+drop table t1;
+
+set @old_sql_mode= @@sql_mode, sql_mode= 'traditional';
+create table t1 (b binary(2), vb varbinary(2));
+insert into t1 values(0x4120, 0x4120);
+--error ER_DATA_TOO_LONG
+insert into t1 values(0x412020, NULL);
+--error ER_DATA_TOO_LONG
+insert into t1 values(NULL, 0x412020);
+drop table t1;
+set @@sql_mode= @old_sql_mode;
+
+--echo End of 5.0 tests
diff --git a/mysql-test/t/type_newdecimal-big.test b/mysql-test/t/type_newdecimal-big.test
index e200017f2ba..9a1104e4fe6 100644
--- a/mysql-test/t/type_newdecimal-big.test
+++ b/mysql-test/t/type_newdecimal-big.test
@@ -12,12 +12,31 @@ drop procedure if exists sp1;
delimiter //;
#
-create procedure sp1 () begin
- declare v1, v2, v3, v4 decimal(16,12); declare v5 int;
- set v1 = 1; set v2 = 2; set v3 = 1000000000000; set v4 = 2000000000000; set v5 = 0;
- while v5 < 100000 do
- set v1 = v1 + 0.000000000001; set v2 = v2 - 0.000000000001; set v3 = v3 + 1; set v4 = v4 - 1; set v5 = v5 + 1;
- end while; select v1, v2, v3 * 0.000000000001, v4 * 0.000000000001; end;//
+CREATE PROCEDURE sp1()
+BEGIN
+ DECLARE v1, v2, v3, v4 DECIMAL(28,12);
+ DECLARE v3_2, v4_2 DECIMAL(28, 12);
+ DECLARE counter INT;
+
+ SET v1 = 1;
+ SET v2 = 2;
+ SET v3 = 1000000000000;
+ SET v4 = 2000000000000;
+ SET counter = 0;
+
+ WHILE counter < 100000 DO
+ SET v1 = v1 + 0.000000000001;
+ SET v2 = v2 - 0.000000000001;
+ SET v3 = v3 + 1;
+ SET v4 = v4 - 1;
+ SET counter = counter + 1;
+ END WHILE;
+
+ SET v3_2 = v3 * 0.000000000001;
+ SET v4_2 = v4 * 0.000000000001;
+
+ SELECT v1, v2, v3, v3_2, v4, v4_2;
+END//
#
call sp1()//
#-- should return
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index d58d74cdb7c..6d2afb908a4 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -1744,7 +1744,6 @@ drop function f1;
CHECK TABLE v1, v2, v3, v4, v5, v6;
create function f1 () returns int return (select max(col1) from t1);
DROP TABLE t1;
-# following will show underlying table until BUG#11555 fix
CHECK TABLE v1, v2, v3, v4, v5, v6;
drop function f1;
drop function f2;