~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/strict.test

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Testing of "strict" mode
2
 
 
3
 
 
4
 
set @org_mode=@@sql_mode;
5
 
set @@sql_mode='ansi,traditional';
6
 
select @@sql_mode;
7
 
 
8
 
--disable_warnings
9
 
DROP TABLE IF EXISTS t1, t2;
10
 
--enable_warnings
11
 
 
12
 
# Test INSERT with DATE
13
 
 
14
 
CREATE TABLE t1 (col1 date);
15
 
INSERT INTO t1 VALUES('2004-01-01'),('2004-02-29');
16
 
INSERT INTO t1 VALUES('0000-10-31');
17
 
 
18
 
# All test cases expected to fail should return 
19
 
#      SQLSTATE 22007 <invalid date value>
20
 
--error 1292
21
 
INSERT INTO t1 VALUES('2004-0-31');
22
 
--error 1292
23
 
INSERT INTO t1 VALUES('2004-01-02'),('2004-0-31');
24
 
--error 1292
25
 
INSERT INTO t1 VALUES('2004-10-0');
26
 
--error 1292
27
 
INSERT INTO t1 VALUES('2004-09-31');
28
 
--error 1292
29
 
INSERT INTO t1 VALUES('2004-10-32');
30
 
--error 1292
31
 
INSERT INTO t1 VALUES('2003-02-29');
32
 
--error 1292
33
 
INSERT INTO t1 VALUES('2004-13-15');
34
 
--error 1292
35
 
INSERT INTO t1 VALUES('0000-00-00');
36
 
# Standard says we should return SQLSTATE 22018
37
 
--error 1292
38
 
INSERT INTO t1 VALUES ('59');
39
 
 
40
 
# Test the different related modes
41
 
set @@sql_mode='STRICT_ALL_TABLES';
42
 
INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31');
43
 
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
44
 
--error 1292
45
 
INSERT INTO t1 VALUES('2004-0-30');
46
 
--error 1292
47
 
INSERT INTO t1 VALUES('2004-01-04'),('2004-0-31'),('2004-01-05');
48
 
INSERT INTO t1 VALUES('0000-00-00');
49
 
INSERT IGNORE INTO t1 VALUES('2004-0-29');
50
 
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE';
51
 
--error 1292
52
 
INSERT INTO t1 VALUES('0000-00-00');
53
 
INSERT IGNORE INTO t1 VALUES('0000-00-00');
54
 
INSERT INTO t1 VALUES ('2004-0-30');
55
 
--error 1292
56
 
INSERT INTO t1 VALUES ('2004-2-30');
57
 
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
58
 
INSERT INTO t1 VALUES ('2004-2-30');
59
 
set @@sql_mode='ansi,traditional';
60
 
INSERT IGNORE INTO t1 VALUES('2004-02-29'),('2004-13-15'),('0000-00-00');
61
 
 
62
 
select * from t1;
63
 
drop table t1;
64
 
 
65
 
# Test difference in behaviour with InnoDB and MyISAM tables
66
 
 
67
 
set @@sql_mode='strict_trans_tables';
68
 
CREATE TABLE t1 (col1 date) engine=myisam;
69
 
--error 1292
70
 
INSERT INTO t1 VALUES('2004-13-31'),('2004-1-1');
71
 
INSERT INTO t1 VALUES ('2004-1-2'), ('2004-13-31'),('2004-1-3');
72
 
INSERT IGNORE INTO t1 VALUES('2004-13-31'),('2004-1-4');
73
 
--error 1292
74
 
INSERT INTO t1 VALUES ('2003-02-29');
75
 
INSERT ignore INTO t1 VALUES('2003-02-30');
76
 
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
77
 
INSERT ignore INTO t1 VALUES('2003-02-31');
78
 
select * from t1;
79
 
drop table t1;
80
 
 
81
 
set @@sql_mode='strict_trans_tables';
82
 
CREATE TABLE t1 (col1 date) engine=innodb;
83
 
--error 1292
84
 
INSERT INTO t1 VALUES('2004-13-31'),('2004-1-1');
85
 
--error 1292
86
 
INSERT INTO t1 VALUES ('2004-1-2'), ('2004-13-31'),('2004-1-3');
87
 
INSERT IGNORE INTO t1 VALUES('2004-13-31'),('2004-1-4');
88
 
--error 1292
89
 
INSERT INTO t1 VALUES ('2003-02-29');
90
 
INSERT ignore INTO t1 VALUES('2003-02-30');
91
 
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
92
 
INSERT ignore INTO t1 VALUES('2003-02-31');
93
 
select * from t1;
94
 
drop table t1;
95
 
set @@sql_mode='ansi,traditional';
96
 
 
97
 
# Test INSERT with DATETIME
98
 
 
99
 
CREATE TABLE t1 (col1 datetime);
100
 
INSERT INTO t1 VALUES('2004-10-31 15:30:00'),('2004-02-29 15:30:00');
101
 
INSERT INTO t1 VALUES('0000-10-31 15:30:00');
102
 
 
103
 
# All test cases expected to fail should return 
104
 
#      SQLSTATE 22007 <invalid datetime value>
105
 
--error 1292
106
 
INSERT INTO t1 VALUES('2004-0-31 15:30:00');
107
 
--error 1292
108
 
INSERT INTO t1 VALUES('2004-10-0 15:30:00');
109
 
--error 1292
110
 
INSERT INTO t1 VALUES('2004-09-31 15:30:00');
111
 
--error 1292
112
 
INSERT INTO t1 VALUES('2004-10-32 15:30:00');
113
 
--error 1292
114
 
INSERT INTO t1 VALUES('2003-02-29 15:30:00');
115
 
--error 1292
116
 
INSERT INTO t1 VALUES('2004-13-15 15:30:00');
117
 
--error 1292
118
 
INSERT INTO t1 VALUES('0000-00-00 15:30:00');
119
 
# Standard says we should return SQLSTATE 22018
120
 
--error 1292
121
 
INSERT INTO t1 VALUES ('59');
122
 
select * from t1;
123
 
drop table t1;
124
 
 
125
 
# Test INSERT with TIMESTAMP
126
 
 
127
 
CREATE TABLE t1 (col1 timestamp);
128
 
INSERT INTO t1 VALUES('2004-10-31 15:30:00'),('2004-02-29 15:30:00');
129
 
 
130
 
# All test cases expected to fail should return 
131
 
#      SQLSTATE 22007 <invalid datetime value>
132
 
# Standard says we should return ok, but we can't as this is out of range
133
 
--error 1292
134
 
INSERT INTO t1 VALUES('0000-10-31 15:30:00');
135
 
--error 1292
136
 
INSERT INTO t1 VALUES('2004-0-31 15:30:00');
137
 
--error 1292
138
 
INSERT INTO t1 VALUES('2004-10-0 15:30:00');
139
 
--error 1292
140
 
INSERT INTO t1 VALUES('2004-09-31 15:30:00');
141
 
--error 1292
142
 
INSERT INTO t1 VALUES('2004-10-32 15:30:00');
143
 
--error 1292
144
 
INSERT INTO t1 VALUES('2003-02-29 15:30:00');
145
 
--error 1292
146
 
INSERT INTO t1 VALUES('2004-13-15 15:30:00');
147
 
--error 1292
148
 
INSERT INTO t1 VALUES('2004-02-29 25:30:00');
149
 
--error 1292
150
 
INSERT INTO t1 VALUES('2004-02-29 15:65:00');
151
 
