mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / type_varchar.test
blob9098881e379c1decdc9374122393dea6ae883ce6
1 --disable_warnings
2 drop table if exists t1, t2;
3 --enable_warnings
5 create table t1 (v varchar(30), c char(3), e enum('abc','def','ghi'), t text);
6 let $MYSQLD_DATADIR= `select @@datadir`;
7 copy_file $MYSQL_TEST_DIR/std_data/vchar.frm $MYSQLD_DATADIR/test/vchar.frm;
8 truncate table vchar;
9 show create table t1;
10 show create table vchar;
11 insert into t1 values ('abc', 'de', 'ghi', 'jkl');
12 insert into t1 values ('abc ', 'de ', 'ghi', 'jkl ');
13 insert into t1 values ('abc    ', 'd  ', 'ghi', 'jkl    ');
14 insert into vchar values ('abc', 'de', 'ghi', 'jkl');
15 insert into vchar values ('abc ', 'de ', 'ghi', 'jkl ');
16 insert into vchar values ('abc    ', 'd  ', 'ghi', 'jkl    ');
17 select length(v),length(c),length(e),length(t) from t1;
18 select length(v),length(c),length(e),length(t) from vchar;
19 alter table vchar add i int;
20 show create table vchar;
21 select length(v),length(c),length(e),length(t) from vchar;
22 drop table t1, vchar;
23 create table t1 (v varchar(20));
24 insert into t1 values('a ');
25 select v='a' from t1;
26 select binary v='a' from t1;
27 select binary v='a ' from t1;
28 insert into t1 values('a');
29 --error ER_DUP_ENTRY
30 alter table t1 add primary key (v);
31 drop table t1;
32 create table t1 (v varbinary(20));
33 insert into t1 values('a');
34 insert into t1 values('a ');
35 alter table t1 add primary key (v);
36 drop table t1;
39 # Test with varchar of lengths 254,255,256,258 & 258 to ensure we don't
40 # have any problems with varchar with one or two byte length_bytes
43 create table t1 (v varchar(254), index (v));
44 insert into t1 values ("This is a test ");
45 insert into t1 values ("Some sample data");
46 insert into t1 values (" garbage ");
47 insert into t1 values (" This is a test ");
48 insert into t1 values ("This is a test");
49 insert into t1 values ("Hello world");
50 insert into t1 values ("Foo bar");
51 insert into t1 values ("This is a test");
52 insert into t1 values ("MySQL varchar test");
53 insert into t1 values ("test MySQL varchar");
54 insert into t1 values ("This is a long string to have some random length data included");
55 insert into t1 values ("Short string");
56 insert into t1 values ("VSS");
57 insert into t1 values ("Some samples");
58 insert into t1 values ("Bar foo");
59 insert into t1 values ("Bye");
60 let $i= 255;
61 let $j= 5;
62 while ($j)
64   select * from t1 where v like 'This is a test' order by v;
65   select * from t1 where v='This is a test' order by v;
66   select * from t1 where v like 'S%' order by v;
67   explain select * from t1 where v like 'This is a test' order by v;
68   explain select * from t1 where v='This is a test' order by v;
69   explain select * from t1 where v like 'S%' order by v;
70   eval alter table t1 change v v varchar($i);
71   inc $i;
72   dec $j;
74 let $i= 258;
75 let $j= 6;
76 while ($j)
78   select * from t1 where v like 'This is a test' order by v;
79   select * from t1 where v='This is a test' order by v;
80   select * from t1 where v like 'S%' order by v;
81   explain select * from t1 where v like 'This is a test' order by v;
82   explain select * from t1 where v='This is a test' order by v;
83   explain select * from t1 where v like 'S%' order by v;
84   eval alter table t1 change v v varchar($i);
85   dec $i;
86   dec $j;
88 alter table t1 change v v varchar(254), drop key v;
90 # Test with length(varchar) > 256 and key < 256 (to ensure things works with
91 # different kind of packing
93 alter table t1 change v v varchar(300), add key (v(10));
94 select * from t1 where v like 'This is a test' order by v;
95 select * from t1 where v='This is a test' order by v;
96 select * from t1 where v like 'S%' order by v;
97 explain select * from t1 where v like 'This is a test' order by v;
98 explain select * from t1 where v='This is a test' order by v;
99 explain select * from t1 where v like 'S%' order by v;
100 drop table t1;
103 # bug#9339 - meaningless Field_varstring::get_key_image
105 create table t1 (pkcol varchar(16), othercol varchar(16), primary key (pkcol));
106 insert into t1 values ('test', 'something');
107 update t1 set othercol='somethingelse' where pkcol='test';
108 select * from t1;
109 drop table t1;
112 # Bug #9489: problems with key handling
115 create table t1 (a int, b varchar(12));
116 insert into t1 values (1, 'A'), (22, NULL);
117 create table t2 (a int);
118 insert into t2 values (22), (22);
119 select t1.a, t1.b, min(t1.b) from t1 inner join t2 ON t2.a = t1.a 
120   group by t1.b, t1.a;
121 drop table t1, t2;
124 # Bug #10543: convert varchar with index to text
126 create table t1 (f1 varchar(65500));
127 create index index1 on t1(f1(10));
128 show create table t1;
129 alter table t1 modify f1 varchar(255);
130 show create table t1;
131 alter table t1 modify f1 tinytext;
132 show create table t1;
133 drop table t1;
136 # BUG#15588: String overrun
139 --disable_warnings
140 DROP TABLE IF EXISTS t1;
141 --enable_warnings
143 CREATE TABLE t1(f1 VARCHAR(100) DEFAULT 'test');
144 INSERT INTO t1 VALUES(SUBSTR(f1, 1, 3));
145 DROP TABLE IF EXISTS t1;
147 CREATE TABLE t1(f1 CHAR(100) DEFAULT 'test');
148 INSERT INTO t1 VALUES(SUBSTR(f1, 1, 3));
149 DROP TABLE IF EXISTS t1;
152 # Bug#14897 "ResultSet.getString("table.column") sometimes doesn't find the
153 # column"
154 # Test that after upgrading an old 4.1 VARCHAR column to 5.0 VARCHAR we preserve
155 # the original column metadata.
157 --disable_warnings
158 drop table if exists t1, t2, t3;
159 --enable_warnings
161 create table t3 (
162   id int(11),
163   en varchar(255) character set utf8,
164   cz varchar(255) character set utf8
166 remove_file $MYSQLD_DATADIR/test/t3.frm;
167 copy_file $MYSQL_TEST_DIR/std_data/14897.frm $MYSQLD_DATADIR/test/t3.frm;
168 truncate table t3;
169 insert into t3 (id, en, cz) values 
170 (1,'en string 1','cz string 1'),
171 (2,'en string 2','cz string 2'),
172 (3,'en string 3','cz string 3');
174 create table t1 ( 
175   id int(11),
176   name_id int(11)
178 insert into t1 (id, name_id) values (1,1), (2,3), (3,3);
180 create table t2 (id int(11));
181 insert into t2 (id) values (1), (2), (3);
183 # max_length is different for varchar fields in ps-protocol and we can't 
184 # replace a single metadata column, disable PS protocol
185 --disable_ps_protocol
186 --enable_metadata
187 select t1.*, t2.id, t3.en, t3.cz from t1 left join t2 on t1.id=t2.id
188 left join t3 on t1.id=t3.id order by t3.id;
189 --disable_metadata
190 --enable_ps_protocol
191 drop table t1, t2, t3;
194 # Bug #11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
196 CREATE TABLE t1 (a CHAR(2));
197 INSERT INTO t1 VALUES (10), (50), (30), ('1a'), (60), ('t');
198 SELECT a,(a + 0) FROM t1 ORDER BY a;
199 SELECT a,(a DIV 2) FROM t1 ORDER BY a;
200 SELECT a,CAST(a AS SIGNED) FROM t1 ORDER BY a;
201 DROP TABLE t1;