~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/func_like.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
Import upstream version 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 #4200: Prepared statement parameter as argument to ESCAPE
 
39
#
 
40
prepare stmt1 from 'select * from t1 where a like \'a\\%\' escape ?';
 
41
set @esc='#';
 
42
execute stmt1 using @esc;  
 
43
deallocate prepare stmt1;
 
44
 
 
45
drop table t1;
 
46
 
 
47
#
 
48
# Bug #2885: like and datetime
 
49
#
 
50
 
 
51
create table t1 (a datetime);
 
52
insert into t1 values ('2004-03-11 12:00:21');
 
53
select * from t1 where a like '2004-03-11 12:00:21';
 
54
drop table t1;
 
55
 
 
56
#
 
57
# Test like with non-default character set
 
58
#
 
59
 
 
60
SET NAMES koi8r;
 
61
 
 
62
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET koi8r);
 
63
 
 
64
INSERT INTO t1 VALUES ('����'),('����'),('����'),('����'),('����'),('����');
 
65
INSERT INTO t1 VALUES ('����������'),('����������'),('����������'),('����������');
 
66
INSERT INTO t1 VALUES ('����������'),('����������'),('����������'),('����������');
 
67
INSERT INTO t1 VALUES ('����������'),('����������'),('����������'),('����������');
 
68
 
 
69
SELECT * FROM t1 WHERE a LIKE '%����%';
 
70
SELECT * FROM t1 WHERE a LIKE '%���%';
 
71
SELECT * FROM t1 WHERE a LIKE '����%';
 
72
 
 
73
DROP TABLE t1;
 
74
 
 
75
# Bug #2547 Strange "like" behaviour in tables with default charset=cp1250
 
76
# Test like with non-default character set using TurboBM
 
77
#
 
78
SET NAMES cp1250;
 
79
CREATE TABLE t1 (a varchar(250) NOT NULL) DEFAULT CHARACTER SET=cp1250;
 
80
INSERT INTO t1 VALUES
 
81
('Techni Tapes Sp. z o.o.'),
 
82
('Pojazdy Szynowe PESA Bydgoszcz SA Holding'),
 
83
('AKAPESTER 1 P.P.H.U.'),
 
84
('Pojazdy Szynowe PESA Bydgoszcz S A Holding'),
 
85
('PPUH PESKA-I Maria Struniarska');
 
86
 
 
87
select * from t1 where a like '%PESA%';
 
88
select * from t1 where a like '%PESA %';
 
89
select * from t1 where a like '%PES%';
 
90
select * from t1 where a like '%PESKA%';
 
91
select * from t1 where a like '%ESKA%';
 
92
DROP TABLE t1;
 
93
 
 
94
#
 
95
# LIKE crashed for binary collations in some cases
 
96
#
 
97
select _cp866'aaaaaaaaa' like _cp866'%aaaa%' collate cp866_bin;
 
98
 
 
99
#
 
100
# Check 8bit escape character
 
101
#
 
102
set names koi8r;
 
103
select 'andre%' like 'andre�%' escape '�';
 
104
 
 
105
# Check 8bit escape character with charset conversion:
 
106
# For "a LIKE b ESCAPE c" expressions,
 
107
# escape character is converted into the operation character set,
 
108
# which is result of aggregation  of character sets of "a" and "b".
 
109
# "c" itself doesn't take part in aggregation, because its collation
 
110
# doesn't matter, escape character is always compared binary.
 
111
# In the example below, escape character is converted from koi8r into cp1251:
 
112
#
 
113
select _cp1251'andre%' like convert('andre�%' using cp1251)  escape '�';
 
114
 
 
115
#
 
116
# End of 4.1 tests