--error 1292
152
 
INSERT INTO t1 VALUES('2004-02-29 15:31:61');
153
 
--error 1292
154
 
INSERT INTO t1 VALUES('0000-00-00 15:30:00');
155
 
--error 1292
156
 
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
157
 
INSERT IGNORE INTO t1 VALUES('0000-00-00 00:00:00');
158
 
# Standard says we should return SQLSTATE 22018
159
 
--error 1292
160
 
INSERT INTO t1 VALUES ('59');
161
 
 
162
 
set @@sql_mode='STRICT_ALL_TABLES,ALLOW_INVALID_DATES';
163
 
--error 1292
164
 
INSERT INTO t1 VALUES('2004-0-31 15:30:00');
165
 
--error 1292
166
 
INSERT INTO t1 VALUES('2004-10-0 15:30:00');
167
 
--error 1292
168
 
INSERT INTO t1 VALUES('2004-10-32 15:30:00');
169
 
--error 1292
170
 
INSERT INTO t1 VALUES('2004-02-30 15:30:04');
171
 
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
172
 
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
173
 
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
174
 
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_DATE';
175
 
--error 1292
176
 
INSERT INTO t1 VALUES('0000-00-00 00:00:00');
177
 
set @@sql_mode='ansi,traditional';
178
 
SELECT * FROM t1;
179
 
DROP TABLE t1;
180
 
 
181
 
 
182
 
#### Test INSERT with STR_TO_DATE into DATE/DATETIME/TIMESTAMP
183
 
 
184
 
CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp);
185
 
 
186
 
INSERT INTO t1 (col1) VALUES (STR_TO_DATE('15.10.2004','%d.%m.%Y'));
187
 
INSERT INTO t1 (col2) VALUES (STR_TO_DATE('15.10.2004 10.15','%d.%m.%Y %H.%i'));
188
 
INSERT INTO t1 (col3) VALUES (STR_TO_DATE('15.10.2004 10.15','%d.%m.%Y %H.%i'));
189
 
 
190
 
## Test INSERT with STR_TO_DATE into DATE
191
 
#       All test cases expected to fail should return 
192
 
#       SQLSTATE 22007 <invalid date value>
193
 
 
194
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i'));
195
 
 
196
 
--error 1292
197
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i'));
198
 
--error 1292
199
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i'));
200
 
--error 1292
201
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i'));
202
 
--error 1411
203
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
204
 
--error 1292
205
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i'));
206
 
--error 1411
207
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i'));
208
 
--error 1292
209
 
INSERT INTO t1 (col1) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y'));
210
 
 
211
 
## Test INSERT with STR_TO_DATE into DATETIME
212
 
#       All test cases expected to fail should return 
213
 
#       SQLSTATE 22007 <invalid datetime value>
214
 
 
215
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i'));
216
 
 
217
 
--error 1292
218
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i'));
219
 
--error 1292
220
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i'));
221
 
--error 1292
222
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i'));
223
 
--error 1411
224
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
225
 
--error 1292
226
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i'));
227
 
--error 1411
228
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i'));
229
 
--error 1292
230
 
INSERT INTO t1 (col2) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y'));
231
 
 
232
 
## Test INSERT with STR_TO_DATE into TIMESTAMP
233
 
#       All test cases expected to fail should return 
234
 
#       SQLSTATE 22007 <invalid datetime value>
235
 
 
236
 
--error 1292
237
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.10.0000 15.30','%d.%m.%Y %H.%i'));
238
 
--error 1292
239
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.0.2004 15.30','%d.%m.%Y %H.%i'));
240
 
--error 1292
241
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('0.10.2004 15.30','%d.%m.%Y %H.%i'));
242
 
--error 1292
243
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('31.9.2004 15.30','%d.%m.%Y %H.%i'));
244
 
--error 1411
245
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
246
 
--error 1292
247
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('29.02.2003 15.30','%d.%m.%Y %H.%i'));
248
 
--error 1411
249
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('15.13.2004 15.30','%d.%m.%Y %H.%i'));
250
 
--error 1292
251
 
INSERT INTO t1 (col3) VALUES(STR_TO_DATE('00.00.0000','%d.%m.%Y'));
252
 
 
253
 
drop table t1;
254
 
 
255
 
 
256
 
#### Test INSERT with CAST AS DATE/DATETIME into DATE/DATETIME/TIMESTAMP
257
 
 
258
 
CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp);
259
 
 
260
 
INSERT INTO t1 (col1) VALUES (CAST('2004-10-15' AS DATE));
261
 
INSERT INTO t1 (col2) VALUES (CAST('2004-10-15 10:15' AS DATETIME));
262
 
INSERT INTO t1 (col3) VALUES (CAST('2004-10-15 10:15' AS DATETIME));
263
 
 
264
 
 
265
 
## Test INSERT with CAST AS DATE into DATE
266
 
#       All test cases expected to fail should return 
267
 
#       SQLSTATE 22007 <invalid date value>
268
 
 
269
 
INSERT INTO t1 (col1) VALUES(CAST('0000-10-31' AS DATE));
270
 
 
271
 
--error 1292
272
 
INSERT INTO t1 (col1) VALUES(CAST('2004-10-0' AS DATE));
273
 
--error 1292
274
 
INSERT INTO t1 (col1) VALUES(CAST('2004-0-10' AS DATE));
275
 
 
276
 
# deactivated because of Bug#8294
277
 
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
278
 
# --error 1292
279
 
# INSERT INTO t1 (col1) VALUES(CAST('2004-9-31' AS DATE));
280
 
# --error 1292
281
 
# INSERT INTO t1 (col1) VALUES(CAST('2004-10-32' AS DATE));
282
 
# --error 1292
283
 
# INSERT INTO t1 (col1) VALUES(CAST('2003-02-29' AS DATE));
284
 
# --error 1292
285
 
# INSERT INTO t1 (col1) VALUES(CAST('2004-13-15' AS DATE));
286
 
 
287
 
# deactivated because of Bug#6145
288
 
#  Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
289
 
--error 1292
290
 
INSERT INTO t1 (col1) VALUES(CAST('0000-00-00' AS DATE));
291
 
 
292
 
## Test INSERT with CAST AS DATETIME into DATETIME
293
 
#       All test cases expected to fail should return 
294
 
#       SQLSTATE 22007 <invalid datetime value>
295
 
 
296
 
INSERT INTO t1 (col2) VALUES(CAST('0000-10-31 15:30' AS DATETIME));
297
 
 
298
 
--error 1292
299
 
INSERT INTO t1 (col2) VALUES(CAST('2004-10-0 15:30' AS DATETIME));
300
 
--error 1292
301
 
INSERT INTO t1 (col2) VALUES(CAST('2004-0-10 15:30' AS DATETIME));
302
 
 
303
 
# deactivated because of Bug#8294
304
 
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
305
 
#--error 1292
306
 
#INSERT INTO t1 (col2) VALUES(CAST('2004-9-31 15:30' AS DATETIME));
307
 
#--error 1292
308
 
#INSERT INTO t1 (col2) VALUES(CAST('2004-10-32 15:30' AS DATETIME));
309
 
#--error 1292
310
 
#INSERT INTO t1 (col2) VALUES(CAST('2003-02-29 15:30' AS DATETIME));
311
 
#--error 1292
312
 
#INSERT INTO t1 (col2) VALUES(CAST('2004-13-15 15:30' AS DATETIME));
313
 
 
314
 
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
315
 
