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

« back to all changes in this revision

Viewing changes to mysql-test/t/sql_mode.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
--disable_warnings
 
2
drop table if exists t1,t2,v1,v2;
 
3
drop view if exists t1,t2,v1,v2;
 
4
--enable_warnings
 
5
 
 
6
CREATE TABLE `t1` (
 
7
  a int not null auto_increment,
 
8
  `pseudo` varchar(35) character set latin2 NOT NULL default '',
 
9
  `email` varchar(60) character set latin2 NOT NULL default '',
 
10
  PRIMARY KEY  (a),
 
11
  UNIQUE KEY `email` USING BTREE (`email`) 
 
12
) ENGINE=HEAP CHARSET=latin1 ROW_FORMAT DYNAMIC;
 
13
set @@sql_mode="";
 
14
show variables like 'sql_mode';
 
15
show create table t1;
 
16
set @@sql_mode="ansi_quotes";
 
17
show variables like 'sql_mode';
 
18
show create table t1;
 
19
set @@sql_mode="no_table_options";
 
20
show variables like 'sql_mode';
 
21
show create table t1;
 
22
set @@sql_mode="no_key_options";
 
23
show variables like 'sql_mode';
 
24
show create table t1;
 
25
set @@sql_mode="no_field_options,mysql323,mysql40";
 
26
show variables like 'sql_mode';
 
27
show create table t1;
 
28
set sql_mode="postgresql,oracle,mssql,db2,maxdb";
 
29
select @@sql_mode;
 
30
show create table t1;
 
31
drop table t1;
 
32
 
 
33
#
 
34
# Check that a binary collation adds 'binary'
 
35
# suffix into a char() column definition in
 
36
# mysql40 and mysql2323 modes. This allows
 
37
# not to lose the column's case sensitivity
 
38
# when loading the dump in pre-4.1 servers. 
 
39
#
 
40
# Thus, in 4.0 and 3.23 modes we dump:
 
41
#
 
42
#   'char(10) collate xxx_bin' as 'char(10) binary' 
 
43
#   'binary(10)' as 'binary(10)'
 
44
#
 
45
# In mysql-4.1 these types are different, and they will
 
46
# be recreated differently.
 
47
#
 
48
# In mysqld-4.0 the the above two types were the same,
 
49
# so it will create a 'char(10) binary' column for both definitions.
 
50
 
51
CREATE TABLE t1 (
 
52
 a char(10),
 
53
 b char(10) collate latin1_bin,
 
54
 c binary(10)
 
55
) character set latin1;
 
56
set @@sql_mode="";
 
57
show create table t1;
 
58
set @@sql_mode="mysql323";
 
59
show create table t1;
 
60
set @@sql_mode="mysql40";
 
61
show create table t1;
 
62
drop table t1;
 
63
 
 
64
#
 
65
# BUG#5318 - failure: 'IGNORE_SPACE' affects numeric values after DEFAULT
 
66
#
 
67
# Force the usage of the default
 
68
set session sql_mode = '';
 
69
# statement for comparison, value starts with '.'
 
70
create table t1 ( min_num   dec(6,6)     default .000001);
 
71
show create table t1;
 
72
drop table t1 ;
 
73
#
 
74
set session sql_mode = 'IGNORE_SPACE';
 
75
# statement for comparison, value starts with '0'
 
76
create table t1 ( min_num   dec(6,6)     default 0.000001);
 
77
show create table t1;
 
78
drop table t1 ;
 
79
# This statement fails, value starts with '.'
 
80
create table t1 ( min_num   dec(6,6)     default .000001);
 
81
show create table t1;
 
82
drop table t1 ;
 
83
 
 
84
#
 
85
# Bug #10732: Set SQL_MODE to NULL gives garbled error message
 
86
#
 
87
--error 1231
 
88
set @@SQL_MODE=NULL;
 
89
 
 
90
#
 
91
# Bug #797: in sql_mode=ANSI, show create table ignores auto_increment
 
92
#
 
93
set session sql_mode=ansi;
 
94
create table t1
 
95
(f1 integer auto_increment primary key,
 
96
 f2 timestamp default current_timestamp on update current_timestamp);
 
97
show create table t1;
 
98
set session sql_mode=no_field_options;
 
99
show create table t1;
 
100
drop table t1;
 
101
 
 
102
# End of 4.1 tests
 
103
 
 
104
#
 
105
# test for 
 
106
#  WL 1941 "NO_C_ESCAPES sql_mode"
 
107
#
 
108
# an sql_mode to disable \n, \r, \b, etc escapes in string literals. actually, to
 
109
# disable special meaning of backslash completely. It's not in the SQL standard
 
