mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / func_str.test
blob09d27d07f496e33ac063a12ae60a5c6ff7b7a6a6
1 # Description
2 # -----------
3 # Testing string functions
5 --disable_warnings
6 drop table if exists t1,t2;
7 --enable_warnings
9 set names latin1;
11 select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
12 select 'hello' 'monty';
13 select length('\n\t\r\b\0\_\%\\');
14 select bit_length('\n\t\r\b\0\_\%\\');
15 select char_length('\n\t\r\b\0\_\%\\');
16 select length(_latin1'\n\t\n\b\0\\_\\%\\');
17 select concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h');
18 select hex(char(256));
19 select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ;
20 select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE'); 
21 select position(binary 'll' in 'hello'),position('a' in binary 'hello');
23 # Bug#11728 string function LEFT,
24 # strange undocumented behaviour, strict mode
26 select left('hello',null), right('hello',null);
27 select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ;
28 select concat('',left(right(concat('what ',concat('is ','happening')),9),4),'',substring('monty',5,1)) ;
29 select substring_index('www.tcx.se','.',-2),substring_index('www.tcx.se','.',1);
30 select substring_index('www.tcx.se','tcx',1),substring_index('www.tcx.se','tcx',-1);
31 select substring_index('.tcx.se','.',-2),substring_index('.tcx.se','.tcx',-1);
32 select substring_index('aaaaaaaaa1','a',1);
33 select substring_index('aaaaaaaaa1','aa',1);
34 select substring_index('aaaaaaaaa1','aa',2);
35 select substring_index('aaaaaaaaa1','aa',3);
36 select substring_index('aaaaaaaaa1','aa',4);
37 select substring_index('aaaaaaaaa1','aa',5);
38 select substring_index('aaaaaaaaa1','aaa',1);
39 select substring_index('aaaaaaaaa1','aaa',2);
40 select substring_index('aaaaaaaaa1','aaa',3);
41 select substring_index('aaaaaaaaa1','aaa',4);
42 select substring_index('aaaaaaaaa1','aaaa',1);
43 select substring_index('aaaaaaaaa1','aaaa',2);
44 select substring_index('aaaaaaaaa1','1',1);
45 select substring_index('aaaaaaaaa1','a',-1);
46 select substring_index('aaaaaaaaa1','aa',-1);
47 select substring_index('aaaaaaaaa1','aa',-2);
48 select substring_index('aaaaaaaaa1','aa',-3);
49 select substring_index('aaaaaaaaa1','aa',-4);
50 select substring_index('aaaaaaaaa1','aa',-5);
51 select substring_index('aaaaaaaaa1','aaa',-1);
52 select substring_index('aaaaaaaaa1','aaa',-2);
53 select substring_index('aaaaaaaaa1','aaa',-3);
54 select substring_index('aaaaaaaaa1','aaa',-4);
55 select substring_index('the king of thethe hill','the',-2);
56 select substring_index('the king of the the hill','the',-2);
57 select substring_index('the king of the  the hill','the',-2);
58 select substring_index('the king of the  the hill',' the ',-1);
59 select substring_index('the king of the  the hill',' the ',-2);
60 select substring_index('the king of the  the hill',' ',-1);
61 select substring_index('the king of the  the hill',' ',-2);
62 select substring_index('the king of the  the hill',' ',-3);
63 select substring_index('the king of the  the hill',' ',-4);
64 select substring_index('the king of the  the hill',' ',-5);
65 select substring_index('the king of the.the hill','the',-2);
66 select substring_index('the king of thethethe.the hill','the',-3);
67 select substring_index('the king of thethethe.the hill','the',-1);
68 select substring_index('the king of the the hill','the',1);
69 select substring_index('the king of the the hill','the',2);
70 select substring_index('the king of the the hill','the',3);
72 select concat(':',ltrim('  left  '),':',rtrim('  right  '),':');
73 select concat(':',trim(leading from '  left  '),':',trim(trailing from '  right  '),':');
74 select concat(':',trim(LEADING FROM ' left'),':',trim(TRAILING FROM ' right '),':');
75 select concat(':',trim(' m '),':',trim(BOTH FROM ' y '),':',trim('*' FROM '*s*'),':');
76 select concat(':',trim(BOTH 'ab' FROM 'ababmyabab'),':',trim(BOTH '*' FROM '***sql'),':');
77 select concat(':',trim(LEADING '.*' FROM '.*my'),':',trim(TRAILING '.*' FROM 'sql.*.*'),':');
78 select TRIM("foo" FROM "foo"), TRIM("foo" FROM "foook"), TRIM("foo" FROM "okfoo");
80 select concat_ws(', ','monty','was here','again');
81 select concat_ws(NULL,'a'),concat_ws(',',NULL,'');
82 select concat_ws(',','',NULL,'a');
83 SELECT CONCAT('"',CONCAT_WS('";"',repeat('a',60),repeat('b',60),repeat('c',60),repeat('d',100)), '"');
85 select insert('txs',2,1,'hi'),insert('is ',4,0,'a'),insert('txxxxt',2,4,'es');
86 select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb'),replace('aaaa','','b'),replace('bbbb','a','c');
87 select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ;
88 select soundex(''),soundex('he'),soundex('hello all folks'),soundex('#3556 in bugdb');
89 select 'mood' sounds like 'mud';
90 select 'Glazgo' sounds like 'Liverpool';
91 select null sounds like 'null';
92 select 'null' sounds like null;
93 select null sounds like null;
94 select md5('hello');
95 select crc32("123");
96 select sha('abc');
97 select sha1('abc');
98 select aes_decrypt(aes_encrypt('abc','1'),'1');
99 select aes_decrypt(aes_encrypt('abc','1'),1);
100 select aes_encrypt(NULL,"a");
101 select aes_encrypt("a",NULL);
102 select aes_decrypt(NULL,"a");
103 select aes_decrypt("a",NULL);
104 select aes_decrypt("a","a");
105 select aes_decrypt(aes_encrypt("","a"),"a");
106 select repeat('monty',5),concat('*',space(5),'*');
107 select reverse('abc'),reverse('abcd');
108 select rpad('a',4,'1'),rpad('a',4,'12'),rpad('abcd',3,'12'), rpad(11, 10 , 22), rpad("ab", 10, 22);
109 select lpad('a',4,'1'),lpad('a',4,'12'),lpad('abcd',3,'12'), lpad(11, 10 , 22);
110 select rpad(741653838,17,'0'),lpad(741653838,17,'0');
111 select rpad('abcd',7,'ab'),lpad('abcd',7,'ab');
112 select rpad('abcd',1,'ab'),lpad('abcd',1,'ab');
113 select rpad('STRING', 20, CONCAT('p','a','d') );
114 select lpad('STRING', 20, CONCAT('p','a','d') );
116 select LEAST(NULL,'HARRY','HARRIOT',NULL,'HAROLD'),GREATEST(NULL,'HARRY','HARRIOT',NULL,'HAROLD');
117 select least(1,2,3) | greatest(16,32,8), least(5,4)*1,greatest(-1.0,1.0)*1,least(3,2,1)*1.0,greatest(1,1.1,1.0),least("10",9),greatest("A","B","0");
119 select decode(encode(repeat("a",100000),"monty"),"monty")=repeat("a",100000);
120 select decode(encode("abcdef","monty"),"monty")="abcdef";
122 select quote('\'\"\\test');
123 select quote(concat('abc\'', '\\cba'));
124 select quote(1/0), quote('\0\Z');
125 select length(quote(concat(char(0),"test")));
126 select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))));
127 select unhex(hex("foobar")), hex(unhex("1234567890ABCDEF")), unhex("345678"), unhex(NULL);
128 select hex(unhex("1")), hex(unhex("12")), hex(unhex("123")), hex(unhex("1234")), hex(unhex("12345")), hex(unhex("123456"));
129 select length(unhex(md5("abrakadabra")));
132 # Bug #6564: QUOTE(NULL
135 select concat('a', quote(NULL));
138 # Wrong usage of functions
141 select reverse("");
142 select insert("aa",100,1,"b"),insert("aa",1,3,"b"),left("aa",-1),substring("a",1,2);
143 select elt(2,1),field(NULL,"a","b","c"),reverse("");
144 select locate("a","b",2),locate("","a",1);
145 select ltrim("a"),rtrim("a"),trim(BOTH "" from "a"),trim(BOTH " " from "a");
146 select concat("1","2")|0,concat("1",".5")+0.0;
147 select substring_index("www.tcx.se","",3);
148 select length(repeat("a",100000000)),length(repeat("a",1000*64));
149 select position("0" in "baaa" in (1)),position("0" in "1" in (1,2,3)),position("sql" in ("mysql"));
150 select position(("1" in (1,2,3)) in "01");
151 select length(repeat("a",65500)),length(concat(repeat("a",32000),repeat("a",32000))),length(replace("aaaaa","a",concat(repeat("a",10000)))),length(insert(repeat("a",40000),1,30000,repeat("b",50000)));
152 select length(repeat("a",1000000)),length(concat(repeat("a",32000),repeat("a",32000),repeat("a",32000))),length(replace("aaaaa","a",concat(repeat("a",32000)))),length(insert(repeat("a",48000),1,1000,repeat("a",48000)));
155 # Problem med concat
158 create table t1 ( domain char(50) );
159 insert into t1 VALUES ("hello.de" ), ("test.de" );
160 select domain from t1 where concat('@', trim(leading '.' from concat('.', domain))) = '@hello.de';
161 select domain from t1 where concat('@', trim(leading '.' from concat('.', domain))) = '@test.de';
162 drop table t1;
165 # Test bug in concat_ws
168 CREATE TABLE t1 (
169   id int(10) unsigned NOT NULL,
170   title varchar(255) default NULL,
171   prio int(10) unsigned default NULL,
172   category int(10) unsigned default NULL,
173   program int(10) unsigned default NULL,
174   bugdesc text,
175   created datetime default NULL,
176   modified timestamp NOT NULL,
177   bugstatus int(10) unsigned default NULL,
178   submitter int(10) unsigned default NULL
179 ) ENGINE=MyISAM;
181 INSERT INTO t1 VALUES (1,'Link',1,1,1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','2001-02-28 08:40:16',20010228084016,0,4);
182 SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter), '"') FROM t1;
183 SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1;
184 SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter) FROM t1;
185 SELECT bugdesc, REPLACE(bugdesc, 'xxxxxxxxxxxxxxxxxxxx', 'bbbbbbbbbbbbbbbbbbbb') from t1 group by bugdesc;
186 drop table t1;
189 # Test bug in AES_DECRYPT() when called with wrong argument
192 CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id (id)) ENGINE=MyISAM;
193 INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf');
194 SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password");
195 DROP TABLE t1;
197 CREATE TABLE t1 (
198   wid int(10) unsigned NOT NULL auto_increment,
199   data_podp date default NULL,
200   status_wnio enum('nowy','podp','real','arch') NOT NULL default 'nowy',
201   PRIMARY KEY(wid)
204 INSERT INTO t1 VALUES (8,NULL,'real');
205 INSERT INTO t1 VALUES (9,NULL,'nowy');
206 SELECT elt(status_wnio,data_podp) FROM t1 GROUP BY wid;
207 DROP TABLE t1;
210 # test for #739
212 CREATE TABLE t1 (title text) ENGINE=MyISAM;
213 INSERT INTO t1 VALUES ('Congress reconvenes in September to debate welfare and adult education');
214 INSERT INTO t1 VALUES ('House passes the CAREERS bill');
215 SELECT CONCAT("</a>",RPAD("",(55 - LENGTH(title)),".")) from t1;
216 DROP TABLE t1;
219 # test for Bug #2290 "output truncated with ELT when using DISTINCT"
222 CREATE TABLE t1 (i int, j int);
223 INSERT INTO t1 VALUES (1,1),(2,2);
224 SELECT DISTINCT i, ELT(j, '345', '34') FROM t1;
225 DROP TABLE t1;
228 # bug #3756: quote and NULL
231 create table t1(a char(4));
232 insert into t1 values ('one'),(NULL),('two'),('four');
233 select a, quote(a), isnull(quote(a)), quote(a) is null, ifnull(quote(a), 'n') from t1;
234 drop table t1;
237 # Bug #5498: TRIM fails with LEADING or TRAILING if remstr = str
240 select trim(trailing 'foo' from 'foo');
241 select trim(leading 'foo' from 'foo');
244 # crashing bug with QUOTE() and LTRIM() or TRIM() fixed
245 # Bug #7495
248 select quote(ltrim(concat('    ', 'a')));
249 select quote(trim(concat('    ', 'a')));
251 # Bad results from QUOTE(). Bug #8248
252 CREATE TABLE t1 SELECT 1 UNION SELECT 2 UNION SELECT 3;
253 SELECT QUOTE('A') FROM t1;
254 DROP TABLE t1;
256 # Test collation and coercibility
259 select 1=_latin1'1';
260 select _latin1'1'=1;
261 select _latin2'1'=1;
262 select 1=_latin2'1';
263 --error 1267
264 select _latin1'1'=_latin2'1';
265 select row('a','b','c') = row('a','b','c');
266 select row('A','b','c') = row('a','b','c');
267 select row('A' COLLATE latin1_bin,'b','c') = row('a','b','c');
268 select row('A','b','c') = row('a' COLLATE latin1_bin,'b','c');
269 --error 1267
270 select row('A' COLLATE latin1_general_ci,'b','c') = row('a' COLLATE latin1_bin,'b','c');
272 --error 1267
273 select concat(_latin1'a',_latin2'a');
274 --error 1270
275 select concat(_latin1'a',_latin2'a',_latin5'a');
276 --error 1271
277 select concat(_latin1'a',_latin2'a',_latin5'a',_latin7'a');
278 --error 1267
279 select concat_ws(_latin1'a',_latin2'a');
282 # Test FIELD() and collations
284 select FIELD('b','A','B');
285 select FIELD('B','A','B');
286 select FIELD('b' COLLATE latin1_bin,'A','B');
287 select FIELD('b','A' COLLATE latin1_bin,'B');
288 --error 1270
289 select FIELD(_latin2'b','A','B');
290 --error 1270
291 select FIELD('b',_latin2'A','B');
292 select FIELD('1',_latin2'3','2',1);
294 select POSITION(_latin1'B' IN _latin1'abcd');
295 select POSITION(_latin1'B' IN _latin1'abcd' COLLATE latin1_bin);
296 select POSITION(_latin1'B' COLLATE latin1_bin IN _latin1'abcd');
297 --error 1267
298 select POSITION(_latin1'B' COLLATE latin1_general_ci IN _latin1'abcd' COLLATE latin1_bin);
299 --error 1267
300 select POSITION(_latin1'B' IN _latin2'abcd');
302 select FIND_IN_SET(_latin1'B',_latin1'a,b,c,d');
304 # fix this:
305 --disable_parsing
306 select FIND_IN_SET(_latin1'B',_latin1'a,b,c,d' COLLATE latin1_bin);
307 select FIND_IN_SET(_latin1'B' COLLATE latin1_bin,_latin1'a,b,c,d');
308 --enable_parsing
310 --error 1267
311 select FIND_IN_SET(_latin1'B' COLLATE latin1_general_ci,_latin1'a,b,c,d' COLLATE latin1_bin);
312 --error 1267
313 select FIND_IN_SET(_latin1'B',_latin2'a,b,c,d');
315 select SUBSTRING_INDEX(_latin1'abcdabcdabcd',_latin1'd',2);
317 # fix this:
318 --disable_parsing
319 select SUBSTRING_INDEX(_latin1'abcdabcdabcd' COLLATE latin1_bin,_latin1'd',2);
320 select SUBSTRING_INDEX(_latin1'abcdabcdabcd',_latin1'd' COLLATE latin1_bin,2);
321 --enable_parsing
323 --error 1267
324 select SUBSTRING_INDEX(_latin1'abcdabcdabcd',_latin2'd',2);
325 --error 1267
326 select SUBSTRING_INDEX(_latin1'abcdabcdabcd' COLLATE latin1_general_ci,_latin1'd' COLLATE latin1_bin,2);
328 select _latin1'B' between _latin1'a' and _latin1'c';
329 select _latin1'B' collate latin1_bin between _latin1'a' and _latin1'c';
330 select _latin1'B' between _latin1'a' collate latin1_bin and _latin1'c';
331 select _latin1'B' between _latin1'a' and _latin1'c' collate latin1_bin;
332 --error 1270
333 select _latin2'B' between _latin1'a' and _latin1'b';
334 --error 1270
335 select _latin1'B' between _latin2'a' and _latin1'b';
336 --error 1270
337 select _latin1'B' between _latin1'a' and _latin2'b';
338 --error 1270
339 select _latin1'B' collate latin1_general_ci between _latin1'a' collate latin1_bin and _latin1'b';
341 select _latin1'B' in (_latin1'a',_latin1'b');
342 select _latin1'B' collate latin1_bin in (_latin1'a',_latin1'b');
343 select _latin1'B' in (_latin1'a' collate latin1_bin,_latin1'b');
344 select _latin1'B' in (_latin1'a',_latin1'b' collate latin1_bin);
345 --error 1270
346 select _latin2'B' in (_latin1'a',_latin1'b');
347 --error 1270
348 select _latin1'B' in (_latin2'a',_latin1'b');
349 --error 1270
350 select _latin1'B' in (_latin1'a',_latin2'b');
351 --error 1270
352 select _latin1'B' COLLATE latin1_general_ci in (_latin1'a' COLLATE latin1_bin,_latin1'b');
353 --error 1270
354 select _latin1'B' COLLATE latin1_general_ci in (_latin1'a',_latin1'b' COLLATE latin1_bin);
356 select collation(bin(130)), coercibility(bin(130));
357 select collation(oct(130)), coercibility(oct(130));
358 select collation(conv(130,16,10)), coercibility(conv(130,16,10));
359 select collation(hex(130)), coercibility(hex(130));
360 select collation(char(130)), coercibility(hex(130));
361 select collation(format(130,10)), coercibility(format(130,10));
362 select collation(lcase(_latin2'a')), coercibility(lcase(_latin2'a'));
363 select collation(ucase(_latin2'a')), coercibility(ucase(_latin2'a'));
364 select collation(left(_latin2'a',1)), coercibility(left(_latin2'a',1));
365 select collation(right(_latin2'a',1)), coercibility(right(_latin2'a',1));
366 select collation(substring(_latin2'a',1,1)), coercibility(substring(_latin2'a',1,1));
367 select collation(concat(_latin2'a',_latin2'b')), coercibility(concat(_latin2'a',_latin2'b'));
368 select collation(lpad(_latin2'a',4,_latin2'b')), coercibility(lpad(_latin2'a',4,_latin2'b'));
369 select collation(rpad(_latin2'a',4,_latin2'b')), coercibility(rpad(_latin2'a',4,_latin2'b'));
370 select collation(concat_ws(_latin2'a',_latin2'b')), coercibility(concat_ws(_latin2'a',_latin2'b'));
371 select collation(make_set(255,_latin2'a',_latin2'b',_latin2'c')), coercibility(make_set(255,_latin2'a',_latin2'b',_latin2'c'));
372 select collation(export_set(255,_latin2'y',_latin2'n',_latin2' ')), coercibility(export_set(255,_latin2'y',_latin2'n',_latin2' '));
373 select collation(trim(_latin2' a ')), coercibility(trim(_latin2' a '));
374 select collation(ltrim(_latin2' a ')), coercibility(ltrim(_latin2' a '));
375 select collation(rtrim(_latin2' a ')), coercibility(rtrim(_latin2' a '));
376 select collation(trim(LEADING _latin2' ' FROM _latin2'a')), coercibility(trim(LEADING _latin2'a' FROM _latin2'a'));
377 select collation(trim(TRAILING _latin2' ' FROM _latin2'a')), coercibility(trim(TRAILING _latin2'a' FROM _latin2'a'));
378 select collation(trim(BOTH _latin2' ' FROM _latin2'a')), coercibility(trim(BOTH _latin2'a' FROM _latin2'a'));
379 select collation(repeat(_latin2'a',10)), coercibility(repeat(_latin2'a',10));
380 select collation(reverse(_latin2'ab')), coercibility(reverse(_latin2'ab'));
381 select collation(quote(_latin2'ab')), coercibility(quote(_latin2'ab'));
382 select collation(soundex(_latin2'ab')), coercibility(soundex(_latin2'ab'));
383 select collation(substring(_latin2'ab',1)), coercibility(substring(_latin2'ab',1));
384 select collation(insert(_latin2'abcd',2,3,_latin2'ef')), coercibility(insert(_latin2'abcd',2,3,_latin2'ef'));
385 select collation(replace(_latin2'abcd',_latin2'b',_latin2'B')), coercibility(replace(_latin2'abcd',_latin2'b',_latin2'B'));
386 select collation(encode('abcd','ab')), coercibility(encode('abcd','ab'));
388 create table t1 
389 select
390   bin(130),
391   oct(130),
392   conv(130,16,10),
393   hex(130),
394   char(130),
395   format(130,10),
396   left(_latin2'a',1),
397   right(_latin2'a',1), 
398   lcase(_latin2'a'), 
399   ucase(_latin2'a'),
400   substring(_latin2'a',1,1),
401   concat(_latin2'a',_latin2'b'),
402   lpad(_latin2'a',4,_latin2'b'),
403   rpad(_latin2'a',4,_latin2'b'),
404   concat_ws(_latin2'a',_latin2'b'),
405   make_set(255,_latin2'a',_latin2'b',_latin2'c'),
406   export_set(255,_latin2'y',_latin2'n',_latin2' '),
407   trim(_latin2' a '),
408   ltrim(_latin2' a '),
409   rtrim(_latin2' a '),
410   trim(LEADING _latin2' ' FROM _latin2' a '),
411   trim(TRAILING _latin2' ' FROM _latin2' a '),
412   trim(BOTH _latin2' ' FROM _latin2' a '),
413   repeat(_latin2'a',10),
414   reverse(_latin2'ab'),
415   quote(_latin2'ab'),
416   soundex(_latin2'ab'),
417   substring(_latin2'ab',1),
418   insert(_latin2'abcd',2,3,_latin2'ef'),
419   replace(_latin2'abcd',_latin2'b',_latin2'B'),
420   encode('abcd','ab')
422 show create table t1;
423 drop table t1;
426 # Bug#9129
428 create table t1 (a char character set latin2);
429 insert into t1 values (null);
430 select charset(a), collation(a), coercibility(a) from t1;
431 drop table t1;
432 select charset(null), collation(null), coercibility(null);
434 # Make sure OUTER JOIN is not replaced with a regular joun
436 CREATE TABLE t1 (a int, b int);
437 CREATE TABLE t2 (a int, b int);
438 INSERT INTO t1 VALUES (1,1),(2,2);
439 INSERT INTO t2 VALUES (2,2),(3,3);
440 select t1.*,t2.* from t1 left join t2 on (t1.b=t2.b)
441 where collation(t2.a) = _utf8'binary' order by t1.a,t2.a;
442 select t1.*,t2.* from t1 left join t2 on (t1.b=t2.b)
443 where charset(t2.a) = _utf8'binary' order by t1.a,t2.a;
444 select t1.*,t2.* from t1 left join t2 on (t1.b=t2.b)
445 where coercibility(t2.a) = 2 order by t1.a,t2.a;
446 DROP TABLE t1, t2;
449 # test for SUBSTR
451 select SUBSTR('abcdefg',3,2);
452 select SUBSTRING('abcdefg',3,2);
453 select SUBSTR('abcdefg',-3,2) FROM DUAL;
454 select SUBSTR('abcdefg',-1,5) FROM DUAL;
455 select SUBSTR('abcdefg',0,0) FROM DUAL;
456 select SUBSTR('abcdefg',-1,-1) FROM DUAL;
457 select SUBSTR('abcdefg',1,-1) FROM DUAL;
460 # Test that fix_fields doesn't follow to upper level (to comparison)
461 # when an error on a lower level (in concat) has accured:
463 create table t7 (s1 char);
464 --error 1267
465 select * from t7
466 where concat(s1 collate latin1_general_ci,s1 collate latin1_swedish_ci) = 'AA';
467 drop table t7;
469 select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2);
471 explain extended select md5('hello');
472 explain extended select sha('abc');
473 explain extended select sha1('abc');
474 explain extended select soundex('');
475 explain extended select 'mood' sounds like 'mud';
476 explain extended select aes_decrypt(aes_encrypt('abc','1'),'1');
477 explain extended select concat('*',space(5),'*');
478 explain extended select reverse('abc');
479 explain extended select rpad('a',4,'1');
480 explain extended select lpad('a',4,'1');
481 explain extended select concat_ws(',','',NULL,'a');
482 explain extended select make_set(255,_latin2'a', _latin2'b', _latin2'c');
483 explain extended select elt(2,1);
484 explain extended select locate("a","b",2);
485 explain extended select format(130,10);
486 explain extended select char(0);
487 explain extended select conv(130,16,10);
488 explain extended select hex(130);
489 explain extended select binary 'HE';
490 explain extended select export_set(255,_latin2'y', _latin2'n', _latin2' ');
491 explain extended select FIELD('b' COLLATE latin1_bin,'A','B');
492 explain extended select FIND_IN_SET(_latin1'B', _latin1'a,b,c,d');
493 explain extended select collation(conv(130,16,10));
494 explain extended select coercibility(conv(130,16,10));
495 explain extended select length('\n\t\r\b\0\_\%\\');
496 explain extended select bit_length('\n\t\r\b\0\_\%\\');
497 explain extended select bit_length('\n\t\r\b\0\_\%\\');
498 explain extended select concat('monty',' was here ','again');
499 explain extended select length('hello');
500 explain extended select char(ascii('h'));
501 explain extended select ord('h');
502 explain extended select quote(1/0);
503 explain extended select crc32("123");
504 explain extended select replace('aaaa','a','b');
505 explain extended select insert('txs',2,1,'hi');
506 explain extended select left(_latin2'a',1);
507 explain extended select right(_latin2'a',1);
508 explain extended select lcase(_latin2'a');
509 explain extended select ucase(_latin2'a');
510 explain extended select SUBSTR('abcdefg',3,2);
511 explain extended select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2);
512 explain extended select trim(_latin2' a ');
513 explain extended select ltrim(_latin2' a ');
514 explain extended select rtrim(_latin2' a ');
515 explain extended select decode(encode(repeat("a",100000),"monty"),"monty");
518 # lpad returns incorrect result (Bug #2182)
521 SELECT lpad(12345, 5, "#");
524 # Problem the the CONV() function (Bug #2972)
527 SELECT conv(71, 10, 36), conv('1Z', 36, 10);
528 SELECT conv(71, 10, 37), conv('1Z', 37, 10), conv(0,1,10),conv(0,0,10), conv(0,-1,10);
531 # Bug in SUBSTRING when mixed with CONCAT and ORDER BY (Bug #3089)
534 create table t1 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8;
535 insert into t1 values (1,'aaaaaaaaaa'), (2,'bbbbbbbbbb');
536 create table t2 (id int(1), str varchar(10)) DEFAULT CHARSET=utf8;
537 insert into t2 values (1,'cccccccccc'), (2,'dddddddddd');
538 select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2 
539 where t2.id=t1.id order by name;
540 drop table t1, t2;
543 # Test case for conversion of long string value to integer (Bug #3472)
546 create table t1 (c1 INT, c2 INT UNSIGNED);
547 insert into t1 values ('21474836461','21474836461');
548 insert into t1 values ('-21474836461','-21474836461');
549 show warnings;
550 select * from t1;
551 drop table t1;
554 # Bug #4878: LEFT() in integer/float context
557 select left(1234, 3) + 0;
560 # Bug #7101: bug with LEFT() when used as a field in GROUP BY aggregation
562 create table t1 (a int not null primary key, b varchar(40), c datetime);
563 insert into t1 (a,b,c) values (1,'Tom','2004-12-10 12:13:14'),(2,'ball games','2004-12-10 12:13:14'), (3,'Basil','2004-12-10 12:13:14'), (4,'Dean','2004-12-10 12:13:14'),(5,'Ellis','2004-12-10 12:13:14'), (6,'Serg','2004-12-10 12:13:14'), (7,'Sergei','2004-12-10 12:13:14'),(8,'Georg','2004-12-10 12:13:14'),(9,'Salle','2004-12-10 12:13:14'),(10,'Sinisa','2004-12-10 12:13:14'); 
564 select count(*) as total, left(c,10) as reg from t1 group by reg order by reg desc limit 0,12;
565 drop table t1;
568 # Bug#7455 unexpected result: TRIM(<NULL> FROM <whatever>) gives NOT NULL
569 # According to ANSI if one of the TRIM arguments is NULL, then the result
570 # must be NULL too.
572 select trim(null from 'kate') as "must_be_null";
573 select trim('xyz' from null) as "must_be_null";
574 select trim(leading NULL from 'kate') as "must_be_null";
575 select trim(trailing NULL from 'xyz') as "must_be_null";
578 # Bug #7751 - conversion for a bigint unsigned constant 
581 CREATE TABLE t1 (
582   id int(11) NOT NULL auto_increment,
583   a bigint(20) unsigned default NULL,
584   PRIMARY KEY  (id)
585 ) ENGINE=MyISAM;
587 INSERT INTO t1 VALUES
588 ('0','16307858876001849059');
590 SELECT CONV('e251273eb74a8ee3', 16, 10);
592 EXPLAIN 
593 SELECT id
594   FROM t1
595   WHERE a = 16307858876001849059;
597 EXPLAIN 
598   SELECT id
599   FROM t1
600   WHERE a = CONV('e251273eb74a8ee3', 16, 10);
602 DROP TABLE t1;
605 # Bug #6317: string function CHAR, parameter is NULL, wrong result
607 SELECT CHAR(NULL,121,83,81,'76') as my_column;
608 SELECT CHAR_LENGTH(CHAR(NULL,121,83,81,'76')) as my_column;
610 # Test case for bug #8669: null aes_decrypt result in order by query
613 CREATE TABLE t1 (id int PRIMARY KEY, str char(255) NOT NULL);
614 CREATE TABLE t2 (id int NOT NULL UNIQUE);
615 INSERT INTO t2 VALUES (1),(2);
616 INSERT INTO t1 VALUES (1, aes_encrypt('foo', 'bar'));
617 INSERT INTO t1 VALUES (2, 'not valid');
619 SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id;
620 SELECT t1.id, aes_decrypt(str, 'bar') FROM t1, t2 WHERE t1.id = t2.id
621  ORDER BY t1.id;
623 DROP TABLE t1, t2;
626 # Bug #10944: Mishandling of NULL arguments in FIELD()
628 select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
629 select field(NULL,1,2,NULL), field(NULL,1,2,0);
632 # Bug #10124: access by integer index with a string key that is not a number  
635 CREATE TABLE t1 (str varchar(20) PRIMARY KEY);
636 CREATE TABLE t2 (num int primary key);
637 INSERT INTO t1 VALUES ('notnumber');
638 INSERT INTO t2 VALUES (0), (1); 
640 SELECT * FROM t1, t2 WHERE num=str;
641 SELECT * FROM t1, t2 WHERE num=substring(str from 1 for 6);
643 DROP TABLE t1,t2;
646 # Bug #11469: NOT NULL optimization wrongly used for arguments of CONCAT_WS  
649 CREATE TABLE t1(
650   id int(11) NOT NULL auto_increment,
651   pc int(11) NOT NULL default '0',
652   title varchar(20) default NULL,
653   PRIMARY KEY (id)
656 INSERT INTO t1 VALUES
657   (1, 0, 'Main'),
658   (2, 1, 'Toys'),
659   (3, 1, 'Games');
661 SELECT t1.id, CONCAT_WS('->', t3.title, t2.title, t1.title) as col1
662   FROM t1 LEFT JOIN t1 AS t2 ON t1.pc=t2.id
663           LEFT JOIN t1 AS t3 ON t2.pc=t3.id;
664 SELECT t1.id, CONCAT_WS('->', t3.title, t2.title, t1.title) as col1
665   FROM t1 LEFT JOIN t1 AS t2 ON t1.pc=t2.id
666           LEFT JOIN t1 AS t3 ON t2.pc=t3.id
667     WHERE CONCAT_WS('->', t3.title, t2.title, t1.title) LIKE '%Toys%';
669 DROP TABLE t1;
672 CREATE TABLE t1(
673   trackid     int(10) unsigned NOT NULL auto_increment,
674   trackname   varchar(100) NOT NULL default '',
675   PRIMARY KEY (trackid)
678 CREATE TABLE t2(
679   artistid    int(10) unsigned NOT NULL auto_increment,
680   artistname  varchar(100) NOT NULL default '',
681   PRIMARY KEY (artistid)
684 CREATE TABLE t3(
685   trackid     int(10) unsigned NOT NULL,
686   artistid    int(10) unsigned NOT NULL,
687   PRIMARY KEY (trackid,artistid)
690 INSERT INTO t1 VALUES (1, 'April In Paris'), (2, 'Autumn In New York');
691 INSERT INTO t2 VALUES (1, 'Vernon Duke');
692 INSERT INTO t3 VALUES (1,1);
694 SELECT CONCAT_WS(' ', trackname, artistname) trackname, artistname
695   FROM t1 LEFT JOIN t3 ON t1.trackid=t3.trackid
696           LEFT JOIN t2 ON t2.artistid=t3.artistid
697     WHERE CONCAT_WS(' ', trackname, artistname) LIKE '%In%';
699 DROP TABLE t1,t2,t3;
702 # Correct length reporting from substring() (BUG#10269)
704 create table t1 (b varchar(5));
705 insert t1 values ('ab'), ('abc'), ('abcd'), ('abcde');
706 select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1;
707 select * from (select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1) t;
708 drop table t1;
711 # Bug #9854  hex() and out of range handling
713 select hex(29223372036854775809), hex(-29223372036854775809);
716 # Bug #11311: Incorrect length returned from LPAD() and RPAD()
718 create table t1 (i int);
719 insert into t1 values (1000000000),(1);
720 --enable_metadata
721 select lpad(i, 7, ' ') as t from t1;
722 select rpad(i, 7, ' ') as t from t1;
723 --disable_metadata
724 drop table t1;
727 # Bug #10418: LOAD_FILE does not behave like in manual if file does not exist
730 select load_file("lkjlkj");
731 select ifnull(load_file("lkjlkj"),"it's null");
734 # Bug#15351: Wrong collation used for comparison of md5() and sha()
735 # parameter can lead to a wrong result.
737 create table t1 (f1 varchar(4), f2 varchar(64), unique key k1 (f1,f2));
738 insert into t1 values ( 'test',md5('test')), ('test', sha('test'));
739 select * from t1 where f1='test' and (f2= md5("test") or f2= md5("TEST"));
740 select * from t1 where f1='test' and (f2= md5("TEST") or f2= md5("test"));
741 select * from t1 where f1='test' and (f2= sha("test") or f2= sha("TEST"));
742 select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test"));
743 drop table t1;
746 # Bug#18243: REVERSE changes its argument
749 CREATE TABLE t1 (a varchar(10));
750 INSERT INTO t1 VALUES ('abc'), ('xyz');
752 SELECT a, CONCAT(a,' ',a) AS c FROM t1
753   HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
755 SELECT a, CONCAT(a,' ',a) AS c FROM t1
756   HAVING LEFT(CONCAT(a,' ',a),
757               LENGTH(CONCAT(a,' ',a))-
758                      INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
760 DROP TABLE t1;
763 # Bug#17526: WRONG PRINT for TRIM FUNCTION with two arguments
766 CREATE TABLE t1 (s varchar(10));
767 INSERT INTO t1 VALUES ('yadda'), ('yaddy');
769 EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab';
770 EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab';
771 EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab';
772 EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab';
773 EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab';
775 DROP TABLE t1;
778 # Bug#23409: ENCODE() and DECODE() functions aren't printed correctly
780 create table t1(f1 varchar(4));
781 explain extended select encode(f1,'zxcv') as 'enc' from t1;
782 explain extended select decode(f1,'zxcv') as 'enc' from t1;
783 drop table t1;
786 # Bug #31758 inet_ntoa, oct, crashes server with null + filesort 
788 create table t1 (a bigint not null)engine=myisam;
789 insert into t1 set a = 1024*1024*1024*4;
790 delete from t1 order by (inet_ntoa(a)) desc limit 10;
791 drop table t1;
792 create table t1 (a char(36) not null)engine=myisam;
793 insert ignore into t1 set a = ' ';
794 insert ignore into t1 set a = ' ';
795 select * from t1 order by (oct(a));
796 drop table t1;
798 --echo End of 4.1 tests
801 # Bug #13361: SELECT FORMAT(<decimal field with null>, 2) crashes
803 create table t1 (d decimal default null);
804 insert into t1 values (null);
805 select format(d, 2) from t1;
806 drop table t1;
809 # Bug #14676: substring_index() returns incorrect results
811 create table t1 (c varchar(40));
812 insert into t1 values ('y,abc'),('y,abc');
813 select c, substring_index(lcase(c), @q:=',', -1) as res from t1;
814 drop table t1;
817 # Bug #17043: Casting trimmed string to decimal loses precision
819 select cast(rtrim('  20.06 ') as decimal(19,2));
820 select cast(ltrim('  20.06 ') as decimal(19,2));
821 select cast(rtrim(ltrim('  20.06 ')) as decimal(19,2));
824 # Bug #13975: "same string" + 0 has 2 different results
826 select conv("18383815659218730760",10,10) + 0;
827 select "18383815659218730760" + 0;
830 # Bug #21698: substitution of a string field for a constant under a function 
833 CREATE TABLE t1 (code varchar(10));
834 INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13');
836 SELECT ASCII(code), code FROM t1 WHERE code='A12';
837 SELECT ASCII(code), code FROM t1 WHERE code='A12' AND ASCII(code)=65;
839 INSERT INTO t1 VALUES ('a12 '), ('A12  ');
841 SELECT LENGTH(code), code FROM t1 WHERE code='A12';
842 SELECT LENGTH(code), code FROM t1 WHERE code='A12' AND LENGTH(code)=5;
844 ALTER TABLE t1 ADD INDEX (code);
845 CREATE TABLE t2 (id varchar(10) PRIMARY KEY);
846 INSERT INTO t2 VALUES ('a11'), ('a12'), ('a13'), ('a14');
848 SELECT * FROM t1 INNER JOIN t2 ON t1.code=t2.id 
849   WHERE t2.id='a12' AND (LENGTH(code)=5 OR code < 'a00');
850 EXPLAIN EXTENDED 
851 SELECT * FROM t1 INNER JOIN t2 ON code=id 
852   WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00');
854 DROP TABLE t1,t2;
857 # Bug#22684: The Functions ENCODE, DECODE and FORMAT are not real functions
860 select encode(NULL, NULL);
861 select encode("data", NULL);
862 select encode(NULL, "password");
864 select decode(NULL, NULL);
865 select decode("data", NULL);
866 select decode(NULL, "password");
868 select format(NULL, NULL);
869 select format(pi(), NULL);
870 select format(NULL, 2);
872 select benchmark(NULL, NULL);
873 select benchmark(0, NULL);
874 select benchmark(100, NULL);
875 select benchmark(NULL, 1+1);
878 # Bug #20752: BENCHMARK with many iterations returns too quickly
881 # not a string, but belongs with the above Bug#22684
882 select benchmark(-1, 1);
885 # Please note:
886 # 1) The collation of the password is irrelevant, the encryption uses
887 # the binary representation of the string without charset/collation.
888 # 2) These tests can not print the encoded text directly, because it's binary,
889 # and doing this would cause problems with source control.
890 # Instead, an md5() checksum is used, to verify the result indirectly.
891 # 3) Each md5() result must be identical.
892 # 4) The md5() result must never change, and must be stable across releases.
894 set @password="password";
895 set @my_data="clear text to encode";
896 select md5(encode(@my_data, "password"));
897 select md5(encode(@my_data, _utf8 "password"));
898 select md5(encode(@my_data, binary "password"));
899 select md5(encode(@my_data, _latin1 "password"));
900 select md5(encode(@my_data, _koi8r "password"));
901 select md5(encode(@my_data, (select "password" from dual)));
902 select md5(encode(@my_data, concat("pass", "word")));
903 select md5(encode(@my_data, @password));
905 set @my_data="binary encoded data";
906 select md5(decode(@my_data, "password"));
907 select md5(decode(@my_data, _utf8 "password"));
908 select md5(decode(@my_data, binary "password"));
909 select md5(decode(@my_data, _latin1 "password"));
910 select md5(decode(@my_data, _koi8r "password"));
911 select md5(decode(@my_data, (select "password" from dual)));
912 select md5(decode(@my_data, concat("pass", "word")));
913 select md5(decode(@my_data, @password));
915 set @dec=5;
916 select format(pi(), (1+1));
917 select format(pi(), (select 3 from dual));
918 select format(pi(), @dec);
920 set @bench_count=10;
921 select benchmark(10, pi());
922 select benchmark(5+5, pi());
923 select benchmark((select 10 from dual), pi());
924 select benchmark(@bench_count, pi());
928 # Bug #10963
929 # 4294967296 18446744073709551616
931 select locate('he','hello',-2);
932 select locate('lo','hello',-4294967295);
933 select locate('lo','hello',4294967295);
934 select locate('lo','hello',-4294967296);
935 select locate('lo','hello',4294967296);
936 select locate('lo','hello',-4294967297);
937 select locate('lo','hello',4294967297);
938 select locate('lo','hello',-18446744073709551615);
939 select locate('lo','hello',18446744073709551615);
940 select locate('lo','hello',-18446744073709551616);
941 select locate('lo','hello',18446744073709551616);
942 select locate('lo','hello',-18446744073709551617);
943 select locate('lo','hello',18446744073709551617);
945 select left('hello', 10);
946 select left('hello', 0);
947 select left('hello', -1);
948 select left('hello', -4294967295);
949 select left('hello', 4294967295);
950 select left('hello', -4294967296);
951 select left('hello', 4294967296);
952 select left('hello', -4294967297);
953 select left('hello', 4294967297);
954 select left('hello', -18446744073709551615);
955 select left('hello', 18446744073709551615);
956 select left('hello', -18446744073709551616);
957 select left('hello', 18446744073709551616);
958 select left('hello', -18446744073709551617);
959 select left('hello', 18446744073709551617);
961 select right('hello', 10);
962 select right('hello', 0);
963 select right('hello', -1);
964 select right('hello', -4294967295);
965 select right('hello', 4294967295);
966 select right('hello', -4294967296);
967 select right('hello', 4294967296);
968 select right('hello', -4294967297);
969 select right('hello', 4294967297);
970 select right('hello', -18446744073709551615);
971 select right('hello', 18446744073709551615);
972 select right('hello', -18446744073709551616);
973 select right('hello', 18446744073709551616);
974 select right('hello', -18446744073709551617);
975 select right('hello', 18446744073709551617);
977 select substring('hello', 2, -1);
979 select substring('hello', -1, 1);
980 select substring('hello', -2, 1);
981 select substring('hello', -4294967295, 1);
982 select substring('hello', 4294967295, 1);
983 select substring('hello', -4294967296, 1);
984 select substring('hello', 4294967296, 1);
985 select substring('hello', -4294967297, 1);
986 select substring('hello', 4294967297, 1);
987 select substring('hello', -18446744073709551615, 1);
988 select substring('hello', 18446744073709551615, 1);
989 select substring('hello', -18446744073709551616, 1);
990 select substring('hello', 18446744073709551616, 1);
991 select substring('hello', -18446744073709551617, 1);
992 select substring('hello', 18446744073709551617, 1);
993 select substring('hello', 1, -1);
994 select substring('hello', 1, -4294967295);
995 select substring('hello', 1, 4294967295);
996 select substring('hello', 1, -4294967296);
997 select substring('hello', 1, 4294967296);
998 select substring('hello', 1, -4294967297);
999 select substring('hello', 1, 4294967297);
1000 select substring('hello', 1, -18446744073709551615);
1001 select substring('hello', 1, 18446744073709551615);
1002 select substring('hello', 1, -18446744073709551616);
1003 select substring('hello', 1, 18446744073709551616);
1004 select substring('hello', 1, -18446744073709551617);
1005 select substring('hello', 1, 18446744073709551617);
1006 select substring('hello', -1, -1);
1007 select substring('hello', -4294967295, -4294967295);
1008 select substring('hello', 4294967295, 4294967295);
1009 select substring('hello', -4294967296, -4294967296);
1010 select substring('hello', 4294967296, 4294967296);
1011 select substring('hello', -4294967297, -4294967297);
1012 select substring('hello', 4294967297, 4294967297);
1013 select substring('hello', -18446744073709551615, -18446744073709551615);
1014 select substring('hello', 18446744073709551615, 18446744073709551615);
1015 select substring('hello', -18446744073709551616, -18446744073709551616);
1016 select substring('hello', 18446744073709551616, 18446744073709551616);
1017 select substring('hello', -18446744073709551617, -18446744073709551617);
1018 select substring('hello', 18446744073709551617, 18446744073709551617);
1020 select insert('hello', -1, 1, 'hi');
1021 select insert('hello', -4294967295, 1, 'hi');
1022 select insert('hello', 4294967295, 1, 'hi');
1023 select insert('hello', -4294967296, 1, 'hi');
1024 select insert('hello', 4294967296, 1, 'hi');
1025 select insert('hello', -4294967297, 1, 'hi');
1026 select insert('hello', 4294967297, 1, 'hi');
1027 select insert('hello', -18446744073709551615, 1, 'hi');
1028 select insert('hello', 18446744073709551615, 1, 'hi');
1029 select insert('hello', -18446744073709551616, 1, 'hi');
1030 select insert('hello', 18446744073709551616, 1, 'hi');
1031 select insert('hello', -18446744073709551617, 1, 'hi');
1032 select insert('hello', 18446744073709551617, 1, 'hi');
1033 select insert('hello', 1, -1, 'hi');
1034 select insert('hello', 1, -4294967295, 'hi');
1035 select insert('hello', 1, 4294967295, 'hi');
1036 select insert('hello', 1, -4294967296, 'hi');
1037 select insert('hello', 1, 4294967296, 'hi');
1038 select insert('hello', 1, -4294967297, 'hi');
1039 select insert('hello', 1, 4294967297, 'hi');
1040 select insert('hello', 1, -18446744073709551615, 'hi');
1041 select insert('hello', 1, 18446744073709551615, 'hi');
1042 select insert('hello', 1, -18446744073709551616, 'hi');
1043 select insert('hello', 1, 18446744073709551616, 'hi');
1044 select insert('hello', 1, -18446744073709551617, 'hi');
1045 select insert('hello', 1, 18446744073709551617, 'hi');
1046 select insert('hello', -1, -1, 'hi');
1047 select insert('hello', -4294967295, -4294967295, 'hi');
1048 select insert('hello', 4294967295, 4294967295, 'hi');
1049 select insert('hello', -4294967296, -4294967296, 'hi');
1050 select insert('hello', 4294967296, 4294967296, 'hi');
1051 select insert('hello', -4294967297, -4294967297, 'hi');
1052 select insert('hello', 4294967297, 4294967297, 'hi');
1053 select insert('hello', -18446744073709551615, -18446744073709551615, 'hi');
1054 select insert('hello', 18446744073709551615, 18446744073709551615, 'hi');
1055 select insert('hello', -18446744073709551616, -18446744073709551616, 'hi');
1056 select insert('hello', 18446744073709551616, 18446744073709551616, 'hi');
1057 select insert('hello', -18446744073709551617, -18446744073709551617, 'hi');
1058 select insert('hello', 18446744073709551617, 18446744073709551617, 'hi');
1060 select repeat('hello', -1);
1061 select repeat('hello', -4294967295);
1062 select repeat('hello', 4294967295);
1063 select repeat('hello', -4294967296);
1064 select repeat('hello', 4294967296);
1065 select repeat('hello', -4294967297);
1066 select repeat('hello', 4294967297);
1067 select repeat('hello', -18446744073709551615);
1068 select repeat('hello', 18446744073709551615);
1069 select repeat('hello', -18446744073709551616);
1070 select repeat('hello', 18446744073709551616);
1071 select repeat('hello', -18446744073709551617);
1072 select repeat('hello', 18446744073709551617);
1074 select space(-1);
1075 select space(-4294967295);
1076 select space(4294967295);
1077 select space(-4294967296);
1078 select space(4294967296);
1079 select space(-4294967297);
1080 select space(4294967297);
1081 select space(-18446744073709551615);
1082 select space(18446744073709551615);
1083 select space(-18446744073709551616);
1084 select space(18446744073709551616);
1085 select space(-18446744073709551617);
1086 select space(18446744073709551617);
1088 select rpad('hello', -1, '1');
1089 select rpad('hello', -4294967295, '1');
1090 select rpad('hello', 4294967295, '1');
1091 select rpad('hello', -4294967296, '1');
1092 select rpad('hello', 4294967296, '1');
1093 select rpad('hello', -4294967297, '1');
1094 select rpad('hello', 4294967297, '1');
1095 select rpad('hello', -18446744073709551615, '1');
1096 select rpad('hello', 18446744073709551615, '1');
1097 select rpad('hello', -18446744073709551616, '1');
1098 select rpad('hello', 18446744073709551616, '1');
1099 select rpad('hello', -18446744073709551617, '1');
1100 select rpad('hello', 18446744073709551617, '1');
1102 select lpad('hello', -1, '1');
1103 select lpad('hello', -4294967295, '1');
1104 select lpad('hello', 4294967295, '1');
1105 select lpad('hello', -4294967296, '1');
1106 select lpad('hello', 4294967296, '1');
1107 select lpad('hello', -4294967297, '1');
1108 select lpad('hello', 4294967297, '1');
1109 select lpad('hello', -18446744073709551615, '1');
1110 select lpad('hello', 18446744073709551615, '1');
1111 select lpad('hello', -18446744073709551616, '1');
1112 select lpad('hello', 18446744073709551616, '1');
1113 select lpad('hello', -18446744073709551617, '1');
1114 select lpad('hello', 18446744073709551617, '1');
1118 # BUG#17047: CHAR() and IN() can return NULL without signaling NULL
1119 # result
1121 SET @orig_sql_mode = @@SQL_MODE;
1122 SET SQL_MODE=traditional;
1124 SELECT CHAR(0xff,0x8f USING utf8);
1125 SELECT CHAR(0xff,0x8f USING utf8) IS NULL;
1127 SET SQL_MODE=@orig_sql_mode;
1130 # Bug #24947: problem with some string function with unsigned int parameters
1133 select substring('abc', cast(2 as unsigned int));
1134 select repeat('a', cast(2 as unsigned int));
1135 select rpad('abc', cast(5 as unsigned integer), 'x');
1136 select lpad('abc', cast(5 as unsigned integer), 'x');
1139 # Bug#15757: Wrong SUBSTRING() result when a tmp table was employed.
1141 create table t1(f1 longtext);
1142 insert into t1 values ("123"),("456");
1143 select substring(f1,1,1) from t1 group by 1;
1144 create table t2(f1 varchar(3));
1145 insert into t1 values ("123"),("456");
1146 select substring(f1,4,1), substring(f1,-4,1) from t2;
1147 drop table t1,t2;
1150 # Bug #25197 :repeat function returns null when using table field directly as count
1153 --disable_warnings
1154 DROP TABLE IF EXISTS t1;
1155 --enable_warnings
1157 CREATE TABLE `t1` (
1158   `id` varchar(20) NOT NULL,
1159   `tire` tinyint(3) unsigned NOT NULL,
1160   PRIMARY KEY (`id`)
1163 INSERT INTO `t1` (`id`, `tire`) VALUES ('A', 0), ('B', 1),('C', 2);
1165 SELECT REPEAT( '#', tire ) AS A,
1166        REPEAT( '#', tire % 999 ) AS B, tire FROM `t1`;
1168 SELECT REPEAT('0', CAST(0 AS UNSIGNED));
1169 SELECT REPEAT('0', -2);
1170 SELECT REPEAT('0', 2);
1172 DROP TABLE t1;
1175 # Bug #26537: UNHEX() IS NULL comparison fails
1177 SELECT UNHEX('G');
1178 SELECT UNHEX('G') IS NULL;
1181 # Bug #26281: INSERT() function mishandles NUL on boundary condition
1183 SELECT INSERT('abc', 3, 3, '1234');
1184 SELECT INSERT('abc', 4, 3, '1234');
1185 SELECT INSERT('abc', 5, 3, '1234');
1186 SELECT INSERT('abc', 6, 3, '1234');
1189 # Bug #27530: Grouping on crc32, or create table select crc32
1191 CREATE TABLE t1 (a INT);
1192 CREATE VIEW v1 AS SELECT CRC32(a) AS C FROM t1;
1194 INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
1195 SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1;
1196 SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1 ORDER BY 1;
1197 SELECT * FROM (SELECT CRC32(a) FROM t1) t2;
1198 CREATE TABLE t2 SELECT CRC32(a) FROM t1;
1199 desc t2;
1200 SELECT * FROM v1;
1201 SELECT * FROM (SELECT * FROM v1) x;
1203 DROP TABLE t1, t2;
1204 DROP VIEW v1;
1207 # Bug #27932: LOCATE with argument evaluated to NULL
1210 SELECT LOCATE('foo', NULL) FROM DUAL;
1211 SELECT LOCATE(NULL, 'o') FROM DUAL;
1212 SELECT LOCATE(NULL, NULL) FROM DUAL;
1213 SELECT LOCATE('foo', NULL) IS NULL FROM DUAL;
1214 SELECT LOCATE(NULL, 'o') IS NULL FROM DUAL;
1215 SELECT LOCATE(NULL, NULL) IS NULL FROM DUAL;
1216 SELECT ISNULL(LOCATE('foo', NULL)) FROM DUAL;
1217 SELECT ISNULL(LOCATE(NULL, 'o')) FROM DUAL;
1218 SELECT ISNULL(LOCATE(NULL, NULL)) FROM DUAL;
1219 SELECT LOCATE('foo', NULL) <=> NULL FROM DUAL;
1220 SELECT LOCATE(NULL, 'o') <=> NULL FROM DUAL;
1221 SELECT LOCATE(NULL, NULL) <=> NULL FROM DUAL;
1223 CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a varchar(10), p varchar(10));
1225 INSERT INTO t1 VALUES (1, 'foo', 'o');
1226 INSERT INTO t1 VALUES (2, 'foo', NULL);
1227 INSERT INTO t1 VALUES (3, NULL, 'o');
1228 INSERT INTO t1 VALUES (4, NULL, NULL);
1230 SELECT id, LOCATE(a,p) FROM t1;
1231 SELECT id, LOCATE(a,p) IS NULL FROM t1;
1232 SELECT id, ISNULL(LOCATE(a,p)) FROM t1;
1233 SELECT id, LOCATE(a,p) <=> NULL FROM t1;
1234 SELECT id FROM t1 WHERE LOCATE(a,p) IS NULL;
1235 SELECT id FROM t1 WHERE LOCATE(a,p) <=> NULL; 
1237 DROP TABLE t1;
1240 # Bug #27130: SUBSTR with UNSIGNED 0 as the last argument
1243 SELECT SUBSTR('foo',1,0) FROM DUAL;
1244 SELECT SUBSTR('foo',1,CAST(0 AS SIGNED)) FROM DUAL;
1245 SELECT SUBSTR('foo',1,CAST(0 AS UNSIGNED)) FROM DUAL;
1247 CREATE TABLE t1 (a varchar(10), len int unsigned);
1248 INSERT INTO t1 VALUES ('bar', 2), ('foo', 0);
1250 SELECT SUBSTR(a,1,len) FROM t1;
1252 DROP TABLE t1; 
1255 # Bug #28850: Potential bugs related to the return type of the CHAR function
1258 CREATE TABLE t1 AS SELECT CHAR(0x414243) as c1;
1259 SELECT HEX(c1) from t1;
1260 DROP TABLE t1;
1262 CREATE VIEW v1 AS SELECT CHAR(0x414243) as c1;
1263 SELECT HEX(c1) from v1;
1264 DROP VIEW v1;
1267 # Bug #35558 Wrong server metadata blows up the client
1269 create table t1(a float);
1270 insert into t1 values (1.33);
1271 --enable_metadata
1272 select format(a, 2) from t1;
1273 --disable_metadata
1274 drop table t1;
1277 # Bug #41868: crash or memory overrun with concat + upper, date_format functions
1280 CREATE TABLE t1 (c DATE, aa VARCHAR(30));
1281 INSERT INTO t1 VALUES ('2008-12-31','aaaaaa');
1282 SELECT DATE_FORMAT(c, GET_FORMAT(DATE, 'eur')) h, CONCAT(UPPER(aa),', ', aa) i FROM t1;
1283 DROP TABLE t1;
1286 --echo #
1287 --echo # BUG#44774: load_file function produces valgrind warnings
1288 --echo #
1289 CREATE TABLE t1 (a TINYBLOB);
1290 INSERT INTO t1 VALUES ('aaaaaaaa');
1291 SELECT LOAD_FILE(a) FROM t1;
1292 DROP TABLE t1;
1295 # Bug#46815 CONCAT_WS returning wrong data
1297 CREATE TABLE t1 (f2 VARCHAR(20));
1298 CREATE TABLE t2 (f2 VARCHAR(20));
1300 INSERT INTO t1 VALUES ('MIN'),('MAX');
1301 INSERT INTO t2 VALUES ('LOAD');
1303 SELECT CONCAT_WS('_', (SELECT t2.f2 FROM t2), t1.f2) AS concat_name FROM t1;
1305 DROP TABLE t1, t2;
1308 --echo End of 5.0 tests
1311 # Bug#44358 valgrind errors with decode() function
1313 --disable_warnings
1314 drop table if exists t1;
1315 --enable_warnings
1316 create table t1(f1 tinyint default null)engine=myisam;
1317 insert into t1 values (-1),(null);
1318 explain select 1 as a from t1,(select decode(f1,f1) as b from t1) a;
1319 explain select 1 as a from t1,(select encode(f1,f1) as b from t1) a;
1320 drop table t1;
1322 --echo #
1323 --echo # Bug#49141: Encode function is significantly slower in 5.1 compared to 5.0
1324 --echo #
1326 --disable_warnings
1327 DROP TABLE IF EXISTS t1, t2;
1328 --enable_warnings
1330 CREATE TABLE t1 (a VARCHAR(20), b INT);
1331 CREATE TABLE t2 (a VARCHAR(20), b INT);
1333 INSERT INTO t1 VALUES ('ABC', 1);
1334 INSERT INTO t2 VALUES ('ABC', 1);
1336 SELECT DECODE((SELECT ENCODE('secret', t1.a) FROM t1,t2 WHERE t1.a = t2.a GROUP BY t1.b), t2.a)
1337   FROM t1,t2 WHERE t1.b = t1.b > 0 GROUP BY t2.b;
1339 SELECT DECODE((SELECT ENCODE('secret', 'ABC') FROM t1,t2 WHERE t1.a = t2.a GROUP BY t1.b), t2.a)
1340   FROM t1,t2 WHERE t1.b = t1.b > 0 GROUP BY t2.b;
1342 SELECT DECODE((SELECT ENCODE('secret', t1.a) FROM t1,t2 WHERE t1.a = t2.a GROUP BY t1.b), 'ABC')
1343   FROM t1,t2 WHERE t1.b = t1.b > 0 GROUP BY t2.b;
1345 TRUNCATE TABLE t1;
1346 TRUNCATE TABLE t2;
1348 INSERT INTO t1 VALUES ('EDF', 3), ('BCD', 2), ('ABC', 1);
1349 INSERT INTO t2 VALUES ('EDF', 3), ('BCD', 2), ('ABC', 1);
1351 SELECT DECODE((SELECT ENCODE('secret', t1.a) FROM t1,t2 WHERE t1.a = t2.a GROUP BY t1.b LIMIT 1), t2.a)
1352   FROM t2 WHERE t2.b = 1 GROUP BY t2.b;
1354 DROP TABLE t1, t2;
1356 --echo #
1357 --echo # Bug#52164 Assertion failed: param.sort_length, file .\filesort.cc, line 149
1358 --echo #
1359 CREATE TABLE t1 (a LONGBLOB NOT NULL);
1360 INSERT INTO t1 VALUES (''),('');
1361 SELECT 1 FROM t1, t1 t2
1362 ORDER BY QUOTE(t1.a);
1363 DROP TABLE t1;
1365 --echo #
1366 --echo # Bug#57913 large negative number to string conversion functions crash
1367 --echo # Bug#57810 case/when/then : Assertion failed: length || !scale
1368 --echo #
1369 SELECT '1' IN ('1', SUBSTRING(-9223372036854775809, 1));
1370 SELECT CONVERT(('' IN (REVERSE(CAST(('') AS DECIMAL)), '')), CHAR(3));
1372 --echo # 
1373 --echo # Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail
1374 --echo # and other crashes
1375 --echo #
1376 CREATE TABLE t1 ( a TEXT );
1377 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1378 --eval SELECT 'aaaaaaaaaaaaaa' INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/bug58165.txt';
1379 SELECT insert( substring_index( 'a', 'a', 'b' ), 1, 0, 'x' );
1380 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1381 --eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/bug58165.txt' INTO TABLE t1;
1382 SELECT * FROM t1;
1383 DROP TABLE t1;
1385 --echo End of 5.1 tests