--error 1292
316
 
INSERT INTO t1 (col2) VALUES(CAST('0000-00-00' AS DATETIME));
317
 
 
318
 
## Test INSERT with CAST AS DATETIME into TIMESTAMP
319
 
#       All test cases expected to fail should return 
320
 
#       SQLSTATE 22007 <invalid datetime value>
321
 
--error 1292
322
 
INSERT INTO t1 (col3) VALUES(CAST('0000-10-31 15:30' AS DATETIME));
323
 
# should return OK
324
 
# We accept this to be a failure
325
 
 
326
 
--error 1292
327
 
INSERT INTO t1 (col3) VALUES(CAST('2004-10-0 15:30' AS DATETIME));
328
 
--error 1292
329
 
INSERT INTO t1 (col3) VALUES(CAST('2004-0-10 15:30' AS DATETIME));
330
 
# should return SQLSTATE 22007 <invalid datetime value>
331
 
 
332
 
# deactivated because of Bug#8294
333
 
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
334
 
#--error 1292
335
 
#INSERT INTO t1 (col3) VALUES(CAST('2004-9-31 15:30' AS DATETIME));
336
 
#--error 1292
337
 
#INSERT INTO t1 (col3) VALUES(CAST('2004-10-32 15:30' AS DATETIME));
338
 
#--error 1292
339
 
#INSERT INTO t1 (col3) VALUES(CAST('2003-02-29 15:30' AS DATETIME));
340
 
#--error 1292
341
 
#INSERT INTO t1 (col3) VALUES(CAST('2004-13-15 15:30' AS DATETIME));
342
 
 
343
 
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
344
 
--error 1292
345
 
INSERT INTO t1 (col3) VALUES(CAST('0000-00-00' AS DATETIME));
346
 
 
347
 
drop table t1;
348
 
 
349
 
 
350
 
#### Test INSERT with CONVERT to DATE/DATETIME into DATE/DATETIME/TIMESTAMP
351
 
 
352
 
CREATE TABLE t1 (col1 date, col2 datetime, col3 timestamp);
353
 
 
354
 
INSERT INTO t1 (col1) VALUES (CONVERT('2004-10-15',DATE));
355
 
INSERT INTO t1 (col2) VALUES (CONVERT('2004-10-15 10:15',DATETIME));
356
 
INSERT INTO t1 (col3) VALUES (CONVERT('2004-10-15 10:15',DATETIME));
357
 
 
358
 
 
359
 
## Test INSERT with CONVERT to DATE into DATE
360
 
#       All test cases expected to fail should return 
361
 
#       SQLSTATE 22007 <invalid date value>
362
 
 
363
 
INSERT INTO t1 (col1) VALUES(CONVERT('0000-10-31' , DATE));
364
 
 
365
 
--error 1292
366
 
INSERT INTO t1 (col1) VALUES(CONVERT('2004-10-0' , DATE));
367
 
--error 1292
368
 
INSERT INTO t1 (col1) VALUES(CONVERT('2004-0-10' , DATE));
369
 
 
370
 
# deactivated because of Bug#8294
371
 
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
372
 
#--error 1292
373
 
#INSERT INTO t1 (col1) VALUES(CONVERT('2004-9-31' , DATE));
374
 
#--error 1292
375
 
#INSERT INTO t1 (col1) VALUES(CONVERT('2004-10-32' , DATE));
376
 
#--error 1292
377
 
#INSERT INTO t1 (col1) VALUES(CONVERT('2003-02-29' , DATE));
378
 
#--error 1292
379
 
#INSERT INTO t1 (col1) VALUES(CONVERT('2004-13-15',DATE));
380
 
 
381
 
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
382
 
--error 1292
383
 
INSERT INTO t1 (col1) VALUES(CONVERT('0000-00-00',DATE));
384
 
 
385
 
## Test INSERT with CONVERT to DATETIME into DATETIME
386
 
#       All test cases expected to fail should return 
387
 
#       SQLSTATE 22007 <invalid datetime value>
388
 
 
389
 
INSERT INTO t1 (col2) VALUES(CONVERT('0000-10-31 15:30',DATETIME));
390
 
 
391
 
--error 1292
392
 
INSERT INTO t1 (col2) VALUES(CONVERT('2004-10-0 15:30',DATETIME));
393
 
--error 1292
394
 
INSERT INTO t1 (col2) VALUES(CONVERT('2004-0-10 15:30',DATETIME));
395
 
 
396
 
# deactivated because of Bug#8294
397
 
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
398
 
#--error 1292
399
 
#INSERT INTO t1 (col2) VALUES(CONVERT('2004-9-31 15:30',DATETIME));
400
 
#--error 1292
401
 
#INSERT INTO t1 (col2) VALUES(CONVERT('2004-10-32 15:30',DATETIME));
402
 
#--error 1292
403
 
#INSERT INTO t1 (col2) VALUES(CONVERT('2003-02-29 15:30',DATETIME));
404
 
#--error 1292
405
 
#INSERT INTO t1 (col2) VALUES(CONVERT('2004-13-15 15:30',DATETIME));
406
 
 
407
 
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
408
 
--error 1292
409
 
INSERT INTO t1 (col2) VALUES(CONVERT('0000-00-00',DATETIME));
410
 
 
411
 
## Test INSERT with CONVERT to DATETIME into DATETIME
412
 
#       All test cases expected to fail should return 
413
 
#       SQLSTATE 22007 <invalid datetime value>
414
 
--error 1292
415
 
INSERT INTO t1 (col3) VALUES(CONVERT('0000-10-31 15:30',DATETIME));
416
 
# should return OK
417
 
# We accept this to be a failure
418
 
 
419
 
--error 1292
420
 
INSERT INTO t1 (col3) VALUES(CONVERT('2004-10-0 15:30',DATETIME));
421
 
--error 1292
422
 
INSERT INTO t1 (col3) VALUES(CONVERT('2004-0-10 15:30',DATETIME));
423
 
 
424
 
# deactivated because of Bug#8294
425
 
# Bug#8294 Traditional: Misleading error message for invalid CAST to DATE
426
 
#--error 1292
427
 
#INSERT INTO t1 (col3) VALUES(CONVERT('2004-9-31 15:30',DATETIME));
428
 
#--error 1292
429
 
#INSERT INTO t1 (col3) VALUES(CONVERT('2004-10-32 15:30',DATETIME));
430
 
#--error 1292
431
 
#INSERT INTO t1 (col3) VALUES(CONVERT('2003-02-29 15:30',DATETIME));
432
 
#--error 1292
433
 
#INSERT INTO t1 (col3) VALUES(CONVERT('2004-13-15 15:30',DATETIME));
434
 
 
435
 
# Bug#6145: Traditional: CONVERT and CAST should reject zero DATE values
436
 
--error 1292
437
 
INSERT INTO t1 (col3) VALUES(CONVERT('0000-00-00',DATETIME));
438
 
 
439
 
drop table t1;
440
 
 
441
 
 
442
 
# Test INSERT with int
443
 
 
444
 
CREATE TABLE t1(col1 int, col2 int UNSIGNED);
445
 
INSERT INTO t1 VALUES(-128,0),(0,0),(127,255),('-128','0'),('0','0'),('127','255'),(-128.0,0.0),(0.0,0.0),(127.0,255.0);
446
 
# Test that we restored the mode checking properly after an ok query
447
 
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2;
448
 
INSERT INTO t1 (col1) VALUES(-129);
449
 
