~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# Description
2
# -----------
3
# Testing string functions
4
5
--disable_warnings
6
drop table if exists t1,t2;
7
--enable_warnings
8
9
select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo';
10
select 'hello' 'monty';
11
select length('\n\t\r\b\0\_\%\\');
12
select char_length('\n\t\r\b\0\_\%\\');
1086.5.2 by Devananda
added simple test case
13
select character_length('\n\t\r\b\0\_\%\\');
512 by Brian Aker
Adding back more test cases.
14
select length('\n\t\n\b\0\\_\\%\\');
1 by brian
clean slate
15
select concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h');
16
select hex(char(256));
17
select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ;
18
select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE'); 
19
select position(binary 'll' in 'hello'),position('a' in binary 'hello');
20
#
21
# Bug#11728 string function LEFT,
22
# strange undocumented behaviour, strict mode
23
#
24
select left('hello',null), right('hello',null);
25
select left('hello',2),right('hello',2),substring('hello',2,2),mid('hello',1,5) ;
26
select concat('',left(right(concat('what ',concat('is ','happening')),9),4),'',substring('monty',5,1)) ;
27
select substring_index('www.tcx.se','.',-2),substring_index('www.tcx.se','.',1);
28
select substring_index('www.tcx.se','tcx',1),substring_index('www.tcx.se','tcx',-1);
29
select substring_index('.tcx.se','.',-2),substring_index('.tcx.se','.tcx',-1);
30
select substring_index('aaaaaaaaa1','a',1);
31
select substring_index('aaaaaaaaa1','aa',1);
32
select substring_index('aaaaaaaaa1','aa',2);
33
select substring_index('aaaaaaaaa1','aa',3);
34
select substring_index('aaaaaaaaa1','aa',4);
35
select substring_index('aaaaaaaaa1','aa',5);
36
select substring_index('aaaaaaaaa1','aaa',1);
37
select substring_index('aaaaaaaaa1','aaa',2);
38
select substring_index('aaaaaaaaa1','aaa',3);
39
select substring_index('aaaaaaaaa1','aaa',4);
40
select substring_index('aaaaaaaaa1','aaaa',1);
41
select substring_index('aaaaaaaaa1','aaaa',2);
42
select substring_index('aaaaaaaaa1','1',1);
43
select substring_index('aaaaaaaaa1','a',-1);
44
select substring_index('aaaaaaaaa1','aa',-1);
45
select substring_index('aaaaaaaaa1','aa',-2);
46
select substring_index('aaaaaaaaa1','aa',-3);
47
select substring_index('aaaaaaaaa1','aa',-4);
48
select substring_index('aaaaaaaaa1','aa',-5);
49
select substring_index('aaaaaaaaa1','aaa',-1);
50
select substring_index('aaaaaaaaa1','aaa',-2);
51
select substring_index('aaaaaaaaa1','aaa',-3);
52
select substring_index('aaaaaaaaa1','aaa',-4);
53
select substring_index('the king of thethe hill','the',-2);
54
select substring_index('the king of the the hill','the',-2);
55
select substring_index('the king of the  the hill','the',-2);
56
select substring_index('the king of the  the hill',' the ',-1);
57
select substring_index('the king of the  the hill',' the ',-2);
58
select substring_index('the king of the  the hill',' ',-1);
59
select substring_index('the king of the  the hill',' ',-2);
60
select substring_index('the king of the  the hill',' ',-3);
61
select substring_index('the king of the  the hill',' ',-4);
62
select substring_index('the king of the  the hill',' ',-5);
63
select substring_index('the king of the.the hill','the',-2);
64
select substring_index('the king of thethethe.the hill','the',-3);
65
select substring_index('the king of thethethe.the hill','the',-1);
66
select substring_index('the king of the the hill','the',1);
67
select substring_index('the king of the the hill','the',2);
68
select substring_index('the king of the the hill','the',3);
69
70
select concat(':',ltrim('  left  '),':',rtrim('  right  '),':');
71
select concat(':',trim(leading from '  left  '),':',trim(trailing from '  right  '),':');
72
select concat(':',trim(LEADING FROM ' left'),':',trim(TRAILING FROM ' right '),':');
73
select concat(':',trim(' m '),':',trim(BOTH FROM ' y '),':',trim('*' FROM '*s*'),':');
74
select concat(':',trim(BOTH 'ab' FROM 'ababmyabab'),':',trim(BOTH '*' FROM '***sql'),':');
75
select concat(':',trim(LEADING '.*' FROM '.*my'),':',trim(TRAILING '.*' FROM 'sql.*.*'),':');
76
select TRIM("foo" FROM "foo"), TRIM("foo" FROM "foook"), TRIM("foo" FROM "okfoo");
77
78
select concat_ws(', ','monty','was here','again');
79
select concat_ws(NULL,'a'),concat_ws(',',NULL,'');
80
select concat_ws(',','',NULL,'a');
81
SELECT CONCAT('"',CONCAT_WS('";"',repeat('a',60),repeat('b',60),repeat('c',60),repeat('d',100)), '"');
82
83
select insert('txs',2,1,'hi'),insert('is ',4,0,'a'),insert('txxxxt',2,4,'es');
84
select replace('aaaa','a','b'),replace('aaaa','aa','b'),replace('aaaa','a','bb'),replace('aaaa','','b'),replace('bbbb','a','c');
85
select replace(concat(lcase(concat('THIS',' ','IS',' ','A',' ')),ucase('false'),' ','test'),'FALSE','REAL') ;
86
select crc32("123");
87
select repeat('monty',5),concat('*',space(5),'*');
88
select reverse('abc'),reverse('abcd');
89
select rpad('a',4,'1'),rpad('a',4,'12'),rpad('abcd',3,'12'), rpad(11, 10 , 22), rpad("ab", 10, 22);
90
select lpad('a',4,'1'),lpad('a',4,'12'),lpad('abcd',3,'12'), lpad(11, 10 , 22);
91
select rpad(741653838,17,'0'),lpad(741653838,17,'0');
92
select rpad('abcd',7,'ab'),lpad('abcd',7,'ab');
93
select rpad('abcd',1,'ab'),lpad('abcd',1,'ab');
94
select rpad('STRING', 20, CONCAT('p','a','d') );
95
select lpad('STRING', 20, CONCAT('p','a','d') );
96
97
select LEAST(NULL,'HARRY','HARRIOT',NULL,'HAROLD'),GREATEST(NULL,'HARRY','HARRIOT',NULL,'HAROLD');
98
99
select quote('\'\"\\test');
100
select quote(concat('abc\'', '\\cba'));
101
select quote(1/0), quote('\0\Z');
102
select length(quote(concat(char(0),"test")));
103
select hex(quote(concat(char(224),char(227),char(230),char(231),char(232),char(234),char(235))));
104
select unhex(hex("foobar")), hex(unhex("1234567890ABCDEF")), unhex("345678"), unhex(NULL);
105
select hex(unhex("1")), hex(unhex("12")), hex(unhex("123")), hex(unhex("1234")), hex(unhex("12345")), hex(unhex("123456"));
106
107
#
108
# Bug #6564: QUOTE(NULL
109
#
110
111
select concat('a', quote(NULL));
112
113
#
114
# Wrong usage of functions
115
#
116
117
select reverse("");
118
select insert("aa",100,1,"b"),insert("aa",1,3,"b"),left("aa",-1),substring("a",1,2);
119
select elt(2,1),field(NULL,"a","b","c"),reverse("");
120
select locate("a","b",2),locate("","a",1);
121
select ltrim("a"),rtrim("a"),trim(BOTH "" from "a"),trim(BOTH " " from "a");
122
select substring_index("www.tcx.se","",3);
123
select length(repeat("a",100000000)),length(repeat("a",1000*64));
124
select position("0" in "baaa" in (1)),position("0" in "1" in (1,2,3)),position("sql" in ("mysql"));
125
select position(("1" in (1,2,3)) in "01");
126
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)));
127
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)));
128
129
#
130
# Problem med concat
131
#
132
133
create table t1 ( domain char(50) );
134
insert into t1 VALUES ("hello.de" ), ("test.de" );
135
select domain from t1 where concat('@', trim(leading '.' from concat('.', domain))) = '@hello.de';
136
select domain from t1 where concat('@', trim(leading '.' from concat('.', domain))) = '@test.de';
137
drop table t1;
138
139
#
140
# Test bug in concat_ws
141
#
142
1063.9.3 by Brian Aker
Partial fix for tests for tmp
143
CREATE TEMPORARY TABLE t1 (
512 by Brian Aker
Adding back more test cases.
144
  id int NOT NULL,
1 by brian
clean slate
145
  title varchar(255) default NULL,
512 by Brian Aker
Adding back more test cases.
146
  prio int default NULL,
147
  category int default NULL,
148
  program int default NULL,
1 by brian
clean slate
149
  bugdesc text,
150
  created datetime default NULL,
151
  modified timestamp NOT NULL,
512 by Brian Aker
Adding back more test cases.
152
  bugstatus int default NULL,
153
  submitter int default NULL
1 by brian
clean slate
154
) ENGINE=MyISAM;
155
156
INSERT INTO t1 VALUES (1,'Link',1,1,1,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa','2001-02-28 08:40:16',20010228084016,0,4);
157
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter), '"') FROM t1;
158
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1;
159
SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified+0,bugstatus,submitter) FROM t1;
160
SELECT bugdesc, REPLACE(bugdesc, 'xxxxxxxxxxxxxxxxxxxx', 'bbbbbbbbbbbbbbbbbbbb') from t1 group by bugdesc;
161
drop table t1;
162
163
#
164
# Test bug in AES_DECRYPT() when called with wrong argument
165
#
166
1063.9.3 by Brian Aker
Partial fix for tests for tmp
167
CREATE TEMPORARY TABLE t1 (id int NOT NULL auto_increment, tmp text NOT NULL, KEY id (id)) ENGINE=MyISAM;
1 by brian
clean slate
168
INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf');
169
DROP TABLE t1;
170
171
CREATE TABLE t1 (
512 by Brian Aker
Adding back more test cases.
172
  wid int NOT NULL auto_increment,
1 by brian
clean slate
173
  data_podp date default NULL,
174
  status_wnio enum('nowy','podp','real','arch') NOT NULL default 'nowy',
175
  PRIMARY KEY(wid)
176
);
177
178
INSERT INTO t1 VALUES (8,NULL,'real');
179
INSERT INTO t1 VALUES (9,NULL,'nowy');
180
SELECT elt(status_wnio,data_podp) FROM t1 GROUP BY wid;
181
DROP TABLE t1;
182
183
#
184
# test for #739
185
1063.9.3 by Brian Aker
Partial fix for tests for tmp
186
CREATE TEMPORARY TABLE t1 (title text) ENGINE=MyISAM;
1 by brian
clean slate
187
INSERT INTO t1 VALUES ('Congress reconvenes in September to debate welfare and adult education');
188
INSERT INTO t1 VALUES ('House passes the CAREERS bill');
189
SELECT CONCAT("</a>",RPAD("",(55 - LENGTH(title)),".")) from t1;
190
DROP TABLE t1;
191
192
#
193
# test for Bug #2290 "output truncated with ELT when using DISTINCT"
194
#
195
196
CREATE TABLE t1 (i int, j int);
197
INSERT INTO t1 VALUES (1,1),(2,2);
198
SELECT DISTINCT i, ELT(j, '345', '34') FROM t1;
199
DROP TABLE t1;
200
201
#
202
# bug #3756: quote and NULL
203
#
204
205
create table t1(a char(4));
206
insert into t1 values ('one'),(NULL),('two'),('four');
207
select a, quote(a), isnull(quote(a)), quote(a) is null, ifnull(quote(a), 'n') from t1;
208
drop table t1;
209
210
#
211
# Bug #5498: TRIM fails with LEADING or TRAILING if remstr = str
212
#
213
214
select trim(trailing 'foo' from 'foo');
215
select trim(leading 'foo' from 'foo');
216
217
#
218
# crashing bug with QUOTE() and LTRIM() or TRIM() fixed
219
# Bug #7495
220
#
221
222
select quote(ltrim(concat('    ', 'a')));
223
select quote(trim(concat('    ', 'a')));
224
225
# Bad results from QUOTE(). Bug #8248
226
CREATE TABLE t1 SELECT 1 UNION SELECT 2 UNION SELECT 3;
227
SELECT QUOTE('A') FROM t1;
228
DROP TABLE t1;
229
230
#
231
# test for SUBSTR
232
#
233
select SUBSTR('abcdefg',3,2);
234
select SUBSTRING('abcdefg',3,2);
235
select SUBSTR('abcdefg',-3,2);
236
select SUBSTR('abcdefg',-1,5);
237
select SUBSTR('abcdefg',0,0);
238
select SUBSTR('abcdefg',-1,-1);
239
select SUBSTR('abcdefg',1,-1);
240
241
select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2),substring_index("1abcd;2abcd;3abcd;4abcd", ';', -2);
242
243
explain extended select concat('*',space(5),'*');
244
explain extended select reverse('abc');
245
explain extended select rpad('a',4,'1');
246
explain extended select lpad('a',4,'1');
247
explain extended select concat_ws(',','',NULL,'a');
248
explain extended select elt(2,1);
249
explain extended select locate("a","b",2);
250
explain extended select char(0);
251
explain extended select conv(130,16,10);
252
explain extended select hex(130);
253
explain extended select binary 'HE';
254
explain extended select collation(conv(130,16,10));
255
explain extended select length('\n\t\r\b\0\_\%\\');
256
explain extended select concat('monty',' was here ','again');
257
explain extended select length('hello');
258
explain extended select char(ascii('h'));
259
explain extended select ord('h');
260
explain extended select quote(1/0);
261
explain extended select crc32("123");
262
explain extended select replace('aaaa','a','b');
263
explain extended select insert('txs',2,1,'hi');
264
explain extended select SUBSTR('abcdefg',3,2);
265
explain extended select substring_index("1abcd;2abcd;3abcd;4abcd", ';', 2);
266
267
#
268
# lpad returns incorrect result (Bug #2182)
269
#
270
271
SELECT lpad(12345, 5, "#");
272
273
#
274
# Problem the the CONV() function (Bug #2972)
275
#
276
 
