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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
--disable_warnings
drop table if exists t1,t2,v1,v2;
drop view if exists t1,t2,v1,v2;
--enable_warnings

CREATE TABLE `t1` (
  a int not null auto_increment,
  `pseudo` varchar(35) character set latin2 NOT NULL default '',
  `email` varchar(60) character set latin2 NOT NULL default '',
  PRIMARY KEY  (a),
  UNIQUE KEY `email` USING BTREE (`email`) 
) ENGINE=HEAP CHARSET=latin1 ROW_FORMAT DYNAMIC;
set @@sql_mode="";
show variables like 'sql_mode';
show create table t1;
set @@sql_mode="ansi_quotes";
show variables like 'sql_mode';
show create table t1;
set @@sql_mode="no_table_options";
show variables like 'sql_mode';
show create table t1;
set @@sql_mode="no_key_options";
show variables like 'sql_mode';
show create table t1;
set @@sql_mode="no_field_options,mysql323,mysql40";
show variables like 'sql_mode';
show create table t1;
set sql_mode="postgresql,oracle,mssql,db2,maxdb";
select @@sql_mode;
show create table t1;
drop table t1;

#
# Check that a binary collation adds 'binary'
# suffix into a char() column definition in
# mysql40 and mysql2323 modes. This allows
# not to lose the column's case sensitivity
# when loading the dump in pre-4.1 servers. 
#
# Thus, in 4.0 and 3.23 modes we dump:
#
#   'char(10) collate xxx_bin' as 'char(10) binary' 
#   'binary(10)' as 'binary(10)'
#
# In mysql-4.1 these types are different, and they will
# be recreated differently.
#
# In mysqld-4.0 the the above two types were the same,
# so it will create a 'char(10) binary' column for both definitions.
# 
CREATE TABLE t1 (
 a char(10),
 b char(10) collate latin1_bin,
 c binary(10)
) character set latin1;
set @@sql_mode="";
show create table t1;
set @@sql_mode="mysql323";
show create table t1;
set @@sql_mode="mysql40";
show create table t1;
drop table t1;

#
# BUG#5318 - failure: 'IGNORE_SPACE' affects numeric values after DEFAULT
#
# Force the usage of the default
set session sql_mode = '';
# statement for comparison, value starts with '.'
create table t1 ( min_num   dec(6,6)     default .000001);
show create table t1;
drop table t1 ;
#
set session sql_mode = 'IGNORE_SPACE';
# statement for comparison, value starts with '0'
create table t1 ( min_num   dec(6,6)     default 0.000001);
show create table t1;
drop table t1 ;
# This statement fails, value starts with '.'
create table t1 ( min_num   dec(6,6)     default .000001);
show create table t1;
drop table t1 ;

#
# Bug #10732: Set SQL_MODE to NULL gives garbled error message
#
--error 1231
set @@SQL_MODE=NULL;

#
# Bug #797: in sql_mode=ANSI, show create table ignores auto_increment
#
set session sql_mode=ansi;
create table t1
(f1 integer auto_increment primary key,
 f2 timestamp default current_timestamp on update current_timestamp);
show create table t1;
set session sql_mode=no_field_options;
show create table t1;
drop table t1;

# End of 4.1 tests

#
# test for 
#  WL 1941 "NO_C_ESCAPES sql_mode"
#
# an sql_mode to disable \n, \r, \b, etc escapes in string literals. actually, to
# disable special meaning of backslash completely. It's not in the SQL standard
# and it causes some R/3 tests to fail.
#

SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='';
show local variables like 'SQL_MODE';

CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
INSERT t1 (a) VALUES 
('\\'),
('\n'),
('\b'),
('\r'),
('\t'),
('\x'),
('\a'),
('\aa'),
('\\a'),
('\\aa'),
('_'),
('\_'),
('\\_'),
('\\\_'),
('\\\\_'),
('%'),
('\%'),
('\\%'),
('\\\%'),
('\\\\%')
;

SELECT p, hex(a) FROM t1;

delete from t1 where a in ('\n','\r','\t', '\b');

select
  masks.p,
  masks.a as mask,
  examples.a as example
from
            t1 as masks
  left join t1 as examples on examples.a LIKE masks.a
order by masks.p, example;

DROP TABLE t1;

SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
show local variables like 'SQL_MODE';

CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
INSERT t1 (a) VALUES 
('\\'),
('\n'),
('\b'),
('\r'),
('\t'),
('\x'),
('\a'),
('\aa'),
('\\a'),
('\\aa'),
('_'),
('\_'),
('\\_'),
('\\\_'),
('\\\\_'),
('%'),
('\%'),
('\\%'),
('\\\%'),
('\\\\%')
;

SELECT p, hex(a) FROM t1;

delete from t1 where a in ('\n','\r','\t', '\b');

select 
  masks.p,
  masks.a as mask,
  examples.a as example
from
            t1 as masks
  left join t1 as examples on examples.a LIKE masks.a