INSERT INTO t1 (col1) VALUES(128);
450
 
INSERT INTO t1 (col2) VALUES(-1);
451
 
INSERT INTO t1 (col2) VALUES(256);
452
 
INSERT INTO t1 (col1) VALUES('-129');
453
 
INSERT INTO t1 (col1) VALUES('128');
454
 
INSERT INTO t1 (col2) VALUES('-1');
455
 
INSERT INTO t1 (col2) VALUES('256');
456
 
INSERT INTO t1 (col1) VALUES(128.0);
457
 
INSERT INTO t1 (col2) VALUES(-1.0);
458
 
INSERT INTO t1 (col2) VALUES(256.0);
459
 
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 1;
460
 
--error 1264
461
 
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
462
 
--error 1264
463
 
UPDATE t1 SET col2=col2 + 50 WHERE col2 > 0;
464
 
--error 1365
465
 
UPDATE t1 SET col1=col1 / 0 WHERE col1 > 0;
466
 
set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO';
467
 
INSERT INTO t1 values (1/0,1/0);
468
 
set @@sql_mode='ansi,traditional';
469
 
SELECT MOD(col1,0) FROM t1 WHERE col1 > 0 LIMIT 2;
470
 
# Should return SQLSTATE 22018 invalid character value for cast
471
 
--error 1366
472
 
INSERT INTO t1 (col1) VALUES ('');
473
 
--error 1366
474
 
INSERT INTO t1 (col1) VALUES ('a59b');
475
 
--error 1265
476
 
INSERT INTO t1 (col1) VALUES ('1a');
477
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
478
 
INSERT IGNORE INTO t1 values (1/0,1/0);
479
 
set @@sql_mode='ansi';
480
 
INSERT INTO t1 values (1/0,1/0);
481
 
set @@sql_mode='ansi,traditional';
482
 
INSERT IGNORE INTO t1 VALUES('-129','-1'),('128','256');
483
 
INSERT IGNORE INTO t1 VALUES(-129.0,-1.0),(128.0,256.0);
484
 
UPDATE IGNORE t1 SET col2=1/NULL where col1=0;
485
 
 
486
 
SELECT * FROM t1;
487
 
DROP TABLE t1;
488
 
 
489
 
# Test INSERT with int
490
 
 
491
 
CREATE TABLE t1(col1 int, col2 int UNSIGNED);
492
 
INSERT INTO t1 VALUES(-32768,0),(0,0),(32767,65535),('-32768','0'),('32767','65535'),(-32768.0,0.0),(32767.0,65535.0);
493
 
 
494
 
--error 1264
495
 
INSERT INTO t1 (col1) VALUES(-32769);
496
 
--error 1264
497
 
INSERT INTO t1 (col1) VALUES(32768);
498
 
--error 1264
499
 
INSERT INTO t1 (col2) VALUES(-1);
500
 
--error 1264
501
 
INSERT INTO t1 (col2) VALUES(65536);
502
 
--error 1264
503
 
INSERT INTO t1 (col1) VALUES('-32769');
504
 
--error 1264
505
 
INSERT INTO t1 (col1) VALUES('32768');
506
 
--error 1264
507
 
INSERT INTO t1 (col2) VALUES('-1');
508
 
--error 1264
509
 
INSERT INTO t1 (col2) VALUES('65536');
510
 
--error 1264
511
 
INSERT INTO t1 (col1) VALUES(-32769.0);
512
 
--error 1264
513
 
INSERT INTO t1 (col1) VALUES(32768.0);
514
 
--error 1264
515
 
INSERT INTO t1 (col2) VALUES(-1.0);
516
 
--error 1264
517
 
INSERT INTO t1 (col2) VALUES(65536.0);
518
 
--error 1264
519
 
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
520
 
--error 1264
521
 
UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0;
522
 
--error 1365
523
 
UPDATE t1 SET col1 = col1 / 0 WHERE col1 > 0;
524
 
--error 1365
525
 
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
526
 
--error 1366
527
 
INSERT INTO t1 (col1) VALUES ('');
528
 
--error 1366
529
 
INSERT INTO t1 (col1) VALUES ('a59b');
530
 
--error 1265
531
 
INSERT INTO t1 (col1) VALUES ('1a');
532
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
533
 
INSERT IGNORE INTO t1 values (1/0,1/0);
534
 
INSERT IGNORE INTO t1 VALUES(-32769,-1),(32768,65536);
535
 
INSERT IGNORE INTO t1 VALUES('-32769','-1'),('32768','65536');
536
 
INSERT IGNORE INTO t1 VALUES(-32769,-1.0),(32768.0,65536.0);
537
 
UPDATE IGNORE t1 SET col2=1/NULL where col1=0;
538
 
 
539
 
SELECT * FROM t1;
540
 
DROP TABLE t1;
541
 
 
542
 
# Test INSERT with MEDIUMINT
543
 
 
544
 
CREATE TABLE t1 (col1 MEDIUMINT, col2 MEDIUMINT UNSIGNED);
545
 
INSERT INTO t1 VALUES(-8388608,0),(0,0),(8388607,16777215),('-8388608','0'),('8388607','16777215'),(-8388608.0,0.0),(8388607.0,16777215.0);
546
 
--error 1264
547
 
INSERT INTO t1 (col1) VALUES(-8388609);
548
 
--error 1264
549
 
INSERT INTO t1 (col1) VALUES(8388608);
550
 
--error 1264
551
 
INSERT INTO t1 (col2) VALUES(-1);
552
 
--error 1264
553
 
INSERT INTO t1 (col2) VALUES(16777216);
554
 
--error 1264
555
 
INSERT INTO t1 (col1) VALUES('-8388609');
556
 
--error 1264
557
 
INSERT INTO t1 (col1) VALUES('8388608');
558
 
--error 1264
559
 
INSERT INTO t1 (col2) VALUES('-1');
560
 
--error 1264
561
 
INSERT INTO t1 (col2) VALUES('16777216');
562
 
--error 1264
563
 
INSERT INTO t1 (col1) VALUES(-8388609.0);
564
 
--error 1264
565
 
INSERT INTO t1 (col1) VALUES(8388608.0);
566
 
--error 1264
567
 
INSERT INTO t1 (col2) VALUES(-1.0);
568
 
--error 1264
569
 
INSERT INTO t1 (col2) VALUES(16777216.0);
570
 
 
571
 
--error 1264
572
 
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
573
 
--error 1264
574
 
UPDATE t1 SET col2 = col2 + 50 WHERE col2 > 0;
575
 
--error 1365
576
 
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
577
 
--error 1365
578
 
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
579
 
--error 1366
580
 
INSERT INTO t1 (col1) VALUES ('');
581
 
--error 1366
582
 
INSERT INTO t1 (col1) VALUES ('a59b');
583
 
--error 1265
584
 
INSERT INTO t1 (col1) VALUES ('1a');
585
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
586
 
INSERT IGNORE INTO t1 values (1/0,1/0);
587
 
INSERT IGNORE INTO t1 VALUES(-8388609,-1),(8388608,16777216);
588
 
INSERT IGNORE INTO t1 VALUES('-8388609','-1'),('8388608','16777216');
589
 
INSERT IGNORE INTO t1 VALUES(-8388609.0,-1.0),(8388608.0,16777216.0);
590
 
UPDATE IGNORE t1 SET col2=1/NULL where col1=0;
591
 
 
592
 
SELECT * FROM t1;
593
 