277
SELECT conv(71, 10, 36), conv('1Z', 36, 10);
278
SELECT conv(71, 10, 37), conv('1Z', 37, 10), conv(0,1,10),conv(0,0,10), conv(0,-1,10);
279
280
#
281
# Bug in SUBSTRING when mixed with CONCAT and ORDER BY (Bug #3089)
282
#
283
512 by Brian Aker
Adding back more test cases.
284
create table t1 (id int, str varchar(10));
1 by brian
clean slate
285
insert into t1 values (1,'aaaaaaaaaa'), (2,'bbbbbbbbbb');
512 by Brian Aker
Adding back more test cases.
286
create table t2 (id int, str varchar(10));
1 by brian
clean slate
287
insert into t2 values (1,'cccccccccc'), (2,'dddddddddd');
288
select substring(concat(t1.str, t2.str), 1, 15) "name" from t1, t2 
289
where t2.id=t1.id order by name;
290
drop table t1, t2;
291
292
#
293
# Test case for conversion of long string value to integer (Bug #3472)
294
#
295
512 by Brian Aker
Adding back more test cases.
296
create table t1 (c1 INT, c2 INT);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
297
--error ER_WARN_DATA_OUT_OF_RANGE
1 by brian
clean slate
298
insert into t1 values ('21474836461','21474836461');
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
299
--error ER_WARN_DATA_OUT_OF_RANGE
1 by brian
clean slate
300
insert into t1 values ('-21474836461','-21474836461');
301
select * from t1;
302
drop table t1;
303
304
#
305
# Bug #4878: LEFT() in integer/float context
306
#
307
308
select left(1234, 3) + 0;
309
310
#
311
# Bug #7101: bug with LEFT() when used as a field in GROUP BY aggregation
312
#
313
create table t1 (a int not null primary key, b varchar(40), c datetime);
314
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'); 
315
select count(*) as total, left(c,10) as reg from t1 group by reg order by reg desc limit 0,12;
316
drop table t1;
317
318
#
319
# Bug#7455 unexpected result: TRIM(<NULL> FROM <whatever>) gives NOT NULL
320
# According to ANSI if one of the TRIM arguments is NULL, then the result
321
# must be NULL too.
322
#
323
select trim(null from 'kate') as "must_be_null";
324
select trim('xyz' from null) as "must_be_null";
325
select trim(leading NULL from 'kate') as "must_be_null";
326
select trim(trailing NULL from 'xyz') as "must_be_null";
327
328
#
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
329
# Bug #7751 - conversion for a bigint constant 
1 by brian
clean slate
330
#
331
1063.9.3 by Brian Aker
Partial fix for tests for tmp
332
CREATE TEMPORARY TABLE t1 (
512 by Brian Aker
Adding back more test cases.
333
  id int NOT NULL auto_increment,
334
  a bigint default NULL,
1 by brian
clean slate
335
  PRIMARY KEY  (id)
336
) ENGINE=MyISAM;
337
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
338
--error ER_WARN_DATA_OUT_OF_RANGE
512 by Brian Aker
Adding back more test cases.
339
INSERT INTO t1 VALUES ('0','16307858876001849059');
1 by brian
clean slate
340
341
SELECT CONV('e251273eb74a8ee3', 16, 10);
342
343
EXPLAIN 
344
SELECT id
345
  FROM t1
