6
drop table if exists t1;
9
create table t1 (a varchar(10), key(a));
10
insert into t1 values ("a"),("abc"),("abcd"),("hello"),("test");
11
explain extended select * from t1 where a like 'abc%';
12
explain extended select * from t1 where a like concat('abc','%');
13
select * from t1 where a like "abc%";
14
select * from t1 where a like concat("abc","%");
15
select * from t1 where a like "ABC%";
16
select * from t1 where a like "test%";
17
select * from t1 where a like "te_t";
20
# The following will test the Turbo Boyer-Moore code
22
select * from t1 where a like "%a%";
23
select * from t1 where a like "%abcd%";
24
select * from t1 where a like "%abc\d%";
28
create table t1 (a varchar(10), key(a));
33
insert into t1 values ('a'), ('a\\b');
34
select * from t1 where a like 'a\\%' escape '#';
35
select * from t1 where a like 'a\\%' escape '#' and a like 'a\\\\b';
38
# Bug #2885: like and datetime
42
create table t1 (a datetime);
43
insert into t1 values ('2004-03-11 12:00:21');
44
select * from t1 where a like '2004-03-11 12:00:21';
48
# Test like with non-default character set
53
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET koi8r);
55
INSERT INTO t1 VALUES ('����'),('����'),('����'),('����'),('����'),('����');
56
INSERT INTO t1 VALUES ('����������'),('����������'),('����������'),('����������');
57
INSERT INTO t1 VALUES ('����������'),('����������'),('����������'),('����������');
58
INSERT INTO t1 VALUES ('����������'),('����������'),('����������'),('����������');
60
SELECT * FROM t1 WHERE a LIKE '%����%';
61
SELECT * FROM t1 WHERE a LIKE '%���%';
62
SELECT * FROM t1 WHERE a LIKE '����%';
66
# Bug #2547 Strange "like" behaviour in tables with default charset=cp1250
67
# Test like with non-default character set using TurboBM
70
CREATE TABLE t1 (a varchar(250) NOT NULL) DEFAULT CHARACTER SET=cp1250;
72
('Techni Tapes Sp. z o.o.'),
73
('Pojazdy Szynowe PESA Bydgoszcz SA Holding'),
74
('AKAPESTER 1 P.P.H.U.'),
75
('Pojazdy Szynowe PESA Bydgoszcz S A Holding'),
76
('PPUH PESKA-I Maria Struniarska');
78
select * from t1 where a like '%PESA%';
79
select * from t1 where a like '%PESA %';
80
select * from t1 where a like '%PES%';
81
select * from t1 where a like '%PESKA%';
82
select * from t1 where a like '%ESKA%';
86
# LIKE crashed for binary collations in some cases
88
select _cp866'aaaaaaaaa' like _cp866'%aaaa%' collate cp866_bin;
91
# Check 8bit escape character
94
select 'andre%' like 'andre�%' escape '�';
96
# Check 8bit escape character with charset conversion:
97
# For "a LIKE b ESCAPE c" expressions,
98
# escape character is converted into the operation character set,
99
# which is result of aggregation of character sets of "a" and "b".
100
# "c" itself doesn't take part in aggregation, because its collation
101
# doesn't matter, escape character is always compared binary.
102
# In the example below, escape character is converted from koi8r into cp1251:
104
select _cp1251'andre%' like convert('andre�%' using cp1251) escape '�';