1
# Testing of "strict" mode
7
DROP TABLE IF EXISTS t1;
9
CREATE TABLE t1 (col1 INT);
10
INSERT INTO t1 VALUES(-2147483648);
11
INSERT INTO t1 VALUES (0);
12
INSERT INTO t1 VALUES (2147483647);
13
INSERT INTO t1 VALUES ('-2147483648');
14
INSERT INTO t1 VALUES ('2147483647');
15
INSERT INTO t1 VALUES (-2147483648.0);
16
INSERT INTO t1 VALUES (2147483647.0);
17
--error ER_WARN_DATA_OUT_OF_RANGE
18
INSERT INTO t1 (col1) VALUES(-2147483649);
19
--error ER_WARN_DATA_OUT_OF_RANGE
20
INSERT INTO t1 (col1) VALUES(2147643648);
21
--error ER_WARN_DATA_OUT_OF_RANGE
22
INSERT INTO t1 (col1) VALUES('-2147483649');
23
--error ER_WARN_DATA_OUT_OF_RANGE
24
INSERT INTO t1 (col1) VALUES('2147643648');
25
--error ER_WARN_DATA_OUT_OF_RANGE
26
INSERT INTO t1 (col1) VALUES(-2147483649.0);
27
--error ER_WARN_DATA_OUT_OF_RANGE
28
INSERT INTO t1 (col1) VALUES(2147643648.0);
30
--error ER_WARN_DATA_OUT_OF_RANGE
31
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
32
--error ER_DIVISION_BY_ZERO
33
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
34
--error ER_DIVISION_BY_ZERO
35
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
36
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
37
INSERT INTO t1 (col1) VALUES ('');
38
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
39
INSERT INTO t1 (col1) VALUES ('a59b');
40
--error ER_WARN_DATA_TRUNCATED
41
INSERT INTO t1 (col1) VALUES ('1a');
42
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
43
--error ER_DIVISION_BY_ZERO
44
INSERT IGNORE INTO t1 values (1/0);
45
INSERT IGNORE INTO t1 values (-2147483649);
46
INSERT IGNORE INTO t1 values (2147643648);
47
INSERT IGNORE INTO t1 values ('-2147483649');
48
INSERT IGNORE INTO t1 values ('2147643648');
49
INSERT IGNORE INTO t1 values (-2147483649.0);
50
INSERT IGNORE INTO t1 values (2147643648.0);
54
# Test INSERT with BIGINT
55
# Note that this doesn't behave 100 % to standard as we rotate
56
# integers when it's too big/small (just like C)
58
CREATE TABLE t1 (col1 BIGINT);
59
INSERT INTO t1 VALUES (-9223372036854775808);
60
INSERT INTO t1 VALUES (0);
61
INSERT INTO t1 VALUES (9223372036854775807);
62
INSERT INTO t1 VALUES ('-9223372036854775808');
63
INSERT INTO t1 VALUES ('9223372036854775807');
64
INSERT INTO t1 VALUES (-9223372036854774000.0);
65
INSERT INTO t1 VALUES (9223372036854775700.0);
67
--error ER_WARN_DATA_OUT_OF_RANGE
68
INSERT INTO t1 (col1) VALUES(-9223372036854775809);
69
# https://bugs.launchpad.net/drizzle/+bug/316221
70
--error ER_WARN_DATA_OUT_OF_RANGE
71
INSERT INTO t1 (col1) VALUES(9223372036854775808);
73
--error ER_WARN_DATA_OUT_OF_RANGE
74
INSERT INTO t1 (col1) VALUES('-9223372036854775809');
75
--error ER_WARN_DATA_OUT_OF_RANGE
76
INSERT INTO t1 (col1) VALUES('9223372036854775808');
78
# Note that the following two double numbers are slighty bigger than max/min
79
# bigint becasue of rounding errors when converting it to bigint
80
--error ER_WARN_DATA_OUT_OF_RANGE
81
INSERT INTO t1 (col1) VALUES(-9223372036854785809.0);
82
--error ER_WARN_DATA_OUT_OF_RANGE
83
INSERT INTO t1 (col1) VALUES(9223372036854785808.0);
85
# The following doesn't give an error as it's done in integer context
86
# UPDATE t1 SET col1=col1 - 5000 WHERE col1 < 0;
87
# UPDATE t1 SET col2 =col2 + 5000 WHERE col2 > 0;
89
--error ER_DIVISION_BY_ZERO
90
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
91
--error ER_DIVISION_BY_ZERO
92
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
93
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
94
INSERT INTO t1 (col1) VALUES ('');
95
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
96
INSERT INTO t1 (col1) VALUES ('a59b');
97
--error ER_WARN_DATA_TRUNCATED
98
INSERT INTO t1 (col1) VALUES ('1a');
99
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
100
--error ER_DIVISION_BY_ZERO
101
INSERT IGNORE INTO t1 values (1/0);
102
INSERT IGNORE INTO t1 VALUES (-9223372036854775809);
103
INSERT IGNORE INTO t1 VALUES (9223372036854775808);
104
INSERT IGNORE INTO t1 VALUES ('-9223372036854775809');
105
INSERT IGNORE INTO t1 VALUES ('9223372036854775808');
106
INSERT IGNORE INTO t1 VALUES (-9223372036854785809.0);
107
INSERT IGNORE INTO t1 VALUES (9223372036854785808.0);
111
# Test INSERT with NUMERIC
113
CREATE TABLE t1 (col1 NUMERIC(4,2));
114
# The following INSERT statements used to look as follows before
115
# the fix for bug#337038 was implemented:
117
# VALUES (10.55),(10.5555),(0),(-10.55),(-10.5555),(11),(1e+01);
118
# Now that decimal truncation gives an error instead of a warning, we will
119
# get an error on certain INSERT statements below about decimal truncation.
121
INSERT INTO t1 VALUES (10.55);
122
# this statement errors due to decimal truncation. The number
123
# used in insertion is chosen to test that this this error does
125
--error ER_WARN_DATA_TRUNCATED
126
INSERT INTO t1 VALUES (10.5555);
127
INSERT INTO t1 VALUES (0);
128
INSERT INTO t1 VALUES (-10.55);
129
# this statement errors due to decimal truncation. The number
130
# used in insertion is chosen to test that this this error does
132
--error ER_WARN_DATA_TRUNCATED
133
INSERT INTO t1 VALUES (-10.5555);
134
INSERT INTO t1 VALUES (11);
135
INSERT INTO t1 VALUES (1e+01);
137
# The following INSERT statements used to look as follows before
138
# the fix for bug#337038 was implemented:
139
# INSERT INTO t1 VALUES ('10.55'),('10.5555'),('-10.55'),('-10.5555'),('11'),('1e+01');
140
# Now that decimal truncation gives an error instead of a warning, we will
141
# get an error on certain INSERT statements below about decimal truncation.
143
INSERT INTO t1 VALUES ('10.55');
144
# this statement errors due to decimal truncation. The number
145
# used in insertion is chosen to test that this this error does
147
--error ER_WARN_DATA_TRUNCATED
148
INSERT INTO t1 VALUES ('10.5555');
149
INSERT INTO t1 VALUES ('-10.55');
150
# this statement errors due to decimal truncation. The number
151
# used in insertion is chosen to test that this error does
153
--error ER_WARN_DATA_TRUNCATED
154
INSERT INTO t1 VALUES ('-10.5555');
155
INSERT INTO t1 VALUES ('11');
156
INSERT INTO t1 VALUES ('1e+01');
158
# The 2 following inserts should generate a warning, but doesn't yet
159
# because NUMERIC works like DECIMAL
160
--error ER_WARN_DATA_OUT_OF_RANGE
161
INSERT INTO t1 VALUES (101.55);
162
--error ER_WARN_DATA_OUT_OF_RANGE
163
INSERT INTO t1 VALUES (101);
164
--error ER_WARN_DATA_OUT_OF_RANGE
165
INSERT INTO t1 VALUES (-101.55);
166
--error ER_WARN_DATA_OUT_OF_RANGE
167
INSERT INTO t1 VALUES (1010.55);
168
--error ER_WARN_DATA_OUT_OF_RANGE
169
INSERT INTO t1 VALUES (1010);
170
# The 2 following inserts should generate a warning, but doesn't yet
171
# because NUMERIC works like DECIMAL
172
--error ER_WARN_DATA_OUT_OF_RANGE
173
INSERT INTO t1 VALUES ('101.55');
174
--error ER_WARN_DATA_OUT_OF_RANGE
175
INSERT INTO t1 VALUES ('101');
176
--error ER_WARN_DATA_OUT_OF_RANGE
177
INSERT INTO t1 VALUES ('-101.55');
178
--error ER_WARN_DATA_OUT_OF_RANGE
179
INSERT INTO t1 VALUES ('-1010.55');
180
--error ER_WARN_DATA_OUT_OF_RANGE
181
INSERT INTO t1 VALUES ('-100E+1');
182
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
183
INSERT INTO t1 VALUES ('-100E');
184
--error ER_WARN_DATA_OUT_OF_RANGE
185
UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11;
186
--error ER_DIVISION_BY_ZERO
187
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
188
--error ER_DIVISION_BY_ZERO
189
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
190
#--error ER_WARN_DATA_TRUNCATED
191
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
192
INSERT INTO t1 (col1) VALUES ('');
193
#--error ER_WARN_DATA_TRUNCATED
194
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
195
INSERT INTO t1 (col1) VALUES ('a59b');
196
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
197
INSERT INTO t1 (col1) VALUES ('1a');
198
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
199
--error ER_DIVISION_BY_ZERO
200
INSERT IGNORE INTO t1 values (1/0);
201
INSERT IGNORE INTO t1 VALUES (1000);
202
INSERT IGNORE INTO t1 VALUES (-1000);
203
INSERT IGNORE INTO t1 VALUES ('1000');
204
INSERT IGNORE INTO t1 VALUES ('-1000');
205
INSERT IGNORE INTO t1 VALUES (1000.0);
206
INSERT IGNORE INTO t1 VALUES (-1000.0);
207
UPDATE IGNORE t1 SET col1=1/NULL where col1=0;
212
# Testing INSERT with CHAR/VARCHAR
214
CREATE TABLE t1 (col1 CHAR(5), col2 VARCHAR(6));
215
INSERT INTO t1 VALUES ('hello', 'hello');
216
INSERT INTO t1 VALUES ('he', 'he');
217
--error ER_DATA_TOO_LONG
218
INSERT INTO t1 VALUES ('hello ', 'hello ');
219
--error ER_DATA_TOO_LONG
220
INSERT INTO t1 (col1) VALUES ('hellobob');
221
--error ER_DATA_TOO_LONG
222
INSERT INTO t1 (col2) VALUES ('hellobob');
223
--error ER_DATA_TOO_LONG
224
INSERT INTO t1 (col2) VALUES ('hello ');
225
--error ER_DATA_TOO_LONG
226
UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he';
227
--error ER_DATA_TOO_LONG
228
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
229
INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob');
230
UPDATE IGNORE t1 SET col2 ='hellotrudy' WHERE col2 ='he';
235
# Testing INSERT with ENUM
237
CREATE TABLE t1 (col1 enum('red','blue','green'));
238
INSERT INTO t1 VALUES ('red');
239
INSERT INTO t1 VALUES ('blue');
240
INSERT INTO t1 VALUES ('green');
241
--error ER_INVALID_ENUM_VALUE # Bad enum
242
INSERT INTO t1 (col1) VALUES ('yellow');
243
--error ER_INVALID_ENUM_VALUE # Bad enum
244
INSERT INTO t1 (col1) VALUES ('redd');
245
--error ER_INVALID_ENUM_VALUE # Bad enum
246
INSERT INTO t1 VALUES ('');
247
--error ER_INVALID_ENUM_VALUE # Bad enum
248
UPDATE t1 SET col1 ='yellow' WHERE col1 ='green';
249
--error ER_INVALID_ENUM_VALUE # Bad enum
250
INSERT IGNORE INTO t1 VALUES ('yellow');
251
--error ER_INVALID_ENUM_VALUE # Bad enum
252
UPDATE IGNORE t1 SET col1 ='yellow' WHERE col1 ='blue';
256
# Testing of insert of NULL in not NULL column
258
CREATE TABLE t1 (col1 INT NOT NULL, col2 CHAR(5) NOT NULL, col3 DATE NOT NULL);
259
INSERT INTO t1 VALUES (100, 'hello', '2004-08-20');
260
INSERT INTO t1 (col1,col2,col3) VALUES (101, 'hell2', '2004-08-21');
261
--error ER_BAD_NULL_ERROR
262
INSERT INTO t1 (col1,col2,col3) VALUES (NULL, '', '2004-01-01');
263
--error ER_BAD_NULL_ERROR
264
INSERT INTO t1 (col1,col2,col3) VALUES (102, NULL, '2004-01-01');
265
--error ER_BAD_NULL_ERROR
266
INSERT INTO t1 VALUES (103,'',NULL);
267
--error ER_BAD_NULL_ERROR
268
UPDATE t1 SET col1=NULL WHERE col1 =100;
269
--error ER_BAD_NULL_ERROR
270
UPDATE t1 SET col2 =NULL WHERE col2 ='hello';
271
--error ER_BAD_NULL_ERROR
272
UPDATE t1 SET col2 =NULL where col3 IS NOT NULL;
273
INSERT IGNORE INTO t1 values (NULL,NULL,NULL);
277
# Testing of default values
279
CREATE TABLE t1 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL);
280
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
281
SHOW CREATE TABLE t1;
282
INSERT INTO t1 VALUES (1, 'hello');
283
INSERT INTO t1 (col2) VALUES ('hello2');
284
--error ER_BAD_NULL_ERROR
285
INSERT INTO t1 (col2) VALUES (NULL);
286
--error ER_NO_DEFAULT_FOR_FIELD
287
INSERT INTO t1 (col1) VALUES (2);
288
--error ER_NO_DEFAULT_FOR_FIELD
289
INSERT INTO t1 VALUES(default(col1),default(col2));
290
--error ER_NO_DEFAULT_FOR_FIELD
291
INSERT INTO t1 (col1) SELECT 1;
292
--error ER_BAD_NULL_ERROR
293
INSERT INTO t1 SELECT 1,NULL;
294
INSERT IGNORE INTO t1 values (NULL,NULL);
295
--error ER_NO_DEFAULT_FOR_FIELD
296
INSERT IGNORE INTO t1 (col1) values (3);
297
--error ER_NO_DEFAULT_FOR_FIELD
298
INSERT IGNORE INTO t1 () values ();
303
# Bug #9029 Traditional: Wrong SQLSTATE returned for string truncation
306
create table t1 (charcol char(255), varcharcol varchar(255),
307
varbinarycol varbinary(255));
308
--error ER_DATA_TOO_LONG
309
insert into t1 (charcol) values (repeat('x',256));
310
--error ER_DATA_TOO_LONG
311
insert into t1 (varcharcol) values (repeat('x',256));
312
--error ER_DATA_TOO_LONG
313
insert into t1 (varbinarycol) values (repeat('x',256));
318
# Check insert with wrong CAST() (Bug #5912)
321
create table t1 (col1 char(3), col2 integer);
322
--error ER_TRUNCATED_WRONG_VALUE
323
insert into t1 (col1) values (cast(1000 as char(3)));
324
--error ER_TRUNCATED_WRONG_VALUE
325
insert into t1 (col1) values (cast(1000E+0 as char(3)));
326
--error ER_TRUNCATED_WRONG_VALUE
327
insert into t1 (col1) values (cast(1000.0 as char(3)));
328
--error ER_TRUNCATED_WRONG_VALUE
329
insert into t1 (col2) values (cast('abc' as DECIMAL));
330
--error ER_TRUNCATED_WRONG_VALUE
331
insert into t1 (col2) values (10E+0 + 'a');
332
--error ER_WARN_DATA_TRUNCATED
333
insert into t1 (col2) values ('10a');
334
insert into t1 (col2) values (cast('10a' as DECIMAL));
335
insert into t1 (col2) values (cast('10' as DECIMAL));
336
insert into t1 (col2) values (cast('10' as DECIMAL));
337
insert into t1 (col2) values (10E+0 + '0 ');
341
# Test fields with no default value that are NOT NULL (Bug #5986)
342
CREATE TABLE t1 (i int not null);
343
--error ER_NO_DEFAULT_FOR_FIELD
344
INSERT INTO t1 VALUES ();
345
--error ER_NO_DEFAULT_FOR_FIELD
346
INSERT INTO t1 VALUES (DEFAULT);
347
--error ER_NO_DEFAULT_FOR_FIELD
348
INSERT INTO t1 VALUES (DEFAULT(i));
349
ALTER TABLE t1 ADD j int;
350
--error ER_NO_DEFAULT_FOR_FIELD
351
INSERT INTO t1 SET j = 1;
352
--error ER_NO_DEFAULT_FOR_FIELD
353
INSERT INTO t1 SET j = 1, i = DEFAULT;
354
--error ER_NO_DEFAULT_FOR_FIELD
355
INSERT INTO t1 SET j = 1, i = DEFAULT(i);
356
--error ER_NO_DEFAULT_FOR_FIELD
357
INSERT INTO t1 VALUES (DEFAULT,1);
359
CREATE TABLE t1 (i int not null);
360
--error ER_NO_DEFAULT_FOR_FIELD
361
INSERT INTO t1 VALUES ();
362
--error ER_NO_DEFAULT_FOR_FIELD
363
INSERT INTO t1 VALUES (DEFAULT);
364
# DEFAULT(i) is an error even with the default sql_mode
365
--error ER_NO_DEFAULT_FOR_FIELD
366
INSERT INTO t1 VALUES (DEFAULT(i));
367
ALTER TABLE t1 ADD j int;
368
--error ER_NO_DEFAULT_FOR_FIELD
369
INSERT INTO t1 SET j = 1;
370
--error ER_NO_DEFAULT_FOR_FIELD
371
INSERT INTO t1 SET j = 1, i = DEFAULT;
372
--error ER_NO_DEFAULT_FOR_FIELD
373
INSERT INTO t1 SET j = 1, i = DEFAULT(i);
374
--error ER_NO_DEFAULT_FOR_FIELD
375
INSERT INTO t1 VALUES (DEFAULT,1);
379
# Bugs #8295 and #8296: varchar and varbinary conversion
382
--error ER_TOO_BIG_FIELDLENGTH
383
create table t1(a varchar(65537));
384
--error ER_TOO_BIG_FIELDLENGTH
385
create table t1(a varbinary(65537));
388
# Bug #9881: problem with altering table
391
create table t1(a int, b date not null);
392
alter table t1 modify a bigint not null;
393
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
394
show create table t1;
398
# Bug #11964: alter table with timestamp field
401
create table t1(a int, b timestamp);
402
alter table t1 add primary key(a);
403
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
404
show create table t1;
406
create table t1(a int, b timestamp default 20050102030405);
407
alter table t1 add primary key(a);
408
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
409
show create table t1;
414
# Bug#17626 CREATE TABLE ... SELECT failure with TRADITIONAL SQL mode
416
create table t1 (date date not null);
417
create table t2 select date from t1;
418
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
419
show create table t2;
422
create table t1 (i int)
423
comment='123456789*123456789*123456789*123456789*123456789*123456789*';
424
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
425
show create table t1;
429
# Bug #26359: Strings becoming truncated and converted to numbers under STRICT mode
432
create table t1(col1 int, col2 int,
435
col9 bigint, col10 bigint);
436
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
437
insert into t1(col1) values('-');
438
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
439
insert into t1(col2) values('+');
440
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
441
insert into t1(col3) values('-');
442
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
443
insert into t1(col4) values('+');
444
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
445
insert into t1(col7) values('-');
446
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
447
insert into t1(col8) values('+');
448
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
449
insert into t1(col9) values('-');
450
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
451
insert into t1(col10) values('+');
456
# Bug#27069 set with identical elements are created
458
--error ER_DUPLICATED_VALUE_IN_TYPE
459
create table t1 (f1 enum('a','a'));
461
--echo End of 5.0 tests