order by masks.p, example;

DROP TABLE t1;

# Bug #6368: Make sure backslashes mixed with doubled quotes are handled
# correctly in NO_BACKSLASH_ESCAPES mode
SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";

SET @@SQL_MODE='';
SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";

#
# Bug#6877: MySQL should give an error if the requested table type 
#           is not available
#

#set session sql_mode = 'NO_ENGINE_SUBSTITUTION';
#--error 1289
#create table t1 (a int) engine=isam;
#--error 1146
#show create table t1;
#drop table if exists t1;
#
## for comparison, lets see the warnings...
#set session sql_mode = '';
#create table t1 (a int) engine=isam;
#show create table t1;
#drop table t1;

#
# Bug #6903: ANSI_QUOTES does not come into play with SHOW CREATE FUNCTION
# or PROCEDURE because it displays the SQL_MODE used to create the routine.
#
SET @@SQL_MODE='';
create function `foo` () returns int return 5;
show create function `foo`;
SET @@SQL_MODE='ANSI_QUOTES';
show create function `foo`;
drop function `foo`;

create function `foo` () returns int return 5;
show create function `foo`;
SET @@SQL_MODE='';
show create function `foo`;
drop function `foo`;

# 
# Bug #6903: ANSI_QUOTES should have effect for SHOW CREATE VIEW (Bug #6903)
#
SET @@SQL_MODE='';
create table t1 (a int);
create table t2 (a int);
create view v1 as select a from t1;
show create view v1;
SET @@SQL_MODE='ANSI_QUOTES';
show create view v1;
# Test a view with a subselect, which will get shown incorrectly without
# thd->lex->view_prepare_mode set properly.
create view v2 as select a from t2 where a in (select a from v1);
drop view v2, v1;
drop table t1, t2;

select @@sql_mode;
set sql_mode=2097152;
select @@sql_mode;
# BUG#14675
set sql_mode=4194304;
select @@sql_mode;
set sql_mode=16384+(65536*4);
select @@sql_mode;
--error 1231
set sql_mode=2147483648*2; # that mode does not exist
select @@sql_mode;

#
# Test WL921: Retain spaces when retrieving CHAR column values

set sql_mode=PAD_CHAR_TO_FULL_LENGTH;
create table t1 (a int auto_increment primary key, b char(5));
insert into t1 (b) values('a'),('b\t'),('c ');
select concat('x',b,'x') from t1;
set sql_mode=0;
select concat('x',b,'x') from t1;
drop table t1;

SET @@SQL_MODE=@OLD_SQL_MODE;


#
# Bug #32753: PAD_CHAR_TO_FULL_LENGTH is not documented and interferes
#             with grant tables
#

create user mysqltest_32753@localhost;

# try to make the user-table space-padded
--connection default
set @OLD_SQL_MODE=@@SESSION.SQL_MODE;
set session sql_mode='PAD_CHAR_TO_FULL_LENGTH';
flush privileges;

# if user-table is affected by PAD_CHAR_TO_FULL_LENGTH, our connect will fail
# --error 1045
connect (user_32753,localhost,mysqltest_32753,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
select current_user();

# clean up
--connection default
set session sql_mode=@OLD_SQL_MODE;
flush privileges;

--disconnect user_32753

--connection default
drop user mysqltest_32753@localhost;

#
# Bug#45100: Incomplete DROP USER in case of SQL_MODE = 'PAD_CHAR_TO_FULL_LENGTH'
#

--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings

# Generate some prerequisites
CREATE USER 'user_PCTFL'@'localhost' identified by 'PWD';
CREATE USER 'user_no_PCTFL'@'localhost' identified by 'PWD';

CREATE TABLE t1 (f1 BIGINT);
CREATE TABLE t2 (f1 CHAR(3) NOT NULL, f2 CHAR(20));

# Grant privilege on a TABLE
GRANT ALL ON t1 TO 'user_PCTFL'@'localhost','user_no_PCTFL'@'localhost';
# Grant privilege on some COLUMN of a table
GRANT SELECT(f1) ON t2 TO 'user_PCTFL'@'localhost','user_no_PCTFL'@'localhost';

SET @OLD_SQL_MODE = @@SESSION.SQL_MODE;
SET SESSION SQL_MODE = 'PAD_CHAR_TO_FULL_LENGTH';
DROP USER 'user_PCTFL'@'localhost';
SET SESSION SQL_MODE = @OLD_SQL_MODE;
DROP USER 'user_no_PCTFL'@'localhost';

FLUSH PRIVILEGES;

SELECT * FROM mysql.db WHERE Host = 'localhost' AND User LIKE 'user_%PCTFL';
SELECT * FROM mysql.tables_priv WHERE Host = 'localhost' AND User LIKE 'user_%PCTFL';
SELECT * FROM mysql.columns_priv WHERE Host = 'localhost' AND User LIKE 'user_%PCTFL';

# Cleanup
DROP TABLE t1;
DROP TABLE t2;