DROP TABLE t1;
594
 
 
595
 
# Test INSERT with INT
596
 
 
597
 
CREATE TABLE t1 (col1 INT, col2 INT UNSIGNED);
598
 
INSERT INTO t1 VALUES(-2147483648,0),(0,0),(2147483647,4294967295),('-2147483648','0'),('2147483647','4294967295'),(-2147483648.0,0.0),(2147483647.0,4294967295.0);
599
 
--error 1264
600
 
INSERT INTO t1 (col1) VALUES(-2147483649);
601
 
--error 1264
602
 
INSERT INTO t1 (col1) VALUES(2147643648);
603
 
--error 1264
604
 
INSERT INTO t1 (col2) VALUES(-1);
605
 
--error 1264
606
 
INSERT INTO t1 (col2) VALUES(4294967296);
607
 
--error 1264
608
 
INSERT INTO t1 (col1) VALUES('-2147483649');
609
 
--error 1264
610
 
INSERT INTO t1 (col1) VALUES('2147643648');
611
 
--error 1264
612
 
INSERT INTO t1 (col2) VALUES('-1');
613
 
--error 1264
614
 
INSERT INTO t1 (col2) VALUES('4294967296');
615
 
--error 1264
616
 
INSERT INTO t1 (col1) VALUES(-2147483649.0);
617
 
--error 1264
618
 
INSERT INTO t1 (col1) VALUES(2147643648.0);
619
 
--error 1264
620
 
INSERT INTO t1 (col2) VALUES(-1.0);
621
 
--error 1264
622
 
INSERT INTO t1 (col2) VALUES(4294967296.0);
623
 
 
624
 
--error 1264
625
 
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
626
 
--error 1264
627
 
UPDATE t1 SET col2 =col2 + 50 WHERE col2 > 0;
628
 
--error 1365
629
 
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
630
 
--error 1365
631
 
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
632
 
--error 1366
633
 
INSERT INTO t1 (col1) VALUES ('');
634
 
--error 1366
635
 
INSERT INTO t1 (col1) VALUES ('a59b');
636
 
--error 1265
637
 
INSERT INTO t1 (col1) VALUES ('1a');
638
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
639
 
INSERT IGNORE INTO t1 values (1/0,1/0);
640
 
INSERT IGNORE INTO t1 values (-2147483649, -1),(2147643648,4294967296);
641
 
INSERT IGNORE INTO t1 values ('-2147483649', '-1'),('2147643648','4294967296');
642
 
INSERT IGNORE INTO t1 values (-2147483649.0, -1.0),(2147643648.0,4294967296.0);
643
 
UPDATE IGNORE t1 SET col2=1/NULL where col1=0;
644
 
SELECT * FROM t1;
645
 
DROP TABLE t1;
646
 
 
647
 
# Test INSERT with BIGINT
648
 
# Note that this doesn't behave 100 % to standard as we rotate
649
 
# integers when it's too big/small (just like C)
650
 
 
651
 
CREATE TABLE t1 (col1 BIGINT, col2 BIGINT UNSIGNED);
652
 
INSERT INTO t1 VALUES(-9223372036854775808,0),(0,0),(9223372036854775807,18446744073709551615);
653
 
INSERT INTO t1 VALUES('-9223372036854775808','0'),('9223372036854775807','18446744073709551615');
654
 
INSERT INTO t1 VALUES(-9223372036854774000.0,0.0),(9223372036854775700.0,1844674407370954000.0);
655
 
 
656
 
--error 1264
657
 
INSERT INTO t1 (col1) VALUES(-9223372036854775809);
658
 
--error 1264
659
 
INSERT INTO t1 (col1) VALUES(9223372036854775808);
660
 
--error 1264
661
 
INSERT INTO t1 (col2) VALUES(-1);
662
 
 
663
 
--error 1264
664
 
INSERT INTO t1 (col2) VALUES(18446744073709551616);
665
 
--error 1264
666
 
INSERT INTO t1 (col1) VALUES('-9223372036854775809');
667
 
--error 1264
668
 
INSERT INTO t1 (col1) VALUES('9223372036854775808');
669
 
--error 1264
670
 
INSERT INTO t1 (col2) VALUES('-1');
671
 
--error 1264
672
 
INSERT INTO t1 (col2) VALUES('18446744073709551616');
673
 
 
674
 
# Note that the following two double numbers are slighty bigger than max/min
675
 
# bigint becasue of rounding errors when converting it to bigint
676
 
--error 1264
677
 
INSERT INTO t1 (col1) VALUES(-9223372036854785809.0);
678
 
--error 1264
679
 
INSERT INTO t1 (col1) VALUES(9223372036854785808.0);
680
 
--error 1264
681
 
INSERT INTO t1 (col2) VALUES(-1.0);
682
 
--error 1264
683
 
INSERT INTO t1 (col2) VALUES(18446744073709551616.0);
684
 
 
685
 
# The following doesn't give an error as it's done in integer context
686
 
# UPDATE t1 SET col1=col1 - 5000 WHERE col1 < 0;
687
 
# UPDATE t1 SET col2 =col2 + 5000 WHERE col2 > 0;
688
 
 
689
 
--error 1365
690
 
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
691
 
--error 1365
692
 
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
693
 
--error 1366
694
 
INSERT INTO t1 (col1) VALUES ('');
695
 
--error 1366
696
 
INSERT INTO t1 (col1) VALUES ('a59b');
697
 
--error 1265
698
 
INSERT INTO t1 (col1) VALUES ('1a');
699
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
700
 
INSERT IGNORE INTO t1 values (1/0,1/0);
701
 
INSERT IGNORE INTO t1 VALUES(-9223372036854775809,-1),(9223372036854775808,18446744073709551616);
702
 
INSERT IGNORE INTO t1 VALUES('-9223372036854775809','-1'),('9223372036854775808','18446744073709551616');
703
 
INSERT IGNORE INTO t1 VALUES(-9223372036854785809.0,-1.0),(9223372036854785808.0,18446744073709551616.0);
704
 
UPDATE IGNORE t1 SET col2=1/NULL where col1=0;
705
 
SELECT * FROM t1;
706
 
DROP TABLE t1;
707
 
 
708
 
# Test INSERT with NUMERIC
709
 
 
710
 
CREATE TABLE t1 (col1 NUMERIC(4,2));
711
 
INSERT INTO t1 VALUES (10.55),(10.5555),(0),(-10.55),(-10.5555),(11),(1e+01);
712
 
# Note that the +/-10.5555 is inserted as +/-10.55, not +/-10.56 !
713
 
INSERT INTO t1 VALUES ('10.55'),('10.5555'),('-10.55'),('-10.5555'),('11'),('1e+01');
714
 
 
715
 
# The 2 following inserts should generate a warning, but doesn't yet
716
 
# because NUMERIC works like DECIMAL
717
 
--error 1264
718
 
INSERT INTO t1 VALUES (101.55);
719
 
--error 1264
720
 
INSERT INTO t1 VALUES (101);
721
 
--error 1264
722
 
INSERT INTO t1 VALUES (-101.55);
723
 
--error 1264
724
 
INSERT INTO t1 VALUES (1010.55);
725
 
--error 1264
726
 
INSERT INTO t1 VALUES (1010);
727
 
# The 2 following inserts should generate a warning, but doesn't yet
728
 
# because NUMERIC works like DECIMAL
729
 
--error 1264
730
 
INSERT INTO t1 VALUES ('101.55');
731
 