110
# and it causes some R/3 tests to fail.
 
111
#
 
112
 
 
113
SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='';
 
114
show local variables like 'SQL_MODE';
 
115
 
 
116
CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
 
117
INSERT t1 (a) VALUES 
 
118
('\\'),
 
119
('\n'),
 
120
('\b'),
 
121
('\r'),
 
122
('\t'),
 
123
('\x'),
 
124
('\a'),
 
125
('\aa'),
 
126
('\\a'),
 
127
('\\aa'),
 
128
('_'),
 
129
('\_'),
 
130
('\\_'),
 
131
('\\\_'),
 
132
('\\\\_'),
 
133
('%'),
 
134
('\%'),
 
135
('\\%'),
 
136
('\\\%'),
 
137
('\\\\%')
 
138
;
 
139
 
 
140
SELECT p, hex(a) FROM t1;
 
141
 
 
142
delete from t1 where a in ('\n','\r','\t', '\b');
 
143
 
 
144
select
 
145
  masks.p,
 
146
  masks.a as mask,
 
147
  examples.a as example
 
148
from
 
149
            t1 as masks
 
150
  left join t1 as examples on examples.a LIKE masks.a
 
151
order by masks.p, example;
 
152
 
 
153
DROP TABLE t1;
 
154
 
 
155
SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
 
156
show local variables like 'SQL_MODE';
 
157
 
 
158
CREATE TABLE t1 (p int not null auto_increment, a varchar(20), primary key(p));
 
159
INSERT t1 (a) VALUES 
 
160
('\\'),
 
161
('\n'),
 
162
('\b'),
 
163
('\r'),
 
164
('\t'),
 
165
('\x'),
 
166
('\a'),
 
167
('\aa'),
 
168
('\\a'),
 
169
('\\aa'),
 
170
('_'),
 
171
('\_'),
 
172
('\\_'),
 
173
('\\\_'),
 
174
('\\\\_'),
 
175
('%'),
 
176
('\%'),
 
177
('\\%'),
 
178
('\\\%'),
 
179
('\\\\%')
 
180
;
 
181
 
 
182
SELECT p, hex(a) FROM t1;
 
183
 
 
184
delete from t1 where a in ('\n','\r','\t', '\b');
 
185
 
 
186
select 
 
187
  masks.p,
 
188
  masks.a as mask,
 
189
  examples.a as example
 
190
from
 
191
            t1 as masks
 
192
  left join t1 as examples on examples.a LIKE masks.a
 
193
order by masks.p, example;
 
194
 
 
195
DROP TABLE t1;
 
196
 
 
197
# Bug #6368: Make sure backslashes mixed with doubled quotes are handled
 
198
# correctly in NO_BACKSLASH_ESCAPES mode
 
199
SET @@SQL_MODE='NO_BACKSLASH_ESCAPES';
 
200
SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
 
201
SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
 
202
 
 
203
SET @@SQL_MODE='';
 
204
SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
 
205
SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
 
206
 
 
207
#
 
208
# Bug#6877: MySQL should give an error if the requested table type 
 
209
#           is not available
 
210
#
 
211
 
 
212
#set session sql_mode = 'NO_ENGINE_SUBSTITUTION';
 
213
#--error 1289
 
214
#create table t1 (a int) engine=isam;
 
215
#--error 1146
 
216
#show create table t1;
 
217
#drop table if exists t1;
 
218
#
 
219
## for comparison, lets see the warnings...
 
220
#set session sql_mode = '';
 
221
#create table t1 (a int) engine=isam;
 
222
#show create table t1;
 
223
#drop table t1;
 
224
 
 
225
#
 
226
# Bug #6903: ANSI_QUOTES does not come into play with SHOW CREATE FUNCTION
 
227
# or PROCEDURE because it displays the SQL_MODE used to create the routine.
 
228
#
 
229
SET @@SQL_MODE='';
 
230
create function `foo` () returns int return 5;
 
231
show create function `foo`;
 
232
SET @@SQL_MODE='ANSI_QUOTES';
 
233
show create function `foo`;
 
234
drop function `foo`;
 
235
 
 
236
create function `foo` () returns int return 5;
 
237
show create function `foo`;
 
238
SET @@SQL_MODE='';
 
239
show create function `foo`;
 
240
drop function `foo`;
 
241
 
 
242
 
243
# Bug #6903: ANSI_QUOTES should have effect for SHOW CREATE VIEW (Bug #6903)
 
244
#
 
245
SET @@SQL_MODE='';
 
246
create table t1 (a int);
 
247
create table t2 (a int);
 
248
create view v1 as select a from t1;
 
249
show create view v1;
 
