1
by brian
clean slate |
1 |
#
|
2 |
# Test of like
|
|
3 |
#
|
|
4 |
||
5 |
--disable_warnings |
|
6 |
drop table if exists t1; |
|
7 |
--enable_warnings |
|
8 |
||
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"; |
|
18 |
||
19 |
#
|
|
20 |
# The following will test the Turbo Boyer-Moore code
|
|
21 |
#
|
|
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%"; |
|
25 |
||
26 |
drop table t1; |
|
27 |
||
28 |
create table t1 (a varchar(10), key(a)); |
|
29 |
||
30 |
#
|
|
31 |
# Bug #2231
|
|
32 |
#
|
|
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'; |
|
36 |
||
37 |
#
|
|
38 |
# Bug #2885: like and datetime
|
|
39 |
#
|
|
40 |
||
41 |
drop table t1; |
|
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'; |
|
45 |
drop table t1; |
|
46 |
||
47 |
#
|
|
48 |
# Test like with non-default character set
|
|
49 |
#
|
|
50 |
||
51 |
SET NAMES koi8r; |
|
52 |
||
53 |
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET koi8r); |
|
54 |
||
55 |
INSERT INTO t1 VALUES ('ÆÙ×Á'),('æÙ×Á'),('Æù×Á'),('ÆÙ÷Á'),('ÆÙ×á'),('æù÷á'); |
|
56 |
INSERT INTO t1 VALUES ('ÆÙ×ÁÐÒÏÌÄÖ'),('æÙ×ÁÐÒÏÌÄÖ'),('Æù×ÁÐÒÏÌÄÖ'),('ÆÙ÷ÁÐÒÏÌÄÖ'); |
|
57 |
INSERT INTO t1 VALUES ('ÆÙ×áÐÒÏÌÄÖ'),('ÆÙ×ÁðÒÏÌÄÖ'),('ÆÙ×ÁÐòÏÌÄÖ'),('ÆÙ×ÁÐÒïÌÄÖ'); |
|
58 |
INSERT INTO t1 VALUES ('ÆÙ×ÁÐÒÏìÄÖ'),('ÆÙ×ÁÐÒÏÌäÖ'),('ÆÙ×ÁÐÒÏÌÄö'),('æù÷áðòïìäö'); |
|
59 |
||
60 |
SELECT * FROM t1 WHERE a LIKE '%Æù×Á%'; |
|
61 |
SELECT * FROM t1 WHERE a LIKE '%Æù×%'; |
|
62 |
SELECT * FROM t1 WHERE a LIKE 'Æù×Á%'; |
|
63 |
||
64 |
DROP TABLE t1; |
|
65 |
||
66 |
# Bug #2547 Strange "like" behaviour in tables with default charset=cp1250
|
|
67 |
# Test like with non-default character set using TurboBM
|
|
68 |
#
|
|
69 |
SET NAMES cp1250; |
|
70 |
CREATE TABLE t1 (a varchar(250) NOT NULL) DEFAULT CHARACTER SET=cp1250; |
|
71 |
INSERT INTO t1 VALUES |
|
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'); |
|
77 |
||
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%'; |
|
83 |
DROP TABLE t1; |
|
84 |
||
85 |
#
|
|
86 |
# LIKE crashed for binary collations in some cases
|
|
87 |
#
|
|
88 |
select _cp866'aaaaaaaaa' like _cp866'%aaaa%' collate cp866_bin; |
|
89 |
||
90 |
#
|
|
91 |
# Check 8bit escape character
|
|
92 |
#
|
|
93 |
set names koi8r; |
|
94 |
select 'andre%' like 'andreÊ%' escape 'Ê'; |
|
95 |
||
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:
|
|
103 |
#
|
|
104 |
select _cp1251'andre%' like convert('andreÊ%' using cp1251) escape 'Ê'; |
|
105 |
||
106 |
#
|
|
107 |
# End of 4.1 tests
|