mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / func_concat.test
blobe56d1121808e48d986c6bc091bf3287dda83e822
2 # Test of problem with CONCAT_WS() and long separators.
5 --disable_warnings
6 DROP TABLE IF EXISTS t1;
7 DROP PROCEDURE IF EXISTS p1;
8 --enable_warnings
10 CREATE TABLE t1 ( number INT NOT NULL, alpha CHAR(6) NOT NULL );
11 INSERT INTO t1 VALUES (1413006,'idlfmv'),
12 (1413065,'smpsfz'),(1413127,'sljrhx'),(1413304,'qerfnd');
14 SELECT number, alpha, CONCAT_WS('<---->',number,alpha) AS new
15 FROM t1 GROUP BY number;
17 SELECT CONCAT_WS('<---->',number,alpha) AS new
18 FROM t1 GROUP BY new LIMIT 1;
20 SELECT number, alpha, CONCAT_WS('<->',number,alpha) AS new
21 FROM t1 GROUP BY new LIMIT 1;
23 SELECT number, alpha, CONCAT_WS('-',number,alpha,alpha,alpha,alpha,alpha,alpha,alpha) AS new
24 FROM t1 GROUP BY new LIMIT 1;
26 SELECT number, alpha, CONCAT_WS('<------------------>',number,alpha) AS new
27 FROM t1 GROUP BY new LIMIT 1;
28 drop table t1;
31 # Bug #5540: a problem with double type
34 create table t1 (a char(4), b double, c date, d tinyint(4));
35 insert into t1 values ('AAAA', 105, '2003-03-01', 1);
36 select * from t1 where concat(A,C,B,D) = 'AAAA2003-03-011051';
37 drop table t1;
39 # BUG#6825 
40 select 'a' union select concat('a', -4);
41 select 'a' union select concat('a', -4.5);
43 select 'a' union select concat('a', -(4 + 1));
44 select 'a' union select concat('a', 4 - 5);
46 select 'a' union select concat('a', -'3');
47 select 'a' union select concat('a', -concat('3',4));
49 select 'a' union select concat('a', -0);
50 --replace_result a-0.0 a0.0
51 select 'a' union select concat('a', -0.0);
53 --replace_result a-0.0000 a0.0000
54 select 'a' union select concat('a', -0.0000);
57 # Bug#16716: subselect in concat() may lead to a wrong result
59 select concat((select x from (select 'a' as x) as t1 ),
60   (select y from (select 'b' as y) as t2 )) from (select 1 union select 2 )
61   as t3;
63 # End of 4.1 tests
66 # Bug#15962: CONCAT() in UNION may lead to a data trucation.
68 create table t1(f1 varchar(6)) charset=utf8;
69 insert into t1 values ("123456");
70 select concat(f1, 2) a from t1 union select 'x' a from t1;
71 drop table t1;
74 # Bug #36488: regexp returns false matches, concatenating with previous rows
76 CREATE TABLE t1 (c1 varchar(100), c2 varchar(100));
77 INSERT INTO t1 VALUES ('',''), ('','First'), ('Random','Random');
78 SELECT * FROM t1 WHERE CONCAT(c1,' ',c2) REGEXP 'First.*';
79 DROP TABLE t1;
81 --echo # End of 5.0 tests
84 --echo #
85 --echo # Bug #44743: Join in combination with concat does not always work
86 --echo #
87 CREATE TABLE t1 (
88   a VARCHAR(100) NOT NULL DEFAULT '0',
89   b VARCHAR(2) NOT NULL DEFAULT '',
90   c VARCHAR(2) NOT NULL DEFAULT '',
91   d TEXT NOT NULL,
92   PRIMARY KEY (a, b, c),
93   KEY (a)
94 ) DEFAULT CHARSET=utf8;
96 INSERT INTO t1 VALUES ('gui_A', 'a', 'b', 'str1'),
97   ('gui_AB', 'a', 'b', 'str2'), ('gui_ABC', 'a', 'b', 'str3');
99 CREATE TABLE t2 (
100   a VARCHAR(100) NOT NULL DEFAULT '',
101   PRIMARY KEY (a)
102 ) DEFAULT CHARSET=latin1;
104 INSERT INTO t2 VALUES ('A'), ('AB'), ('ABC');
106 SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
107   LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
109 EXPLAIN SELECT CONCAT('gui_', t2.a), t1.d FROM t2 
110   LEFT JOIN t1 ON t1.a = CONCAT('gui_', t2.a) AND t1.b = 'a' AND t1.c = 'b';
112 DROP TABLE t1, t2;
115 --echo #
116 --echo # Bug #50096: CONCAT_WS inside procedure returning wrong data
117 --echo #
119 CREATE PROCEDURE p1(a varchar(255), b int, c int)
120   SET @query = CONCAT_WS(",", a, b, c);
122 CALL p1("abcde", "0", "1234");
123 SELECT @query;
125 DROP PROCEDURE p1;
127 --echo #
128 --echo # Bug #40625: Concat fails on DOUBLE values in a Stored Procedure,
129 --echo #             while DECIMAL works
130 --echo #
132 DELIMITER //;
133 CREATE PROCEDURE p1()
134 BEGIN
135   DECLARE v1 DOUBLE(10,3);
136   SET v1= 100;
137   SET @s = CONCAT('########################################', 40 , v1);
138   SELECT @s;
139 END;//
140 DELIMITER ;//
142 CALL p1();
143 CALL p1();
145 DROP PROCEDURE p1;
147 --echo # End of 5.1 tests