2
set @org_mode=@@sql_mode;
3
set @@sql_mode='ansi,traditional';
7
DROP TABLE IF EXISTS t1, t2;
10
# Test INSERT with DATE
12
CREATE TABLE t1 (col1 date);
13
INSERT INTO t1 VALUES('2004-01-01'),('2004-02-29');
14
INSERT INTO t1 VALUES('0000-10-31');
16
# All test cases expected to fail should return
17
# SQLSTATE 22007 <invalid date value>
18
--error ER_TRUNCATED_WRONG_VALUE
19
INSERT INTO t1 VALUES('2004-0-31');
20
--error ER_TRUNCATED_WRONG_VALUE
21
INSERT INTO t1 VALUES('2004-01-02'),('2004-0-31');
22
--error ER_TRUNCATED_WRONG_VALUE
23
INSERT INTO t1 VALUES('2004-10-0');
24
--error ER_TRUNCATED_WRONG_VALUE
25
INSERT INTO t1 VALUES('2004-09-31');
26
--error ER_TRUNCATED_WRONG_VALUE
27
INSERT INTO t1 VALUES('2004-10-32');
28
--error ER_TRUNCATED_WRONG_VALUE
29
INSERT INTO t1 VALUES('2003-02-29');
30
--error ER_TRUNCATED_WRONG_VALUE
31
INSERT INTO t1 VALUES('2004-13-15');
32
--error ER_TRUNCATED_WRONG_VALUE
33
INSERT INTO t1 VALUES('0000-00-00');
34
# Standard says we should return SQLSTATE 22018
35
--error ER_TRUNCATED_WRONG_VALUE
36
INSERT INTO t1 VALUES ('59');
38
# Test the different related modes
39
set @@sql_mode='STRICT_ALL_TABLES';
40
INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31');
41
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
42
--error ER_TRUNCATED_WRONG_VALUE
43
INSERT INTO t1 VALUES('2004-0-30');
44
--error ER_TRUNCATED_WRONG_VALUE
45
INSERT INTO t1 VALUES('2004-01-04'),('2004-0-31'),('2004-01-05');
46
INSERT INTO t1 VALUES('0000-00-00');
47
INSERT IGNORE INTO t1 VALUES('2004-0-29');
48
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE';
49
--error ER_TRUNCATED_WRONG_VALUE
50
INSERT INTO t1 VALUES('0000-00-00');
51
INSERT IGNORE INTO t1 VALUES('0000-00-00');
52
INSERT INTO t1 VALUES ('2004-0-30');
53
--error ER_TRUNCATED_WRONG_VALUE
54
INSERT INTO t1 VALUES ('2004-2-30');
55
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
56
INSERT INTO t1 VALUES ('2004-2-30');
57
set @@sql_mode='ansi,traditional';
58
INSERT IGNORE INTO t1 VALUES('2004-02-29'),('2004-13-15'),('0000-00-00');
62
# Test difference in behaviour with InnoDB and MyISAM tables
64
set @@sql_mode='strict_trans_tables';
65
CREATE TABLE t1 (col1 date) engine=myisam;
66
--error ER_TRUNCATED_WRONG_VALUE
67
INSERT INTO t1 VALUES('2004-13-31'),('2004-1-1');
68
INSERT INTO t1 VALUES ('2004-1-2'), ('2004-13-31'),('2004-1-3');
69
INSERT IGNORE INTO t1 VALUES('2004-13-31'),('2004-1-4');
70
--error ER_TRUNCATED_WRONG_VALUE
71
INSERT INTO t1 VALUES ('2003-02-29');
72
INSERT ignore INTO t1 VALUES('2003-02-30');
73
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
74
INSERT ignore INTO t1 VALUES('2003-02-31');
78
set @@sql_mode='strict_trans_tables';
79
CREATE TABLE t1 (col1 date) engine=innodb;
80
--error ER_TRUNCATED_WRONG_VALUE
81
INSERT INTO t1 VALUES('2004-13-31'),('2004-1-1');
82
--error ER_TRUNCATED_WRONG_VALUE
83
INSERT INTO t1 VALUES ('2004-1-2'), ('2004-13-31'),('2004-1-3');
84
INSERT IGNORE INTO t1 VALUES('2004-13-31'),('2004-1-4');
85
--error ER_TRUNCATED_WRONG_VALUE
86
INSERT INTO t1 VALUES ('2003-02-29');
87
INSERT ignore INTO t1 VALUES('2003-02-30');
88
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
89
INSERT ignore INTO t1 VALUES('2003-02-31');
94
# Test INSERT with DATETIME
96
CREATE TABLE t1 (col1 datetime);
97
INSERT INTO t1 VALUES('2004-10-31 15:30:00'),('2004-02-29 15:30:00');
98
INSERT INTO t1 VALUES('0000-10-31 15:30:00');
100
# All test cases expected to fail should return
101
# SQLSTATE 22007 <invalid datetime value>
102
--error ER_TRUNCATED_WRONG_VALUE
103
INSERT INTO t1 VALUES('2004-0-31 15:30:00');
104
--error ER_TRUNCATED_WRONG_VALUE
105
INSERT INTO t1 VALUES('2004-10-0 15:30:00');
106
--error ER_TRUNCATED_WRONG_VALUE
107
INSERT INTO t1 VALUES('2004-09-31 15:30:00');
108
--error ER_TRUNCATED_WRONG_VALUE
109
INSERT INTO t1 VALUES('2004-10-32 15:30:00');
110
--error ER_TRUNCATED_WRONG_VALUE
111
INSERT INTO t1 VALUES('2003-02-29 15:30:00');
112
--error ER_TRUNCATED_WRONG_VALUE
113
INSERT INTO t1 VALUES('2004-13-15 15:30:00');
114
--error ER_TRUNCATED_WRONG_VALUE
115
INSERT INTO t1 VALUES('0000-00-00 15:30:00');
116
# Standard says we should return SQLSTATE 22018
117
--error ER_TRUNCATED_WRONG_VALUE
118
INSERT INTO t1 VALUES ('59');
123
# Test INSERT with TIMESTAMP
125
CREATE TABLE t1 (col1 timestamp);
126
INSERT INTO t1 VALUES('2004-10-31 15:30:00'),('2004-02-29 15:30:00');
128
# All test cases expected to fail should return
129
# SQLSTATE 22007 <invalid datetime value>
130
# Standard says we should return ok, but we can't as this is out of range
131
--error ER_TRUNCATED_WRONG_VALUE
132
INSERT INTO t1 VALUES('0000-10-31 15:30:00');
133
--error ER_TRUNCATED_WRONG_VALUE
134
INSERT INTO t1 VALUES('2004-0-31 15:30:00');
135
--error ER_TRUNCATED_WRONG_VALUE
136
INSERT INTO t1 VALUES('2004-10-0 15:30:00');
137
--error ER_TRUNCATED_WRONG_VALUE
138
INSERT INTO t1 VALUES('2004-09-31 15:30:00');
139
--error ER_TRUNCATED_WRONG_VALUE
140
INSERT INTO t1 VALUES('2004-10-32 15:30:00');
141
--error ER_TRUNCATED_WRONG_VALUE
142
INSERT INTO t1 VALUES('2003-02-29 15:30:00');
143
--error ER_TRUNCATED_WRONG_VALUE
144
INSERT INTO t1 VALUES('2004-13-15 15:30:00');
145
--error ER_TRUNCATED_WRONG_VALUE
146
INSERT INTO t1 VALUES('2004-02-29 25:30:00');
147
--error ER_TRUNCATED_WRONG_VALUE
148
INSERT INTO t1 VALUES('2004-02-29 15:65:00');
149
--error ER_TRUNCATED_WRONG_VALUE
150
INSERT INTO t1 VALUES('2004-02-29 15:31:61');
151
--error ER_TRUNCATED_WRONG_VALUE
152
INSERT INTO t1 VALUES('0000-00-00 15:30:00');
153
--error ER_TRUNCATED_WRONG_VALUE
154
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
155
INSERT IGNORE INTO t1 VALUES('0000-00-00 00:00:00');
156
# Standard says we should return SQLSTATE 22018
157
--error ER_TRUNCATED_WRONG_VALUE
158
INSERT INTO t1 VALUES ('59');
160
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
161
--error ER_TRUNCATED_WRONG_VALUE
162
INSERT INTO t1 VALUES('2004-0-31 15:30:00');
163
--error ER_TRUNCATED_WRONG_VALUE
164
INSERT INTO t1 VALUES('2004-10-0 15:30:00');
165
--error ER_TRUNCATED_WRONG_VALUE
166
INSERT INTO t1 VALUES('2004-10-32 15:30:00');
167
--error ER_TRUNCATED_WRONG_VALUE
168
INSERT INTO t1 VALUES('2004-02-30 15:30:04');
169
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
170
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
171
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
172
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE';
173
--error ER_TRUNCATED_WRONG_VALUE
174
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
175
set @@sql_mode='ansi,traditional';
179
#### Test INSERT with STR_TO_DATE into DATE/DATETIME/TIMESTAMP
181
CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp);
183
INSERT INTO t1 (col1) VALUES (STR_TO_DATE('15.10.2004','%d.%m.%Y'));
184
INSERT INTO t1 (col2) VALUES (STR_TO_DATE('15.10.2004 10.15','%d.%m.%Y %H.%i'));
185
INSERT INTO t1 (col3) VALUES (STR_TO_DATE('15.10.2004 10.15','%d.%m.%Y %H.%i'));
187
## Test INSERT with STR_TO_DATE into DATE
188
# All test cases expected to fail should return
189
# SQLSTATE 22007 <invalid date value>
191
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i'));
193
--error ER_TRUNCATED_WRONG_VALUE
194
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i'));
195
--error ER_TRUNCATED_WRONG_VALUE
196
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i'));
197
--error ER_TRUNCATED_WRONG_VALUE
198
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i'));
199
--error ER_WRONG_VALUE_FOR_TYPE
200
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
201
--error ER_TRUNCATED_WRONG_VALUE
202
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i'));
203
--error ER_WRONG_VALUE_FOR_TYPE
204
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i'));
205
--error ER_TRUNCATED_WRONG_VALUE
206
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y'));
208
## Test INSERT with STR_TO_DATE into DATETIME
209
# All test cases expected to fail should return
210
# SQLSTATE 22007 <invalid datetime value>
212
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i'));
214
--error ER_TRUNCATED_WRONG_VALUE
215
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i'));
216
--error ER_TRUNCATED_WRONG_VALUE
217
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i'));
218
--error ER_TRUNCATED_WRONG_VALUE
219
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i'));
220
--error ER_WRONG_VALUE_FOR_TYPE
221
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
222
--error ER_TRUNCATED_WRONG_VALUE
223
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i'));
224
--error ER_WRONG_VALUE_FOR_TYPE
225
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i'));
226
--error ER_TRUNCATED_WRONG_VALUE
227
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y'));
229
## Test INSERT with STR_TO_DATE into TIMESTAMP
230
# All test cases expected to fail should return
231
# SQLSTATE 22007 <invalid datetime value>
233
--error ER_TRUNCATED_WRONG_VALUE
234
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i'));
235
--error ER_TRUNCATED_WRONG_VALUE
236
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i'));
237
--error ER_TRUNCATED_WRONG_VALUE
238
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i'));
239
--error ER_TRUNCATED_WRONG_VALUE
240
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i'));
241
--error ER_WRONG_VALUE_FOR_TYPE
242
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
243
--error ER_TRUNCATED_WRONG_VALUE
244
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i'));
245
--error ER_WRONG_VALUE_FOR_TYPE
246
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i'));
247
--error ER_TRUNCATED_WRONG_VALUE
248
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y'));
252
#### Test INSERT with CAST AS DATE/DATETIME into DATE/DATETIME/TIMESTAMP
254
CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp);
256
INSERT INTO t1 (col1) VALUES (CAST('2004-10-15' AS DATE));
257
INSERT INTO t1 (col2) VALUES (CAST('2004-10-15 10:15' AS DATETIME));
258
INSERT INTO t1 (col3) VALUES (CAST('2004-10-15 10:15' AS DATETIME));
261
## Test INSERT with CAST AS DATE into DATE
262
# All test cases expected to fail should return
263
# SQLSTATE 22007 <invalid date value>
265
INSERT INTO t1 (col1) VALUES(CAST('0000-10-31' AS DATE));
267
--error ER_TRUNCATED_WRONG_VALUE
268
INSERT INTO t1 (col1) VALUES(CAST('2004-10-0' AS DATE));
269
--error ER_TRUNCATED_WRONG_VALUE
270
INSERT INTO t1 (col1) VALUES(CAST('2004-0-10' AS DATE));
272
# deactivated because of Bug#8294
273
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
274
# --error ER_TRUNCATED_WRONG_VALUE
275
# INSERT INTO t1 (col1) VALUES(CAST('2004-9-31' AS DATE));
276
# --error ER_TRUNCATED_WRONG_VALUE
277
# INSERT INTO t1 (col1) VALUES(CAST('2004-10-32' AS DATE));
278
# --error ER_TRUNCATED_WRONG_VALUE
279
# INSERT INTO t1 (col1) VALUES(CAST('2003-02-29' AS DATE));
280
# --error ER_TRUNCATED_WRONG_VALUE
281
# INSERT INTO t1 (col1) VALUES(CAST('2004-13-15' AS DATE));
283
# deactivated because of Bug#6145
284
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
285
--error ER_TRUNCATED_WRONG_VALUE
286
INSERT INTO t1 (col1) VALUES(CAST('0000-00-00' AS DATE));
288
## Test INSERT with CAST AS DATETIME into DATETIME
289
# All test cases expected to fail should return
290
# SQLSTATE 22007 <invalid datetime value>
292
INSERT INTO t1 (col2) VALUES(CAST('0000-10-31 15:30' AS DATETIME));
294
--error ER_TRUNCATED_WRONG_VALUE
295
INSERT INTO t1 (col2) VALUES(CAST('2004-10-0 15:30' AS DATETIME));
296
--error ER_TRUNCATED_WRONG_VALUE
297
INSERT INTO t1 (col2) VALUES(CAST('2004-0-10 15:30' AS DATETIME));
299
# deactivated because of Bug#8294
300
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
301
#--error ER_TRUNCATED_WRONG_VALUE
302
#INSERT INTO t1 (col2) VALUES(CAST('2004-9-31 15:30' AS DATETIME));
303
#--error ER_TRUNCATED_WRONG_VALUE
304
#INSERT INTO t1 (col2) VALUES(CAST('2004-10-32 15:30' AS DATETIME));
305
#--error ER_TRUNCATED_WRONG_VALUE
306
#INSERT INTO t1 (col2) VALUES(CAST('2003-02-29 15:30' AS DATETIME));
307
#--error ER_TRUNCATED_WRONG_VALUE
308
#INSERT INTO t1 (col2) VALUES(CAST('2004-13-15 15:30' AS DATETIME));
310
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
311
--error ER_TRUNCATED_WRONG_VALUE
312
INSERT INTO t1 (col2) VALUES(CAST('0000-00-00' AS DATETIME));
314
## Test INSERT with CAST AS DATETIME into TIMESTAMP
315
# All test cases expected to fail should return
316
# SQLSTATE 22007 <invalid datetime value>
317
--error ER_TRUNCATED_WRONG_VALUE
318
INSERT INTO t1 (col3) VALUES(CAST('0000-10-31 15:30' AS DATETIME));
320
# We accept this to be a failure
322
--error ER_TRUNCATED_WRONG_VALUE
323
INSERT INTO t1 (col3) VALUES(CAST('2004-10-0 15:30' AS DATETIME));
324
--error ER_TRUNCATED_WRONG_VALUE
325
INSERT INTO t1 (col3) VALUES(CAST('2004-0-10 15:30' AS DATETIME));
326
# should return SQLSTATE 22007 <invalid datetime value>
328
# deactivated because of Bug#8294
329
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
330
#--error ER_TRUNCATED_WRONG_VALUE
331
#INSERT INTO t1 (col3) VALUES(CAST('2004-9-31 15:30' AS DATETIME));
332
#--error ER_TRUNCATED_WRONG_VALUE
333
#INSERT INTO t1 (col3) VALUES(CAST('2004-10-32 15:30' AS DATETIME));
334
#--error ER_TRUNCATED_WRONG_VALUE
335
#INSERT INTO t1 (col3) VALUES(CAST('2003-02-29 15:30' AS DATETIME));
336
#--error ER_TRUNCATED_WRONG_VALUE
337
#INSERT INTO t1 (col3) VALUES(CAST('2004-13-15 15:30' AS DATETIME));
339
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
340
--error ER_TRUNCATED_WRONG_VALUE
341
INSERT INTO t1 (col3) VALUES(CAST('0000-00-00' AS DATETIME));
346
#### Test INSERT with CONVERT to DATE/DATETIME into DATE/DATETIME/TIMESTAMP
348
CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp);
350
INSERT INTO t1 (col1) VALUES (CONVERT('2004-10-15',DATE));
351
INSERT INTO t1 (col2) VALUES (CONVERT('2004-10-15 10:15',DATETIME));
352
INSERT INTO t1 (col3) VALUES (CONVERT('2004-10-15 10:15',DATETIME));
355
## Test INSERT with CONVERT to DATE into DATE
356
# All test cases expected to fail should return
357
# SQLSTATE 22007 <invalid date value>
359
INSERT INTO t1 (col1) VALUES(CONVERT('0000-10-31' , DATE));
361
--error ER_TRUNCATED_WRONG_VALUE
362
INSERT INTO t1 (col1) VALUES(CONVERT('2004-10-0' , DATE));
363
--error ER_TRUNCATED_WRONG_VALUE
364
INSERT INTO t1 (col1) VALUES(CONVERT('2004-0-10' , DATE));
366
# deactivated because of Bug#8294
367
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
368
#--error ER_TRUNCATED_WRONG_VALUE
369
#INSERT INTO t1 (col1) VALUES(CONVERT('2004-9-31' , DATE));
370
#--error ER_TRUNCATED_WRONG_VALUE
371
#INSERT INTO t1 (col1) VALUES(CONVERT('2004-10-32' , DATE));
372
#--error ER_TRUNCATED_WRONG_VALUE
373
#INSERT INTO t1 (col1) VALUES(CONVERT('2003-02-29' , DATE));
374
#--error ER_TRUNCATED_WRONG_VALUE
375
#INSERT INTO t1 (col1) VALUES(CONVERT('2004-13-15',DATE));
377
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
378
--error ER_TRUNCATED_WRONG_VALUE
379
INSERT INTO t1 (col1) VALUES(CONVERT('0000-00-00',DATE));
381
## Test INSERT with CONVERT to DATETIME into DATETIME
382
# All test cases expected to fail should return
383
# SQLSTATE 22007 <invalid datetime value>
385
INSERT INTO t1 (col2) VALUES(CONVERT('0000-10-31 15:30',DATETIME));
387
--error ER_TRUNCATED_WRONG_VALUE
388
INSERT INTO t1 (col2) VALUES(CONVERT('2004-10-0 15:30',DATETIME));
389
--error ER_TRUNCATED_WRONG_VALUE
390
INSERT INTO t1 (col2) VALUES(CONVERT('2004-0-10 15:30',DATETIME));
392
# deactivated because of Bug#8294
393
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
394
#--error ER_TRUNCATED_WRONG_VALUE
395
#INSERT INTO t1 (col2) VALUES(CONVERT('2004-9-31 15:30',DATETIME));
396
#--error ER_TRUNCATED_WRONG_VALUE
397
#INSERT INTO t1 (col2) VALUES(CONVERT('2004-10-32 15:30',DATETIME));
398
#--error ER_TRUNCATED_WRONG_VALUE
399
#INSERT INTO t1 (col2) VALUES(CONVERT('2003-02-29 15:30',DATETIME));
400
#--error ER_TRUNCATED_WRONG_VALUE
401
#INSERT INTO t1 (col2) VALUES(CONVERT('2004-13-15 15:30',DATETIME));
403
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
404
--error ER_TRUNCATED_WRONG_VALUE
405
INSERT INTO t1 (col2) VALUES(CONVERT('0000-00-00',DATETIME));
407
## Test INSERT with CONVERT to DATETIME into DATETIME
408
# All test cases expected to fail should return
409
# SQLSTATE 22007 <invalid datetime value>
410
--error ER_TRUNCATED_WRONG_VALUE
411
INSERT INTO t1 (col3) VALUES(CONVERT('0000-10-31 15:30',DATETIME));
413
# We accept this to be a failure
415
--error ER_TRUNCATED_WRONG_VALUE
416
INSERT INTO t1 (col3) VALUES(CONVERT('2004-10-0 15:30',DATETIME));
417
--error ER_TRUNCATED_WRONG_VALUE
418
INSERT INTO t1 (col3) VALUES(CONVERT('2004-0-10 15:30',DATETIME));
420
# deactivated because of Bug#8294
421
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
422
#--error ER_TRUNCATED_WRONG_VALUE
423
#INSERT INTO t1 (col3) VALUES(CONVERT('2004-9-31 15:30',DATETIME));
424
#--error ER_TRUNCATED_WRONG_VALUE
425
#INSERT INTO t1 (col3) VALUES(CONVERT('2004-10-32 15:30',DATETIME));
426
#--error ER_TRUNCATED_WRONG_VALUE
427
#INSERT INTO t1 (col3) VALUES(CONVERT('2003-02-29 15:30',DATETIME));
428
#--error ER_TRUNCATED_WRONG_VALUE
429
#INSERT INTO t1 (col3) VALUES(CONVERT('2004-13-15 15:30',DATETIME));
431
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
432
--error ER_TRUNCATED_WRONG_VALUE
433
INSERT INTO t1 (col3) VALUES(CONVERT('0000-00-00',DATETIME));
438
# Zero dates using numbers was not checked properly (Bug #5933 & #6145)
441
create table t1 (col1 date, col2 datetime, col3 timestamp);
442
--error ER_TRUNCATED_WRONG_VALUE
443
insert into t1 values (0,0,0);
444
--error ER_TRUNCATED_WRONG_VALUE
445
insert into t1 values (0.0,0.0,0.0);
446
--error ER_TRUNCATED_WRONG_VALUE
447
insert into t1 (col1) values (convert('0000-00-00',date));
448
--error ER_TRUNCATED_WRONG_VALUE
449
insert into t1 (col1) values (cast('0000-00-00' as date));
451
set sql_mode='no_zero_date';
452
insert into t1 values (0,0,0);
453
insert into t1 values (0.0,0.0,0.0);
455
set sql_mode='traditional';
456
create table t1 (col1 date);
457
insert ignore into t1 values ('0000-00-00');
458
--error ER_TRUNCATED_WRONG_VALUE
459
insert into t1 select * from t1;
460
insert ignore into t1 values ('0000-00-00');
461
insert ignore into t1 (col1) values (cast('0000-00-00' as date));
462
--error ER_TRUNCATED_WRONG_VALUE
463
insert into t1 select * from t1;
464
--error ER_TRUNCATED_WRONG_VALUE
465
alter table t1 modify col1 datetime;
466
alter ignore table t1 modify col1 datetime;
467
--error ER_TRUNCATED_WRONG_VALUE
468
insert into t1 select * from t1;
473
# Bug #5906: handle invalid date due to conversion
475
create table t1 (d date);
476
--error ER_TRUNCATED_WRONG_VALUE
477
insert into t1 values ('2000-10-00');
478
--error ER_TRUNCATED_WRONG_VALUE
479
insert into t1 values (1000);
480
insert into t1 values ('2000-10-01');
481
--error ER_TRUNCATED_WRONG_VALUE
482
update t1 set d = 1100;
487
# Bug #22824: strict, datetime, NULL, wrong warning
489
set @@sql_mode='NO_ZERO_DATE';
490
create table t1(a datetime not null);
491
select count(*) from t1 where a is null;