346
  WHERE a = 16307858876001849059;
347
348
EXPLAIN 
349
  SELECT id
350
  FROM t1
351
  WHERE a = CONV('e251273eb74a8ee3', 16, 10);
352
353
DROP TABLE t1;
354
355
#
356
# Bug #6317: string function CHAR, parameter is NULL, wrong result
357
#
358
SELECT CHAR(NULL,121,83,81,'76') as my_column;
359
SELECT CHAR_LENGTH(CHAR(NULL,121,83,81,'76')) as my_column;
360
#
361
# Test case for bug #8669: null aes_decrypt result in order by query
362
#
363
364
CREATE TABLE t1 (id int PRIMARY KEY, str char(255) NOT NULL);
365
CREATE TABLE t2 (id int NOT NULL UNIQUE);
366
INSERT INTO t2 VALUES (1),(2);
367
INSERT INTO t1 VALUES (2, 'not valid');
368
369
DROP TABLE t1, t2;
370
371
#
372
# Bug #10944: Mishandling of NULL arguments in FIELD()
373
#
374
select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
375
select field(NULL,1,2,NULL), field(NULL,1,2,0);
376
377
#
378
# Bug #10124: access by integer index with a string key that is not a number  
379
#
380
381
CREATE TABLE t1 (str varchar(20) PRIMARY KEY);
382
CREATE TABLE t2 (num int primary key);
383
INSERT INTO t1 VALUES ('notnumber');
384
INSERT INTO t2 VALUES (0), (1); 
385
386
SELECT * FROM t1, t2 WHERE num=str;
387
SELECT * FROM t1, t2 WHERE num=substring(str from 1 for 6);
388
389
DROP TABLE t1,t2;
390
391
#
392
# Bug #11469: NOT NULL optimization wrongly used for arguments of CONCAT_WS  
393
#
394
395
CREATE TABLE t1(
512 by Brian Aker
Adding back more test cases.
396
  id int NOT NULL auto_increment,
397
  pc int NOT NULL default '0',
1 by brian
clean slate
398
  title varchar(20) default NULL,
399
  PRIMARY KEY (id)
400
);
401
402
INSERT INTO t1 VALUES
403
  (1, 0, 'Main'),
