mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/alik/Documents/AllProgs/MySQL/devel/5.0-sp-vars-merge-2
This commit is contained in:
122
mysql-test/include/sp-vars.inc
Normal file
122
mysql-test/include/sp-vars.inc
Normal file
@ -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 ;|
|
@ -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;
|
||||
|
@ -1,3 +1,4 @@
|
||||
drop database if exists mysqltest1;
|
||||
create schema foo;
|
||||
show create schema foo;
|
||||
Database Create Database
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
|
@ -1,3 +1,5 @@
|
||||
drop procedure if exists p1|
|
||||
drop procedure if exists p2|
|
||||
create procedure p1()
|
||||
begin
|
||||
prepare stmt from "select 1";
|
||||
|
1077
mysql-test/r/sp-vars.result
Normal file
1077
mysql-test/r/sp-vars.result
Normal file
File diff suppressed because it is too large
Load Diff
@ -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|
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
1273
mysql-test/sp-vars.test
Normal file
1273
mysql-test/sp-vars.test
Normal file
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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. #############################
|
||||
######################################################################
|
||||
|
@ -367,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")|
|
||||
@ -4797,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|
|
||||
@ -4811,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()|
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user