--error 1264
732
 
INSERT INTO t1 VALUES ('101');
733
 
--error 1264
734
 
INSERT INTO t1 VALUES ('-101.55');
735
 
--error 1264
736
 
INSERT INTO t1 VALUES ('-1010.55');
737
 
--error 1264
738
 
INSERT INTO t1 VALUES ('-100E+1');
739
 
--error 1366
740
 
INSERT INTO t1 VALUES ('-100E');
741
 
--error 1264
742
 
UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11;
743
 
--error 1365
744
 
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
745
 
--error 1365
746
 
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
747
 
#--error 1265
748
 
--error 1366
749
 
INSERT INTO t1 (col1) VALUES ('');
750
 
#--error 1265
751
 
--error 1366
752
 
INSERT INTO t1 (col1) VALUES ('a59b');
753
 
--error 1366
754
 
INSERT INTO t1 (col1) VALUES ('1a');
755
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
756
 
INSERT IGNORE INTO t1 values (1/0);
757
 
INSERT IGNORE INTO t1 VALUES(1000),(-1000);
758
 
INSERT IGNORE INTO t1 VALUES('1000'),('-1000');
759
 
INSERT IGNORE INTO t1 VALUES(1000.0),(-1000.0);
760
 
UPDATE IGNORE t1 SET col1=1/NULL where col1=0;
761
 
SELECT * FROM t1;
762
 
DROP TABLE t1;
763
 
 
764
 
# Test INSERT with FLOAT
765
 
 
766
 
CREATE TABLE t1 (col1 FLOAT, col2 FLOAT UNSIGNED);
767
 
INSERT INTO t1 VALUES (-1.1E-37,0),(+3.4E+38,+3.4E+38);
768
 
INSERT INTO t1 VALUES ('-1.1E-37',0),('+3.4E+38','+3.4E+38');
769
 
# We don't give warnings for underflow
770
 
INSERT INTO t1 (col1) VALUES (3E-46);
771
 
--error 1264
772
 
INSERT INTO t1 (col1) VALUES (+3.4E+39);
773
 
--error 1264
774
 
INSERT INTO t1 (col2) VALUES (-1.1E-3);
775
 
--error 1264
776
 
INSERT INTO t1 (col1) VALUES ('+3.4E+39');
777
 
--error 1264
778
 
INSERT INTO t1 (col2) VALUES ('-1.1E-3');
779
 
--error 1264
780
 
UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
781
 
--error 1365
782
 
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
783
 
--error 1365
784
 
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
785
 
--error 1265
786
 
INSERT INTO t1 (col1) VALUES ('');
787
 
--error 1265
788
 
INSERT INTO t1 (col1) VALUES ('a59b');
789
 
--error 1265
790
 
INSERT INTO t1 (col1) VALUES ('1a');
791
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
792
 
INSERT IGNORE INTO t1 (col1) VALUES (1/0);
793
 
INSERT IGNORE INTO t1 VALUES (+3.4E+39,-3.4E+39);
794
 
INSERT IGNORE INTO t1 VALUES ('+3.4E+39','-3.4E+39');
795
 
SELECT * FROM t1;
796
 
DROP TABLE t1;
797
 
 
798
 
# Test INSERT with DOUBLE
799
 
 
800
 
CREATE TABLE t1 (col1 DOUBLE PRECISION, col2 DOUBLE PRECISION UNSIGNED);
801
 
INSERT INTO t1 VALUES (-2.2E-307,0),(2E-307,0),(+1.7E+308,+1.7E+308);
802
 
INSERT INTO t1 VALUES ('-2.2E-307',0),('-2E-307',0),('+1.7E+308','+1.7E+308');
803
 
# We don't give warnings for underflow
804
 
INSERT INTO t1 (col1) VALUES (-2.2E-330);
805
 
--error 1367,1264
806
 
INSERT INTO t1 (col1) VALUES (+1.7E+309);
807
 
--error 1264
808
 
INSERT INTO t1 (col2) VALUES (-1.1E-3);
809
 
--error 1264
810
 
INSERT INTO t1 (col1) VALUES ('+1.8E+309');
811
 
--error 1264
812
 
INSERT INTO t1 (col2) VALUES ('-1.2E-3');
813
 
UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
814
 
--error 1365
815
 
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
816
 
--error 1365
817
 
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
818
 
--error 1265
819
 
INSERT INTO t1 (col1) VALUES ('');
820
 
--error 1265
821
 
INSERT INTO t1 (col1) VALUES ('a59b');
822
 
--error 1265
823
 
INSERT INTO t1 (col1) VALUES ('1a');
824
 
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
825
 
INSERT IGNORE INTO t1 (col1) values (1/0);
826
 
--error 1367
827
 
INSERT IGNORE INTO t1 VALUES (+1.9E+309,-1.9E+309);
828
 
INSERT IGNORE INTO t1 VALUES ('+2.0E+309','-2.0E+309');
829
 
# stupid...
830
 
--replace_result -0 0 1.7976931348623e+308 1.79769313486232e+308
831
 
SELECT * FROM t1;
832
 
DROP TABLE t1;
833
 
 
834
 
# Testing INSERT with CHAR/VARCHAR
835
 
 
836
 
CREATE TABLE t1 (col1 CHAR(5), col2 VARCHAR(6));
837
 
INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello   ', 'hello ');
838
 
--error 1406
839
 
INSERT INTO t1 (col1) VALUES ('hellobob');
840
 
--error 1406
841
 
INSERT INTO t1 (col2) VALUES ('hellobob');
842
 
INSERT INTO t1 (col2) VALUES ('hello  ');
843
 
--error 1406
844
 
UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he';
845
 
--error 1406
846
 
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
847
 
INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob');
848
 
UPDATE IGNORE t1 SET col2 ='hellotrudy' WHERE col2 ='he';
849
 
SELECT * FROM t1;
850
 
DROP TABLE t1;
851
 
 
852
 
# Testing INSERT with ENUM
853
 
 
854
 
CREATE TABLE t1 (col1 enum('red','blue','green'));
855
 
INSERT INTO t1 VALUES ('red'),('blue'),('green');
856
 
--error 1265
857
 
INSERT INTO t1 (col1) VALUES ('yellow');
858
 
--error 1265
859
 
INSERT INTO t1 (col1) VALUES ('redd');
860
 
--error 1265
861
 
INSERT INTO t1 VALUES ('');
862
 
--error 1265
863
 
UPDATE t1 SET col1 ='yellow' WHERE col1 ='green';
864
 
INSERT IGNORE INTO t1 VALUES ('yellow');
865
 
UPDATE IGNORE t1 SET col1 ='yellow' WHERE col1 ='blue';
866
 
SELECT * FROM t1;
867
 
DROP TABLE t1;
868
 
 
869
 
# Testing of insert of NULL in not NULL column
870
 
 
871
 
CREATE TABLE t1 (col1 INT NOT NULL, col2 CHAR(5) NOT NULL, col3 DATE NOT NULL);
872
 
INSERT INTO t1 VALUES (100, 'hello', '2004-08-20');
873
 
INSERT INTO t1 (col1,col2,col3) VALUES (101, 'hell2', '2004-08-21');
874
 
--error 1048
875
 
INSERT INTO t1 (col1,col2,col3) VALUES (NULL, '', '2004-01-01');
876
 
--error 1048
877
 
INSERT INTO t1 (col1,col2,col3) VALUES (102, NULL, '2004-01-01');
878
 