404
  (2, 1, 'Toys'),
405
  (3, 1, 'Games');
406
407
SELECT t1.id, CONCAT_WS('->', t3.title, t2.title, t1.title) as col1
408
  FROM t1 LEFT JOIN t1 AS t2 ON t1.pc=t2.id
409
          LEFT JOIN t1 AS t3 ON t2.pc=t3.id;
410
SELECT t1.id, CONCAT_WS('->', t3.title, t2.title, t1.title) as col1
411
  FROM t1 LEFT JOIN t1 AS t2 ON t1.pc=t2.id
412
          LEFT JOIN t1 AS t3 ON t2.pc=t3.id
413
    WHERE CONCAT_WS('->', t3.title, t2.title, t1.title) LIKE '%Toys%';
414
415
DROP TABLE t1;
416
417
418
CREATE TABLE t1(
512 by Brian Aker
Adding back more test cases.
419
  trackid     int NOT NULL auto_increment,
1 by brian
clean slate
420
  trackname   varchar(100) NOT NULL default '',
421
  PRIMARY KEY (trackid)
422
);
423
424
CREATE TABLE t2(
512 by Brian Aker
Adding back more test cases.
425
  artistid    int NOT NULL auto_increment,
1 by brian
clean slate
426
  artistname  varchar(100) NOT NULL default '',
427
  PRIMARY KEY (artistid)
428
);
429
430
CREATE TABLE t3(
512 by Brian Aker
Adding back more test cases.
431
  trackid     int NOT NULL,
432
  artistid    int NOT NULL,
1 by brian
clean slate
433
  PRIMARY KEY (trackid,artistid)
434
);
435
436
INSERT INTO t1 VALUES (1, 'April In Paris'), (2, 'Autumn In New York');
437
INSERT INTO t2 VALUES (1, 'Vernon Duke');
438
INSERT INTO t3 VALUES (1,1);
439
440
SELECT CONCAT_WS(' ', trackname, artistname) trackname, artistname
441
  FROM t1 LEFT JOIN t3 ON t1.trackid=t3.trackid