250
SET @@SQL_MODE='ANSI_QUOTES';
 
251
show create view v1;
 
252
# Test a view with a subselect, which will get shown incorrectly without
 
253
# thd->lex->view_prepare_mode set properly.
 
254
create view v2 as select a from t2 where a in (select a from v1);
 
255
drop view v2, v1;
 
256
drop table t1, t2;
 
257
 
 
258
select @@sql_mode;
 
259
set sql_mode=2097152;
 
260
select @@sql_mode;
 
261
# BUG#14675
 
262
set sql_mode=4194304;
 
263
select @@sql_mode;
 
264
set sql_mode=16384+(65536*4);
 
265
select @@sql_mode;
 
266
--error 1231
 
267
set sql_mode=2147483648*2; # that mode does not exist
 
268
select @@sql_mode;
 
269
 
 
270
#
 
271
# Test WL921: Retain spaces when retrieving CHAR column values
 
272
 
 
273
set sql_mode=PAD_CHAR_TO_FULL_LENGTH;
 
274
create table t1 (a int auto_increment primary key, b char(5));
 
275
insert into t1 (b) values('a'),('b\t'),('c ');
 
276
select concat('x',b,'x') from t1;
 
277
set sql_mode=0;
 
278
select concat('x',b,'x') from t1;
 
279
drop table t1;
 
280
 
 
281
SET @@SQL_MODE=@OLD_SQL_MODE;
 
282
 
 
283
 
 
284
#
 
285
# Bug #32753: PAD_CHAR_TO_FULL_LENGTH is not documented and interferes
 
286
#             with grant tables
 
287
#
 
288
 
 
289
create user mysqltest_32753@localhost;
 
290
 
 
291
# try to make the user-table space-padded
 
292
--connection default
 
293
set @OLD_SQL_MODE=@@SESSION.SQL_MODE;
 
294
set session sql_mode='PAD_CHAR_TO_FULL_LENGTH';
 
295
flush privileges;
 
296
 
 
297
# if user-table is affected by PAD_CHAR_TO_FULL_LENGTH, our connect will fail
 
298
# --error 1045
 
299
connect (user_32753,localhost,mysqltest_32753,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
 
300
select current_user();
 
301
 
 
302
# clean up
 
303
--connection default
 
304
set session sql_mode=@OLD_SQL_MODE;
 
305
flush privileges;
 
306
 
 
307
--disconnect user_32753
 
308
 
 
309
--connection default
 
310
drop user mysqltest_32753@localhost;
 
311
 
 
312
#
 
313
# Bug#45100: Incomplete DROP USER in case of SQL_MODE = 'PAD_CHAR_TO_FULL_LENGTH'
 
314
#
 
315
 
 
316
--disable_warnings
 
317
DROP TABLE IF EXISTS t1,t2;
 
318
--enable_warnings
 
319
 
 
320
# Generate some prerequisites
 
321
CREATE USER 'user_PCTFL'@'localhost' identified by 'PWD';
 
322
CREATE USER 'user_no_PCTFL'@'localhost' identified by 'PWD';
 
323
 
 
324
CREATE TABLE t1 (f1 BIGINT);
 
325
CREATE TABLE t2 (f1 CHAR(3) NOT NULL, f2 CHAR(20));
 
326
 
 
327
# Grant privilege on a TABLE
 
328
GRANT ALL ON t1 TO 'user_PCTFL'@'localhost','user_no_PCTFL'@'localhost';
 
329
# Grant privilege on some COLUMN of a table
 
330
GRANT SELECT(f1) ON t2 TO 'user_PCTFL'@'localhost','user_no_PCTFL'@'localhost';
 
331
 
 
332
SET @OLD_SQL_MODE = @@SESSION.SQL_MODE;
 
333
SET SESSION SQL_MODE = 'PAD_CHAR_TO_FULL_LENGTH';
 
334
DROP USER 'user_PCTFL'@'localhost';
 
335
SET SESSION SQL_MODE = @OLD_SQL_MODE;
 
336
DROP USER 'user_no_PCTFL'@'localhost';
 
337
 
 
338
FLUSH PRIVILEGES;
 
339
 
 
340
SELECT * FROM mysql.db WHERE Host = 'localhost' AND User LIKE 'user_%PCTFL';
 
341
SELECT * FROM mysql.tables_priv WHERE Host = 'localhost' AND User LIKE 'user_%PCTFL';
 
342
SELECT * FROM mysql.columns_priv WHERE Host = 'localhost' AND User LIKE 'user_%PCTFL';
 
343
 
 
344
# Cleanup
 
345
DROP TABLE t1;
 
346
DROP TABLE t2;