--error 1048
879
 
INSERT INTO t1 VALUES (103,'',NULL);
880
 
--error 1048
881
 
UPDATE t1 SET col1=NULL WHERE col1 =100;
882
 
--error 1048
883
 
UPDATE t1 SET col2 =NULL WHERE col2 ='hello';
884
 
--error 1048
885
 
UPDATE t1 SET col2 =NULL where col3 IS NOT NULL;
886
 
INSERT IGNORE INTO t1 values (NULL,NULL,NULL);
887
 
SELECT * FROM t1;
888
 
DROP TABLE t1;
889
 
 
890
 
# Testing of default values
891
 
 
892
 
CREATE TABLE t1 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL);
893
 
SHOW CREATE TABLE t1;
894
 
INSERT INTO t1 VALUES (1, 'hello');
895
 
INSERT INTO t1 (col2) VALUES ('hello2');
896
 
--error 1048
897
 
INSERT INTO t1 (col2) VALUES (NULL);
898
 
--error 1364
899
 
INSERT INTO t1 (col1) VALUES (2);
900
 
--error 1364
901
 
INSERT INTO t1 VALUES(default(col1),default(col2));
902
 
--error 1364
903
 
INSERT INTO t1 (col1) SELECT 1;
904
 
--error 1048
905
 
INSERT INTO t1 SELECT 1,NULL;
906
 
INSERT IGNORE INTO t1 values (NULL,NULL);
907
 
INSERT IGNORE INTO t1 (col1) values (3);
908
 
INSERT IGNORE INTO t1 () values ();
909
 
SELECT * FROM t1;
910
 
DROP TABLE t1;
911
 
 
912
 
#
913
 
# Bug #9029 Traditional: Wrong SQLSTATE returned for string truncation
914
 
#
915
 
 
916
 
set sql_mode='traditional';
917
 
create table t1 (charcol char(255), varcharcol varchar(255),
918
 
binarycol binary(255), varbinarycol varbinary(255), tinytextcol tinytext,
919
 
tinyblobcol tinyblob);
920
 
--error 1406
921
 
insert into t1 (charcol) values (repeat('x',256));
922
 
--error 1406
923
 
insert into t1 (varcharcol) values (repeat('x',256));
924
 
--error 1406
925
 
insert into t1 (binarycol) values (repeat('x',256));
926
 
--error 1406
927
 
insert into t1 (varbinarycol) values (repeat('x',256));
928
 
--error 1406
929
 
insert into t1 (tinytextcol) values (repeat('x',256));
930
 
--error 1406
931
 
insert into t1 (tinyblobcol) values (repeat('x',256));
932
 
select * from t1;
933
 
drop table t1;
934
 
 
935
 
#
936
 
# Bug #5902: STR_TO_DATE() didn't give errors in traditional mode
937
 
#
938
 
 
939
 
set sql_mode='traditional';
940
 
create table t1 (col1 datetime);
941
 
--error 1292
942
 
insert into t1 values(STR_TO_DATE('31.10.2004 15.30 abc','%d.%m.%Y %H.%i'));
943
 
--error 1411
944
 