442
          LEFT JOIN t2 ON t2.artistid=t3.artistid
443
    WHERE CONCAT_WS(' ', trackname, artistname) LIKE '%In%';
444
445
DROP TABLE t1,t2,t3;
446
447
#
448
# Correct length reporting from substring() (BUG#10269)
449
#
450
create table t1 (b varchar(5));
451
insert t1 values ('ab'), ('abc'), ('abcd'), ('abcde');
452
select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1;
453
select * from (select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1) t;
454
drop table t1;
455
456
#
457
# Bug #9854  hex() and out of range handling
458
#
459
select hex(29223372036854775809), hex(-29223372036854775809);
460
461
#
462
# Bug #11311: Incorrect length returned from LPAD() and RPAD()
463
#
464
create table t1 (i int);
465
insert into t1 values (1000000000),(1);
466
--enable_metadata
467
select lpad(i, 7, ' ') as t from t1;
468
select rpad(i, 7, ' ') as t from t1;
469
--disable_metadata
470
drop table t1;
471
472
#
473
# Bug #10418: LOAD_FILE does not behave like in manual if file does not exist
474
#
475
476
select load_file("lkjlkj");
477
select ifnull(load_file("lkjlkj"),"it's null");
478
479
#
480
# Bug#18243: REVERSE changes its argument
481
#
482
483
CREATE TABLE t1 (a varchar(10));
484
INSERT INTO t1 VALUES ('abc'), ('xyz');
485
486
SELECT a, CONCAT(a,' ',a) AS c FROM t1
487
  HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
