1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
# Testing of "strict" mode
-- source include/have_innodb.inc
# Test INSERT with INT
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1 (col1 INT);
INSERT INTO t1 VALUES(-2147483648),(0),(2147483647),('-2147483648'),('2147483647'),(-2147483648.0),(2147483647.0);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(-2147483649);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(2147643648);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES('-2147483649');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES('2147643648');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(-2147483649.0);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(2147643648.0);
--error ER_WARN_DATA_OUT_OF_RANGE
UPDATE t1 SET col1 = col1 - 50 WHERE col1 < 0;
--error ER_DIVISION_BY_ZERO
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error ER_DIVISION_BY_ZERO
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('a59b');
--error 1265
INSERT INTO t1 (col1) VALUES ('1a');
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
INSERT IGNORE INTO t1 values (1/0);
INSERT IGNORE INTO t1 values (-2147483649),(2147643648);
INSERT IGNORE INTO t1 values ('-2147483649'),('2147643648');
INSERT IGNORE INTO t1 values (-2147483649.0),(2147643648.0);
SELECT * FROM t1;
DROP TABLE t1;
# Test INSERT with BIGINT
# Note that this doesn't behave 100 % to standard as we rotate
# integers when it's too big/small (just like C)
CREATE TABLE t1 (col1 BIGINT);
INSERT INTO t1 VALUES(-9223372036854775808),(0),(9223372036854775807);
INSERT INTO t1 VALUES('-9223372036854775808'),('9223372036854775807');
INSERT INTO t1 VALUES(-9223372036854774000.0),(9223372036854775700.0);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(-9223372036854775809);
# DISABLED due to https://bugs.launchpad.net/drizzle/+bug/316221
# --error ER_WARN_DATA_OUT_OF_RANGE
# INSERT INTO t1 (col1) VALUES(9223372036854775808);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES('-9223372036854775809');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES('9223372036854775808');
# Note that the following two double numbers are slighty bigger than max/min
# bigint becasue of rounding errors when converting it to bigint
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(-9223372036854785809.0);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 (col1) VALUES(9223372036854785808.0);
# The following doesn't give an error as it's done in integer context
# UPDATE t1 SET col1=col1 - 5000 WHERE col1 < 0;
# UPDATE t1 SET col2 =col2 + 5000 WHERE col2 > 0;
--error ER_DIVISION_BY_ZERO
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error ER_DIVISION_BY_ZERO
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('a59b');
--error 1265
INSERT INTO t1 (col1) VALUES ('1a');
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
INSERT IGNORE INTO t1 values (1/0);
INSERT IGNORE INTO t1 VALUES(-9223372036854775809),(9223372036854775808);
INSERT IGNORE INTO t1 VALUES('-9223372036854775809'),('9223372036854775808');
INSERT IGNORE INTO t1 VALUES(-9223372036854785809.0),(9223372036854785808.0);
SELECT * FROM t1;
DROP TABLE t1;
# Test INSERT with NUMERIC
CREATE TABLE t1 (col1 NUMERIC(4,2));
INSERT INTO t1 VALUES (10.55),(10.5555),(0),(-10.55),(-10.5555),(11),(1e+01);
# Note that the +/-10.5555 is inserted as +/-10.55, not +/-10.56 !
INSERT INTO t1 VALUES ('10.55'),('10.5555'),('-10.55'),('-10.5555'),('11'),('1e+01');
# The 2 following inserts should generate a warning, but doesn't yet
# because NUMERIC works like DECIMAL
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES (101.55);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES (101);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES (-101.55);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES (1010.55);
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES (1010);
# The 2 following inserts should generate a warning, but doesn't yet
# because NUMERIC works like DECIMAL
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES ('101.55');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES ('101');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES ('-101.55');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES ('-1010.55');
--error ER_WARN_DATA_OUT_OF_RANGE
INSERT INTO t1 VALUES ('-100E+1');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 VALUES ('-100E');
--error ER_WARN_DATA_OUT_OF_RANGE
UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11;
--error ER_DIVISION_BY_ZERO
UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0;
--error ER_DIVISION_BY_ZERO
UPDATE t1 SET col1= MOD(col1,0) WHERE col1 > 0;
#--error 1265
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('');
#--error 1265
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('a59b');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
INSERT INTO t1 (col1) VALUES ('1a');
INSERT IGNORE INTO t1 (col1) VALUES ('2a');
INSERT IGNORE INTO t1 values (1/0);
INSERT IGNORE INTO t1 VALUES(1000),(-1000);
INSERT IGNORE INTO t1 VALUES('1000'),('-1000');
INSERT IGNORE INTO t1 VALUES(1000.0),(-1000.0);
UPDATE IGNORE t1 SET col1=1/NULL where col1=0;
SELECT * FROM t1;
DROP TABLE t1;
# Testing INSERT with CHAR/VARCHAR
CREATE TABLE t1 (col1 CHAR(5), col2 VARCHAR(6));
INSERT INTO t1 VALUES ('hello', 'hello'),('he', 'he'),('hello ', 'hello ');
--error 1406
INSERT INTO t1 (col1) VALUES ('hellobob');
--error 1406
INSERT INTO t1 (col2) VALUES ('hellobob');
INSERT INTO t1 (col2) VALUES ('hello ');
--error 1406
UPDATE t1 SET col1 ='hellobob' WHERE col1 ='he';
--error 1406
UPDATE t1 SET col2 ='hellobob' WHERE col2 ='he';
INSERT IGNORE INTO t1 VALUES ('hellobob', 'hellobob');
UPDATE IGNORE t1 SET col2 ='hellotrudy' WHERE col2 ='he';
SELECT * FROM t1;
DROP TABLE t1;
# Testing INSERT with ENUM
CREATE TABLE t1 (col1 enum('red','blue','green'));
INSERT INTO t1 VALUES ('red'),('blue'),('green');
--error 1265
INSERT INTO t1 (col1) VALUES ('yellow');
--error 1265
INSERT INTO t1 (col1) VALUES ('redd');
--error 1265
INSERT INTO t1 VALUES ('');
--error 1265
UPDATE t1 SET col1 ='yellow' WHERE col1 ='green';
INSERT IGNORE INTO t1 VALUES ('yellow');
UPDATE IGNORE t1 SET col1 ='yellow' WHERE col1 ='blue';
SELECT * FROM t1;
DROP TABLE t1;
# Testing of insert of NULL in not NULL column
CREATE TABLE t1 (col1 INT NOT NULL, col2 CHAR(5) NOT NULL, col3 DATE NOT NULL);
INSERT INTO t1 VALUES (100, 'hello', '2004-08-20');
INSERT INTO t1 (col1,col2,col3) VALUES (101, 'hell2', '2004-08-21');
--error 1048
INSERT INTO t1 (col1,col2,col3) VALUES (NULL, '', '2004-01-01');
--error 1048
INSERT INTO t1 (col1,col2,col3) VALUES (102, NULL, '2004-01-01');
--error 1048
INSERT INTO t1 VALUES (103,'',NULL);
--error 1048
UPDATE t1 SET col1=NULL WHERE col1 =100;
--error 1048
UPDATE t1 SET col2 =NULL WHERE col2 ='hello';
--error 1048
UPDATE t1 SET col2 =NULL where col3 IS NOT NULL;
INSERT IGNORE INTO t1 values (NULL,NULL,NULL);
SELECT * FROM t1;
DROP TABLE t1;
# Testing of default values
CREATE TABLE t1 (col1 INT NOT NULL default 99, col2 CHAR(6) NOT NULL);
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES (1, 'hello');
INSERT INTO t1 (col2) VALUES ('hello2');
--error 1048
INSERT INTO t1 (col2) VALUES (NULL);
--error 1364
INSERT INTO t1 (col1) VALUES (2);
--error 1364
INSERT INTO t1 VALUES(default(col1),default(col2));
--error 1364
INSERT INTO t1 (col1) SELECT 1;
--error 1048
INSERT INTO t1 SELECT 1,NULL;
INSERT IGNORE INTO t1 values (NULL,NULL);
--error ER_NO_DEFAULT_FOR_FIELD
INSERT IGNORE INTO t1 (col1) values (3);
--error ER_NO_DEFAULT_FOR_FIELD
INSERT IGNORE INTO t1 () values ();
SELECT * FROM t1;
DROP TABLE t1;
#
# Bug #9029 Traditional: Wrong SQLSTATE returned for string truncation
#
create table t1 (charcol char(255), varcharcol varchar(255),
varbinarycol varbinary(255));
--error 1406
insert into t1 (charcol) values (repeat('x',256));
--error 1406
insert into t1 (varcharcol) values (repeat('x',256));
--error 1406
insert into t1 (varbinarycol) values (repeat('x',256));
select * from t1;
drop table t1;
#
# Check insert with wrong CAST() (Bug #5912)
#
create table t1 (col1 char(3), col2 integer);
--error 1292
insert into t1 (col1) values (cast(1000 as char(3)));
--error 1292
insert into t1 (col1) values (cast(1000E+0 as char(3)));
--error 1292
insert into t1 (col1) values (cast(1000.0 as char(3)));
--error 1292
insert into t1 (col2) values (cast('abc' as DECIMAL));
--error 1292
insert into t1 (col2) values (10E+0 + 'a');
--error 1265
insert into t1 (col2) values ('10a');
insert into t1 (col2) values (cast('10a' as DECIMAL));
insert into t1 (col2) values (cast('10' as DECIMAL));
insert into t1 (col2) values (cast('10' as DECIMAL));
insert into t1 (col2) values (10E+0 + '0 ');
select * from t1;
drop table t1;
# Test fields with no default value that are NOT NULL (Bug #5986)
CREATE TABLE t1 (i int not null);
--error 1364
INSERT INTO t1 VALUES ();
--error 1364
INSERT INTO t1 VALUES (DEFAULT);
--error 1364
INSERT INTO t1 VALUES (DEFAULT(i));
ALTER TABLE t1 ADD j int;
--error 1364
INSERT INTO t1 SET j = 1;
--error 1364
INSERT INTO t1 SET j = 1, i = DEFAULT;
--error 1364
INSERT INTO t1 SET j = 1, i = DEFAULT(i);
--error 1364
INSERT INTO t1 VALUES (DEFAULT,1);
DROP TABLE t1;
CREATE TABLE t1 (i int not null);
--error 1364
INSERT INTO t1 VALUES ();
--error 1364
INSERT INTO t1 VALUES (DEFAULT);
# DEFAULT(i) is an error even with the default sql_mode
--error 1364
INSERT INTO t1 VALUES (DEFAULT(i));
ALTER TABLE t1 ADD j int;
--error 1364
INSERT INTO t1 SET j = 1;
--error 1364
INSERT INTO t1 SET j = 1, i = DEFAULT;
--error 1364
INSERT INTO t1 SET j = 1, i = DEFAULT(i);
--error 1364
INSERT INTO t1 VALUES (DEFAULT,1);
DROP TABLE t1;
#
# Bugs #8295 and #8296: varchar and varbinary conversion
#
--error 1074
create table t1(a varchar(65537));
--error 1074
create table t1(a varbinary(65537));
#
# Bug #9881: problem with altering table
#
create table t1(a int, b date not null);
alter table t1 modify a bigint not null;
show create table t1;
drop table t1;
#
# Bug #11964: alter table with timestamp field
#
create table t1(a int, b timestamp);
alter table t1 add primary key(a);
show create table t1;
drop table t1;
create table t1(a int, b timestamp default 20050102030405);
alter table t1 add primary key(a);
show create table t1;
drop table t1;
#
# Bug#17626 CREATE TABLE ... SELECT failure with TRADITIONAL SQL mode
#
create table t1 (date date not null);
create table t2 select date from t1;
show create table t2;
drop table t2,t1;
create table t1 (i int)
comment '123456789*123456789*123456789*123456789*123456789*123456789*';
show create table t1;
drop table t1;
#
# Bug #26359: Strings becoming truncated and converted to numbers under STRICT mode
#
create table t1(col1 int, col2 int,
col3 int, col4 int,
col7 int, col8 int,
col9 bigint, col10 bigint);
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col1) values('-');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col2) values('+');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col3) values('-');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col4) values('+');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col7) values('-');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col8) values('+');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col9) values('-');
--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
insert into t1(col10) values('+');
drop table t1;
#
# Bug#27069 set with identical elements are created
#
--error 1291
create table t1 (f1 enum('a','a'));
--echo End of 5.0 tests
|