insert into t1 values(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
945
 
--error 1411
946
 
insert into t1 values(STR_TO_DATE('2004.12.12 22:22:33 AM','%Y.%m.%d %r'));
947
 
--error 1411
948
 
insert into t1 values(STR_TO_DATE('2004.12.12 abc','%Y.%m.%d %T'));
949
 
set sql_mode='';
950
 
insert into t1 values(STR_TO_DATE('31.10.2004 15.30 abc','%d.%m.%Y %H.%i'));
951
 
insert into t1 values(STR_TO_DATE('32.10.2004 15.30','%d.%m.%Y %H.%i'));
952
 
insert into t1 values(STR_TO_DATE('2004.12.12 22:22:33 AM','%Y.%m.%d %r'));
953
 
insert into t1 values(STR_TO_DATE('2004.12.12 abc','%Y.%m.%d %T'));
954
 
 
955
 
# Some correct values, just to test the functions
956
 
insert into t1 values(STR_TO_DATE('31.10.2004 15.30','%d.%m.%Y %H.%i'));
957
 
insert into t1 values(STR_TO_DATE('2004.12.12 11:22:33 AM','%Y.%m.%d %r'));
958
 
insert into t1 values(STR_TO_DATE('2004.12.12 10:22:59','%Y.%m.%d %T'));
959
 
 
960
 
select * from t1;
961
 
 
962
 
# Check that select don't abort even in strict mode (for now)
963
 
set sql_mode='traditional';
964
 
 
965
 
select count(*) from t1 where STR_TO_DATE('2004.12.12 10:22:61','%Y.%m.%d %T') IS NULL;
966
 
 
967
 
drop table t1;
968
 
 
969
 
#
970
 
# Check insert with wrong CAST() (Bug #5912)
971
 
#
972
 
 
973
 
create table t1 (col1 char(3), col2 integer);
974
 
--error 1292
975
 
insert into t1 (col1) values (cast(1000 as char(3)));
976
 
--error 1292
977
 
insert into t1 (col1) values (cast(1000E+0 as char(3)));
978
 
--error 1292
979
 
insert into t1 (col1) values (cast(1000.0 as char(3)));
980
 
--error 1292
981
 
insert into t1 (col2) values (cast('abc' as signed integer));
982
 
--error 1292
983
 
insert into t1 (col2) values (10E+0 + 'a');
984
 
--error 1292
985
 
insert into t1 (col2) values (cast('10a' as integer));
986
 
insert into t1 (col2) values (cast('10' as integer));
987
 
insert into t1 (col2) values (cast('10' as signed integer));
988
 
insert into t1 (col2) values (10E+0 + '0 ');
989
 
select * from t1;
990
 
drop table t1;
991
 
 
992
 
#
993
 
# Zero dates using numbers was not checked properly (Bug #5933 & #6145)
994
 
#
995
 
 
996
 
create table t1 (col1 date, col2 datetime, col3 timestamp);
997
 
--error 1292
998
 
insert into t1 values (0,0,0);
999
 
--error 1292
1000
 
insert into t1 values (0.0,0.0,0.0);
1001
 
--error 1292
1002
 
insert into t1 (col1) values (convert('0000-00-00',date));
1003
 
--error 1292
1004
 
insert into t1 (col1) values (cast('0000-00-00' as date));
1005
 
 
1006
 
set sql_mode='no_zero_date';
1007
 
insert into t1 values (0,0,0);
1008
 
insert into t1 values (0.0,0.0,0.0);
1009
 
drop table t1;
1010
 
set sql_mode='traditional';
1011
 
create table t1 (col1 date);
1012
 
insert ignore into t1 values ('0000-00-00');
1013
 
--error 1292
1014
 
insert into t1 select * from t1;
1015
 
insert ignore into t1 values ('0000-00-00');
1016
 
insert ignore into t1 (col1) values (cast('0000-00-00' as date));
1017
 
--error 1292
1018
 
insert into t1 select * from t1;
1019
 
--error 1292
1020
 
alter table t1 modify col1 datetime;
1021
 
alter ignore table t1 modify col1 datetime;
1022
 
--error 1292
1023
 
insert into t1 select * from t1;
1024
 
select * from t1;
1025
 
drop table t1;
1026
 
 
1027
 
#
1028
 
# Test of inserting an invalid value via a stored procedure (Bug #5907)
1029
 
#
1030
 
create table t1 (col1 int);
1031
 
drop procedure if exists t1;
1032
 
delimiter |;
1033
 
create procedure t1 () begin declare exit handler for sqlexception
1034
 
select'a'; insert into t1 values (200); end;|
1035
 
delimiter ;|
1036
 
call t1();
1037
 
select * from t1;
1038
 
drop procedure t1;
1039
 
drop table t1;
1040
 
 
1041
 
#
1042
 
# Restore mode
1043
 
#
1044
 
set sql_mode=@org_mode;
1045
 
 
1046
 
# Test fields with no default value that are NOT NULL (Bug #5986)
1047
 
SET @@sql_mode = 'traditional';
1048
 
CREATE TABLE t1 (i int not null);
1049
 
--error 1364
1050
 
INSERT INTO t1 VALUES ();
1051
 
--error 1364
1052
 
INSERT INTO t1 VALUES (DEFAULT);
1053
 
--error 1364
1054
 
INSERT INTO t1 VALUES (DEFAULT(i));
1055
 
ALTER TABLE t1 ADD j int;
1056
 
--error 1364
1057
 
INSERT INTO t1 SET j = 1;
1058
 
--error 1364
1059
 
INSERT INTO t1 SET j = 1, i = DEFAULT;
1060
 
--error 1364
1061
 
INSERT INTO t1 SET j = 1, i = DEFAULT(i);
1062
 
--error 1364
1063
 
INSERT INTO t1 VALUES (DEFAULT,1);
1064
 
DROP TABLE t1;
1065
 
SET @@sql_mode = '';
1066
 
CREATE TABLE t1 (i int not null);
1067
 
INSERT INTO t1 VALUES ();
1068
 
INSERT INTO t1 VALUES (DEFAULT);
1069
 
# DEFAULT(i) is an error even with the default sql_mode
1070
 
--error 1364
1071
 
INSERT INTO t1 VALUES (DEFAULT(i));
1072
 
ALTER TABLE t1 ADD j int;
1073
 
INSERT INTO t1 SET j = 1;
1074
 
INSERT INTO t1 SET j = 1, i = DEFAULT;
1075
 
--error 1364
1076
 
INSERT INTO t1 SET j = 1, i = DEFAULT(i);
1077
 
INSERT INTO t1 VALUES (DEFAULT,1);
1078
 
DROP TABLE t1;
1079
 
 
1080
 
#
1081
 
# Bugs #8295 and #8296: varchar and varbinary conversion
1082
 
#
1083
 
 
1084
 
set @@sql_mode='traditional';
1085
 
--error 1074
1086
 
create table t1(a varchar(65537));
1087
 
--error 1074
1088
 
create table t1(a varbinary(65537));
1089
 
 
1090
 
#
1091
 
# Bug #9881: problem with altering table
1092
 
#
1093
 
 
1094
 
set @@sql_mode='traditional';
1095
 
create table t1(a int, b date not null);                                       
1096
 
alter table t1 modify a bigint not null;
1097
 
show create table t1;
1098
 
drop table t1;
1099
 
 
1100
 
#
1101
 
# Bug #5906: handle invalid date due to conversion
1102
 
#
1103
 
set @@sql_mode='traditional';
1104
 
create table t1 (d date);
1105
 
--error 1292
1106
 
insert into t1 values ('2000-10-00');
1107
 
--error 1292
1108
 
insert into t1 values (1000);
1109
 
insert into t1 values ('2000-10-01');
1110
 
--error 1292
1111
 
update t1 set d = 1100;
1112
 
select * from t1;
1113
 
drop table t1;
1114
 
 
1115
 
#
1116
 
# Bug #11964: alter table with timestamp field
1117
 
#
1118
 
 
1119
 
set @@sql_mode='traditional';
1120
 
create table t1(a int, b timestamp);
1121
 
alter table t1 add primary key(a);
1122
 
show create table t1;
1123
 
drop table t1;
1124
 
create table t1(a int, b timestamp default 20050102030405);
1125
 
alter table t1 add primary key(a);
1126
 
show create table t1;
1127
 
drop table t1;
1128
 
 
1129
 
#
1130
 
# BIT fields
1131
 
#
1132
 
 
1133
 
set @@sql_mode='traditional';
1134
 
create table t1(a bit(2));
1135
 
--error 1406
1136
 
insert into t1 values(b'101');
1137
 
select * from t1;
1138
 
drop table t1;
1139
 
 
1140
 
#
1141
 
# Bug#17626 CREATE TABLE ... SELECT failure with TRADITIONAL SQL mode
1142
 
#
1143
 
set sql_mode='traditional';
1144
 
create table t1 (date date not null);
1145
 
create table t2 select date from t1;
1146
 
show create table t2;
1147
 
drop table t2,t1;
1148
 
set @@sql_mode= @org_mode;
1149
 
 
1150
 
set names utf8;
1151
 
create table t1 (i int)
1152
 
comment '123456789*123456789*123456789*123456789*123456789*123456789*';
1153
 
show create table t1;
1154
 
drop table t1;
1155
 
 
1156
 
#
1157
 
# Bug #26359: Strings becoming truncated and converted to numbers under STRICT mode
1158
 
#
1159
 
set sql_mode= 'traditional';
1160
 
create table t1(col1 int, col2 int, 
1161
 
  col3 int, col4 int,
1162
 
  col5 mediumint, col6 mediumint,
1163
 
  col7 int, col8 int,
1164
 
  col9 bigint, col10 bigint);
1165
 
--error 1366
1166
 
insert into t1(col1) values('-');
1167
 
--error 1366
1168
 
insert into t1(col2) values('+');
1169
 
--error 1366
1170
 
insert into t1(col3) values('-');
1171
 
--error 1366
1172
 
insert into t1(col4) values('+');
1173
 
--error 1366
1174
 
insert into t1(col5) values('-');
1175
 
--error 1366
1176
 
insert into t1(col6) values('+');
1177
 
--error 1366
1178
 
insert into t1(col7) values('-');
1179
 
--error 1366
1180
 
insert into t1(col8) values('+');
1181
 
--error 1366
1182
 
insert into t1(col9) values('-');
1183
 
--error 1366
1184
 
insert into t1(col10) values('+');
1185
 
drop table t1;
1186
 
 
1187
 
#
1188
 
# Bug #27176: Assigning a string to an year column has unexpected results
1189
 
#
1190
 
set sql_mode='traditional';
1191
 
create table t1(a year);
1192
 
--error 1366
1193
 
insert into t1 values ('-');
1194
 
--error 1366
1195
 
insert into t1 values ('+');
1196
 
--error 1366
1197
 
insert into t1 values ('');
1198
 
--error 1265
1199
 
insert into t1 values ('2000a');
1200
 
--error 1265
1201
 
insert into t1 values ('2E3x');
1202
 
drop table t1;
1203
 
 
1204
 
#
1205
 
# Bug#27069 set with identical elements are created
1206
 
#
1207
 
set sql_mode='traditional';
1208
 
--error 1291
1209
 
create table t1 (f1 set('a','a'));
1210
 
--error 1291
1211
 
create table t1 (f1 enum('a','a'));
1212
 
 
1213
 
#
1214
 
# Bug #22824: strict, datetime, NULL, wrong warning
1215
 
#
1216
 
set @@sql_mode='NO_ZERO_DATE';
1217
 
create table t1(a datetime not null);
1218
 
select count(*) from t1 where a is null;
1219
 
drop table t1;
1220
 
 
1221
 
--echo End of 5.0 tests