488
489
SELECT a, CONCAT(a,' ',a) AS c FROM t1
490
  HAVING LEFT(CONCAT(a,' ',a),
491
              LENGTH(CONCAT(a,' ',a))-
492
                     INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
493
494
DROP TABLE t1;
495
496
#
497
# Bug#17526: WRONG PRINT for TRIM FUNCTION with two arguments
498
#
499
500
CREATE TABLE t1 (s varchar(10));
501
INSERT INTO t1 VALUES ('yadda'), ('yaddy');
502
503
EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(s) > 'ab';
504
EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM('y' FROM s) > 'ab';
505
EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(LEADING 'y' FROM s) > 'ab';
506
EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(TRAILING 'y' FROM s) > 'ab';
507
EXPLAIN EXTENDED SELECT s FROM t1 WHERE TRIM(BOTH 'y' FROM s) > 'ab';
508
509
DROP TABLE t1;
510
511
#
512
# Bug #31758 inet_ntoa, oct, crashes server with null + filesort 
513
#
1063.9.3 by Brian Aker
Partial fix for tests for tmp
514
create TEMPORARY table t1 (a bigint not null)engine=myisam;
1 by brian
clean slate
515
insert into t1 set a = 1024*1024*1024*4;
516
drop table t1;
1063.9.3 by Brian Aker
Partial fix for tests for tmp
517
create TEMPORARY table t1 (a char(36) not null)engine=myisam;
1 by brian
clean slate
518
insert ignore into t1 set a = ' ';
519
insert ignore into t1 set a = ' ';
520
select * from t1 order by (oct(a));
521
drop table t1;
522
523
--echo End of 4.1 tests
524
525
#
526
# Bug #13361: SELECT FORMAT(<decimal field with null>, 2) crashes
527
#
528
create table t1 (d decimal default null);
529
insert into t1 values (null);
530
select format(d, 2) from t1;
531
drop table t1;
532
533
#
534
# Bug #14676: substring_index() returns incorrect results
535
#
536
create table t1 (c varchar(40));
537
insert into t1 values ('y,abc'),('y,abc');
538
select c, substring_index(lcase(c), @q:=',', -1) as res from t1;
539
drop table t1;
540
541
#
542
# Bug #17043: Casting trimmed string to decimal loses precision
543
#
544
select cast(rtrim('  20.06 ') as decimal(19,2));
545
select cast(ltrim('  20.06 ') as decimal(19,2));
546
select cast(rtrim(ltrim('  20.06 ')) as decimal(19,2));
547
548
#
549
# Bug #13975: "same string" + 0 has 2 different results
550
#
551
select conv("18383815659218730760",10,10) + 0;
552
select "18383815659218730760" + 0;
553
554
#
555
# Bug #21698: substitution of a string field for a constant under a function 
556
#
557
558
CREATE TABLE t1 (code varchar(10));
559
INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13');
560
561
SELECT ASCII(code), code FROM t1 WHERE code='A12';
562
SELECT ASCII(code), code FROM t1 WHERE code='A12' AND ASCII(code)=65;
563
564
INSERT INTO t1 VALUES ('a12 '), ('A12  ');
565
566
SELECT LENGTH(code), code FROM t1 WHERE code='A12';
567
SELECT LENGTH(code), code FROM t1 WHERE code='A12' AND LENGTH(code)=5;
568
569
ALTER TABLE t1 ADD INDEX (code);
570
CREATE TABLE t2 (id varchar(10) PRIMARY KEY);
571
INSERT INTO t2 VALUES ('a11'), ('a12'), ('a13'), ('a14');
572
573
SELECT * FROM t1 INNER JOIN t2 ON t1.code=t2.id 
574
  WHERE t2.id='a12' AND (LENGTH(code)=5 OR code < 'a00');
575
EXPLAIN EXTENDED 
576
SELECT * FROM t1 INNER JOIN t2 ON code=id 
577
  WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00');
578
579
DROP TABLE t1,t2;
580
581
#
582
# Bug #20752: BENCHMARK with many iterations returns too quickly
583
#
584
585
# not a string, but belongs with the above Bug#22684
586
select benchmark(-1, 1);
587
588
#
589
# Please note:
590
# 1) The collation of the password is irrelevant, the encryption uses
591
# the binary representation of the string without charset/collation.
592
# 2) These tests can not print the encoded text directly, because it's binary,
593
# and doing this would cause problems with source control.
594
# Instead, an md5() checksum is used, to verify the result indirectly.
595
# 3) Each md5() result must be identical.
596
# 4) The md5() result must never change, and must be stable across releases.
597
#
598
599
set @dec=5;
600
select format(pi(), (1+1));
512 by Brian Aker
Adding back more test cases.
601
select format(pi(), (select 3));
1 by brian
clean slate
602
select format(pi(), @dec);
603
604
set @bench_count=10;
605
select benchmark(10, pi());
606
select benchmark(5+5, pi());
512 by Brian Aker
Adding back more test cases.
607
select benchmark((select 10), pi());
1 by brian
clean slate
608
select benchmark(@bench_count, pi());
609
610
611
#
612
# Bug #10963
613
# 4294967296 18446744073709551616
614
615
select locate('he','hello',-2);
616
select locate('lo','hello',-4294967295);
617
select locate('lo','hello',4294967295);
618
select locate('lo','hello',-4294967296);
619
select locate('lo','hello',4294967296);
620
select locate('lo','hello',-4294967297);
621
select locate('lo','hello',4294967297);
622
select locate('lo','hello',-18446744073709551615);
623
select locate('lo','hello',18446744073709551615);
624
select locate('lo','hello',-18446744073709551616);
625
select locate('lo','hello',18446744073709551616);
626
select locate('lo','hello',-18446744073709551617);
627
select locate('lo','hello',18446744073709551617);
628
629
select left('hello', 10);
630
select left('hello', 0);
631
select left('hello', -1);
632
select left('hello', -4294967295);
633
select left('hello', 4294967295);
634
select left('hello', -4294967296);
635
select left('hello', 4294967296);
636
select left('hello', -4294967297);
637
select left('hello', 4294967297);
638
select left('hello', -18446744073709551615);
639
select left('hello', 18446744073709551615);
640
select left('hello', -18446744073709551616);
641
select left('hello', 18446744073709551616);
642
select left('hello', -18446744073709551617);
643
select left('hello', 18446744073709551617);
644
645
select right('hello', 10);
646
select right('hello', 0);
647
select right('hello', -1);
648
select right('hello', -4294967295);
649
select right('hello', 4294967295);
650
select right('hello', -4294967296);
651
select right('hello', 4294967296);
652
select right('hello', -4294967297);
653
select right('hello', 4294967297);
654
select right('hello', -18446744073709551615);
655
select right('hello', 18446744073709551615);
656
select right('hello', -18446744073709551616);
657
select right('hello', 18446744073709551616);
658
select right('hello', -18446744073709551617);
659
select right('hello', 18446744073709551617);
660
661
select substring('hello', 2, -1);
662
663
select substring('hello', -1, 1);
664
select substring('hello', -2, 1);
665
select substring('hello', -4294967295, 1);
666
select substring('hello', 4294967295, 1);
667
select substring('hello', -4294967296, 1);
668
select substring('hello', 4294967296, 1);
669
select substring('hello', -4294967297, 1);
670
select substring('hello', 4294967297, 1);
671
select substring('hello', -18446744073709551615, 1);
672
select substring('hello', 18446744073709551615, 1);
673
select substring('hello', -18446744073709551616, 1);
674
select substring('hello', 18446744073709551616, 1);
675
select substring('hello', -18446744073709551617, 1);
676
select substring('hello', 18446744073709551617, 1);
677
select substring('hello', 1, -1);
678
select substring('hello', 1, -4294967295);
679
select substring('hello', 1, 4294967295);
680
select substring('hello', 1, -4294967296);
681
select substring('hello', 1, 4294967296);
682
select substring('hello', 1, -4294967297);
683
select substring('hello', 1, 4294967297);
684
select substring('hello', 1, -18446744073709551615);
685
select substring('hello', 1, 18446744073709551615);
686
select substring('hello', 1, -18446744073709551616);
687
select substring('hello', 1, 18446744073709551616);
688
select substring('hello', 1, -18446744073709551617);
689
select substring('hello', 1, 18446744073709551617);
690
select substring('hello', -1, -1);
691
select substring('hello', -4294967295, -4294967295);
692
select substring('hello', 4294967295, 4294967295);
693
select substring('hello', -4294967296, -4294967296);
694
select substring('hello', 4294967296, 4294967296);
695
select substring('hello', -4294967297, -4294967297);
696
select substring('hello', 4294967297, 4294967297);
697
select substring('hello', -18446744073709551615, -18446744073709551615);
698
select substring('hello', 18446744073709551615, 18446744073709551615);
699
select substring('hello', -18446744073709551616, -18446744073709551616);
700
select substring('hello', 18446744073709551616, 18446744073709551616);
701
select substring('hello', -18446744073709551617, -18446744073709551617);
702
select substring('hello', 18446744073709551617, 18446744073709551617);
703
704
select insert('hello', -1, 1, 'hi');
705
select insert('hello', -4294967295, 1, 'hi');
706
select insert('hello', 4294967295, 1, 'hi');
707
select insert('hello', -4294967296, 1, 'hi');
708
select insert('hello', 4294967296, 1, 'hi');
709
select insert('hello', -4294967297, 1, 'hi');
710
select insert('hello', 4294967297, 1, 'hi');
711
select insert('hello', -18446744073709551615, 1, 'hi');
712
select insert('hello', 18446744073709551615, 1, 'hi');
713
select insert('hello', -18446744073709551616, 1, 'hi');
714
select insert('hello', 18446744073709551616, 1, 'hi');
715
select insert('hello', -18446744073709551617, 1, 'hi');
716
select insert('hello', 18446744073709551617, 1, 'hi');
717
select insert('hello', 1, -1, 'hi');
718
select insert('hello', 1, -4294967295, 'hi');
719
select insert('hello', 1, 4294967295, 'hi');
720
select insert('hello', 1, -4294967296, 'hi');
721
select insert('hello', 1, 4294967296, 'hi');
722
select insert('hello', 1, -4294967297, 'hi');
723
select insert('hello', 1, 4294967297, 'hi');
724
select insert('hello', 1, -18446744073709551615, 'hi');
725
select insert('hello', 1, 18446744073709551615, 'hi');
726
select insert('hello', 1, -18446744073709551616, 'hi');
727
select insert('hello', 1, 18446744073709551616, 'hi');
728
select insert('hello', 1, -18446744073709551617, 'hi');
729
select insert('hello', 1, 18446744073709551617, 'hi');
730
select insert('hello', -1, -1, 'hi');
731
select insert('hello', -4294967295, -4294967295, 'hi');
732
select insert('hello', 4294967295, 4294967295, 'hi');
733
select insert('hello', -4294967296, -4294967296, 'hi');
734
select insert('hello', 4294967296, 4294967296, 'hi');
735
select insert('hello', -4294967297, -4294967297, 'hi');
736
select insert('hello', 4294967297, 4294967297, 'hi');
737
select insert('hello', -18446744073709551615, -18446744073709551615, 'hi');
738
select insert('hello', 18446744073709551615, 18446744073709551615, 'hi');
739
select insert('hello', -18446744073709551616, -18446744073709551616, 'hi');
740
select insert('hello', 18446744073709551616, 18446744073709551616, 'hi');
741
select insert('hello', -18446744073709551617, -18446744073709551617, 'hi');
742
select insert('hello', 18446744073709551617, 18446744073709551617, 'hi');
743
744
select repeat('hello', -1);
745
select repeat('hello', -4294967295);
746
select repeat('hello', 4294967295);
747
select repeat('hello', -4294967296);
748
select repeat('hello', 4294967296);
749
select repeat('hello', -4294967297);
750
select repeat('hello', 4294967297);
751
select repeat('hello', -18446744073709551615);
752
select repeat('hello', 18446744073709551615);
753
select repeat('hello', -18446744073709551616);
754
select repeat('hello', 18446744073709551616);
755
select repeat('hello', -18446744073709551617);
756
select repeat('hello', 18446744073709551617);
757
758
select space(-1);
759
select space(-4294967295);
760
select space(4294967295);
761
select space(-4294967296);
762
select space(4294967296);
763
select space(-4294967297);
764
select space(4294967297);
765
select space(-18446744073709551615);
766
select space(18446744073709551615);
767
select space(-18446744073709551616);
768
select space(18446744073709551616);
769
select space(-18446744073709551617);
770
select space(18446744073709551617);
771
772
select rpad('hello', -1, '1');
773
select rpad('hello', -4294967295, '1');
774
select rpad('hello', 4294967295, '1');
775
select rpad('hello', -4294967296, '1');
776
select rpad('hello', 4294967296, '1');
777
select rpad('hello', -4294967297, '1');
778
select rpad('hello', 4294967297, '1');
779
select rpad('hello', -18446744073709551615, '1');
780
select rpad('hello', 18446744073709551615, '1');
781
select rpad('hello', -18446744073709551616, '1');
782
select rpad('hello', 18446744073709551616, '1');
783
select rpad('hello', -18446744073709551617, '1');
784
select rpad('hello', 18446744073709551617, '1');
785
786
select lpad('hello', -1, '1');
787
select lpad('hello', -4294967295, '1');
788
select lpad('hello', 4294967295, '1');
789
select lpad('hello', -4294967296, '1');
790
select lpad('hello', 4294967296, '1');
791
select lpad('hello', -4294967297, '1');
792
select lpad('hello', 4294967297, '1');
793
select lpad('hello', -18446744073709551615, '1');
794
select lpad('hello', 18446744073709551615, '1');
795
select lpad('hello', -18446744073709551616, '1');
796
select lpad('hello', 18446744073709551616, '1');
797
select lpad('hello', -18446744073709551617, '1');
798
select lpad('hello', 18446744073709551617, '1');
799
800
801
#
802
# BUG#17047: CHAR() and IN() can return NULL without signaling NULL
803
# result
804
#
512 by Brian Aker
Adding back more test cases.
805
SELECT CHAR(0xff,0x8f);
806
SELECT CHAR(0xff,0x8f) IS NULL;
1 by brian
clean slate
807
808
#
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
809
# Bug #24947: problem with some string function with int parameters
1 by brian
clean slate
810
#
512 by Brian Aker
Adding back more test cases.
811
#
812
#select substring('abc', cast(2 as int));
813
#select repeat('a', cast(2 as int));
814
#select rpad('abc', cast(5 as integer), 'x');
815
#select lpad('abc', cast(5 as integer), 'x');
1 by brian
clean slate
816
817
#
818
# Bug#15757: Wrong SUBSTRING() result when a tmp table was employed.
819
#
820
create table t1(f1 longtext);
821
insert into t1 values ("123"),("456");
822
select substring(f1,1,1) from t1 group by 1;
823
create table t2(f1 varchar(3));
824
insert into t1 values ("123"),("456");
825
select substring(f1,4,1), substring(f1,-4,1) from t2;
826
drop table t1,t2;
827
828
#
829
# Bug #25197 :repeat function returns null when using table field directly as count
830
#
831
832
--disable_warnings
833
DROP TABLE IF EXISTS t1;
834
--enable_warnings
835
836
CREATE TABLE `t1` (
837
  `id` varchar(20) NOT NULL,
512 by Brian Aker
Adding back more test cases.
838
  `tire` int NOT NULL,
1 by brian
clean slate
839
  PRIMARY KEY (`id`)
840
);
841
842
INSERT INTO `t1` (`id`, `tire`) VALUES ('A', 0), ('B', 1),('C', 2);
843
844
SELECT REPEAT( '#', tire ) AS A,
845
       REPEAT( '#', tire % 999 ) AS B, tire FROM `t1`;
846
512 by Brian Aker
Adding back more test cases.
847
SELECT REPEAT('0', 0);
1 by brian
clean slate
848
SELECT REPEAT('0', -2);
849
SELECT REPEAT('0', 2);
850
851
DROP TABLE t1;
852
853
#
854
# Bug #26537: UNHEX() IS NULL comparison fails
855
#
856
SELECT UNHEX('G');
857
SELECT UNHEX('G') IS NULL;
858
859
#
860
# Bug #26281: INSERT() function mishandles NUL on boundary condition
861
#
862
SELECT INSERT('abc', 3, 3, '1234');
863
SELECT INSERT('abc', 4, 3, '1234');
864
SELECT INSERT('abc', 5, 3, '1234');
865
SELECT INSERT('abc', 6, 3, '1234');
866
867
#
868
# Bug #27932: LOCATE with argument evaluated to NULL
869
#
870
871
SELECT LOCATE('foo', NULL);
872
SELECT LOCATE(NULL, 'o');
873
SELECT LOCATE(NULL, NULL);
874
SELECT LOCATE('foo', NULL) IS NULL;
875
SELECT LOCATE(NULL, 'o') IS NULL;
876
SELECT LOCATE(NULL, NULL) IS NULL;
877
SELECT ISNULL(LOCATE('foo', NULL));
878
SELECT ISNULL(LOCATE(NULL, 'o'));
879
SELECT ISNULL(LOCATE(NULL, NULL));
880
SELECT LOCATE('foo', NULL) <=> NULL;
881
SELECT LOCATE(NULL, 'o') <=> NULL;
882
SELECT LOCATE(NULL, NULL) <=> NULL;
883
884
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a varchar(10), p varchar(10));
885
886
INSERT INTO t1 VALUES (1, 'foo', 'o');
887
INSERT INTO t1 VALUES (2, 'foo', NULL);
888
INSERT INTO t1 VALUES (3, NULL, 'o');
889
INSERT INTO t1 VALUES (4, NULL, NULL);
890
891
SELECT id, LOCATE(a,p) FROM t1;
892
SELECT id, LOCATE(a,p) IS NULL FROM t1;
893
SELECT id, ISNULL(LOCATE(a,p)) FROM t1;
894
SELECT id, LOCATE(a,p) <=> NULL FROM t1;
895
SELECT id FROM t1 WHERE LOCATE(a,p) IS NULL;
896
SELECT id FROM t1 WHERE LOCATE(a,p) <=> NULL; 
897
898
DROP TABLE t1;
899
900
#
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
901
# Bug #27130: SUBSTR with 0 as the last argument
1 by brian
clean slate
902
#
903
904
SELECT SUBSTR('foo',1,0);
512 by Brian Aker
Adding back more test cases.
905
SELECT SUBSTR('foo',1,0);
906
SELECT SUBSTR('foo',1,0);
1 by brian
clean slate
907
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
908
CREATE TABLE t1 (a varchar(10), len int);
1 by brian
clean slate
909
INSERT INTO t1 VALUES ('bar', 2), ('foo', 0);
910
911
SELECT SUBSTR(a,1,len) FROM t1;
912
913
DROP TABLE t1; 
914
915
#
916
# Bug #28850: Potential bugs related to the return type of the CHAR function
917
#
918
919
CREATE TABLE t1 AS SELECT CHAR(0x414243) as c1;
920
SELECT HEX(c1) from t1;
921
DROP TABLE t1;
922
923
--echo End of 5.0 tests