~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/null.test

  • Committer: Monty Taylor
  • Date: 2008-11-16 05:36:13 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116053613-bld4rqxhlkb49c02
Split out cache_row and type_holder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
# Testing of NULL in a lot of different places
8
8
#
9
9
 
10
 
--error ER_DIVISION_BY_ZERO
11
10
select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null;
12
 
--error ER_DIVISION_BY_ZERO
13
11
explain extended select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null;
14
 
select CONCAT(1, NULL),1+NULL,1-NULL;
15
 
select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,CONCAT(IFNULL(NULL,1), 0);
16
 
select strcmp("a",NULL),(1<NULL)+0.0,null like "a%","a%" like null;
 
12
select 1 | NULL,1 & NULL,1+NULL,1-NULL;
 
13
select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,IFNULL(NULL,1) | 0;
 
14
select strcmp("a",NULL),(1<NULL)+0.0,NULL regexp "a",null like "a%","a%" like null;
17
15
select concat("a",NULL),replace(NULL,"a","b"),replace("string","i",NULL),replace("string",NULL,"i"),insert("abc",1,1,NULL),left(NULL,1);
18
16
select repeat("a",0),repeat("ab",5+5),repeat("ab",-1),reverse(NULL);
19
17
select field(NULL,"a","b","c");
22
20
SELECT NULL AND NULL, 1 AND NULL, NULL AND 1, NULL OR NULL, 0 OR NULL, NULL OR 0;
23
21
SELECT (NULL OR NULL) IS NULL;
24
22
select NULL AND 0, 0 and NULL;
25
 
# @TODO Move to functions/inet_ntoa.test when INET_NTOA function is 
26
 
# implemented
27
 
# select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
28
 
# explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
 
23
select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
 
24
explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
29
25
 
30
26
create table t1 (x int);
31
27
insert into t1 values (null);
49
45
#
50
46
# Testing of IFNULL
51
47
#
52
 
create table t1 (a int, b int);
 
48
create table t1 (a int, b int) engine=myisam;
53
49
insert into t1 values(20,null);
54
50
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
55
51
t2.b=t3.a;
63
59
#
64
60
# Test inserting and updating with NULL
65
61
#
66
 
CREATE TABLE t1 (a varchar(16) NOT NULL default '', b int NOT NULL default 0, c datetime NOT NULL default '2009-02-10 00:00:00', d int NOT NULL default 0);
67
 
 
68
 
# Test INSERT with NULL
69
 
 
70
 
--error ER_BAD_NULL_ERROR
 
62
CREATE TABLE t1 (a varchar(16) NOT NULL default '', b int(6) NOT NULL default 0, c datetime NOT NULL default '0000-00-00 00:00:00', d int(6) NOT NULL default 0);
 
63
INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55";
 
64
--error 1048
 
65
UPDATE t1 SET d=1/NULL;
 
66
--error 1048
 
67
UPDATE t1 SET d=NULL;
 
68
--error 1048
71
69
INSERT INTO t1 (a) values (null);
72
 
--error ER_BAD_NULL_ERROR
 
70
--error 1048
73
71
INSERT INTO t1 (a) values (1/null);
74
 
--error ER_BAD_NULL_ERROR
75
72
INSERT INTO t1 (a) values (null),(null);
76
 
--error ER_BAD_NULL_ERROR
 
73
--error 1048
77
74
INSERT INTO t1 (b) values (null);
78
 
--error ER_BAD_NULL_ERROR
 
75
--error 1048
79
76
INSERT INTO t1 (b) values (1/null);
80
 
--error ER_BAD_NULL_ERROR
81
77
INSERT INTO t1 (b) values (null),(null);
82
 
--error ER_BAD_NULL_ERROR
 
78
--error 1048
83
79
INSERT INTO t1 (c) values (null);
84
 
--error ER_BAD_NULL_ERROR
 
80
--error 1048
85
81
INSERT INTO t1 (c) values (1/null);
86
 
--error ER_BAD_NULL_ERROR
87
82
INSERT INTO t1 (c) values (null),(null);
88
 
--error ER_BAD_NULL_ERROR
 
83
--error 1048
89
84
INSERT INTO t1 (d) values (null);
90
 
--error ER_BAD_NULL_ERROR
 
85
--error 1048
91
86
INSERT INTO t1 (d) values (1/null);
92
 
--error ER_BAD_NULL_ERROR
93
87
INSERT INTO t1 (d) values (null),(null);
94
 
 
95
 
# Test UPDATE with NULLs
96
 
 
97
 
# The following should not error since there 
98
 
# are no rows in the table.
99
 
UPDATE t1 SET d= NULL;
100
 
 
101
 
# Insert a default row in order to test UPDATE to NULL error
102
 
INSERT INTO t1 VALUES ();
103
 
 
104
 
--error ER_BAD_NULL_ERROR
105
 
UPDATE t1 SET a=1/NULL;
106
 
--error ER_BAD_NULL_ERROR
107
 
UPDATE t1 SET a=NULL;
108
 
--error ER_BAD_NULL_ERROR
109
 
UPDATE t1 SET b=NULL;
110
 
--error ER_BAD_NULL_ERROR
111
 
UPDATE t1 SET c=NULL;
112
 
--error ER_BAD_NULL_ERROR
113
 
UPDATE t1 SET d=NULL;
114
 
 
115
 
truncate table t1;
116
 
 
117
 
# Test for LOAD DATA INFILE and check for NULL handling
118
 
# Error produced should be 1263, which is almost the same
119
 
# as 1048, only gives a "row" number.
120
 
# @TODO Is there really a reason for a separate error 
121
 
# just for LOAD DATA INFILE?
122
 
--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
123
 
--error ER_WARN_NULL_TO_NOTNULL
124
 
eval LOAD DATA INFILE '$DRIZZLETEST_VARDIR/std_data_ln/null_test.txt' INTO TABLE t1 FIELDS ENCLOSED BY '"';
125
 
 
 
88
select * from t1;
126
89
drop table t1;
127
90
 
128
 
 
129
91
#
130
92
# Test to check elimination of IS NULL predicate for a non-nullable attribute
131
93
# (bug #1990)  
137
99
explain select * from t1 where a between 2 and 3;
138
100
explain select * from t1 where a between 2 and 3 or b is null;
139
101
drop table t1;
 
102
select cast(NULL as signed);
140
103
 
141
104
#
142
105
# IS NULL is unable to use index in range if column is declared not null
143
106
# (Bug #4256)
144
107
#
145
 
#create table t1(i int, key(i));
146
 
#insert into t1 values(1);
147
 
#insert into t1 select i*2 from t1;
148
 
#insert into t1 select i*2 from t1;
149
 
#insert into t1 select i*2 from t1;
150
 
#insert into t1 select i*2 from t1;
151
 
#insert into t1 select i*2 from t1;
152
 
#insert into t1 select i*2 from t1;
153
 
#insert into t1 select i*2 from t1;
154
 
#insert into t1 select i*2 from t1;
155
 
#insert into t1 select i*2 from t1;
156
 
#insert into t1 values(null);
157
 
#explain select * from t1 where i=2 or i is null;
158
 
#select count(*) from t1 where i=2 or i is null;
159
 
# @TODO Fails with error 1265 on line 128.  Bug?
160
 
#alter table t1 change i i int not null;
161
 
#explain select * from t1 where i=2 or i is null;
162
 
#select count(*) from t1 where i=2 or i is null;
163
 
#drop table t1;
 
108
create table t1(i int, key(i));
 
109
insert into t1 values(1);
 
110
insert into t1 select i*2 from t1;
 
111
insert into t1 select i*2 from t1;
 
112
insert into t1 select i*2 from t1;
 
113
insert into t1 select i*2 from t1;
 
114
insert into t1 select i*2 from t1;
 
115
insert into t1 select i*2 from t1;
 
116
insert into t1 select i*2 from t1;
 
117
insert into t1 select i*2 from t1;
 
118
insert into t1 select i*2 from t1;
 
119
insert into t1 values(null);
 
120
explain select * from t1 where i=2 or i is null;
 
121
select count(*) from t1 where i=2 or i is null;
 
122
alter table t1 change i i int not null;
 
123
explain select * from t1 where i=2 or i is null;
 
124
select count(*) from t1 where i=2 or i is null;
 
125
drop table t1;
164
126
 
165
127
#
166
128
# NULL has its own type BINARY(0) by default.
167
129
# But NULL should be weaker than a constant
168
130
# when mixing charsets/collations
169
131
#
 
132
set names latin2;
170
133
# Check that result type is taken from a non-null string
171
134
create table t1 select
172
135
  null as c00,
208
171
  lpad('str', 10, null) as c37,
209
172
  rpad(null, 10, 'str') as c38;
210
173
  
211
 
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
212
174
show create table t1;
213
175
drop table t1;
214
176
 
227
189
  'string' in ('STRING', null) as c08,
228
190
  'string' in (null, 'STRING') as c09;
229
191
 
 
192
# Restore charset to the default value.
 
193
set names latin1;
 
194
 
230
195
#
231
196
# Bug#19145: mysqld crashes if you set the default value of an enum field to NULL
232
197
#
233
 
#create table bug19145a (e enum('a','b','c')          default 'b' , s set('x', 'y', 'z')          default 'y' ) engine=MyISAM;
234
 
#create table bug19145b (e enum('a','b','c')          default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
235
 
 
236
 
#create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
237
 
 
238
 
# Invalid default value for 's'
239
 
#--error ER_INVALID_DEFAULT
240
 
#create table bug19145setnotnulldefaultnull (e enum('a','b','c')          default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
241
 
 
242
 
# Invalid default value for 'e'
243
 
#--error ER_INVALID_DEFAULT
244
 
#create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
245
 
 
246
 
#alter table bug19145a alter column e set default null;
247
 
#alter table bug19145a alter column s set default null;
248
 
#alter table bug19145a add column (i int);
249
 
 
250
 
#alter table bug19145b alter column e set default null;
251
 
#alter table bug19145b alter column s set default null;
252
 
#alter table bug19145b add column (i int);
253
 
 
254
 
# Invalid default value for 'e'
255
 
#--error ER_INVALID_DEFAULT
256
 
#alter table bug19145c alter column e set default null;
257
 
 
258
 
# Invalid default value for 's'
259
 
#--error ER_INVALID_DEFAULT
260
 
#alter table bug19145c alter column s set default null;
261
 
#alter table bug19145c add column (i int);
262
 
 
263
 
#show create table bug19145a;
264
 
#show create table bug19145b;
265
 
#show create table bug19145c;
266
 
 
267
 
#drop table bug19145a;
268
 
#drop table bug19145b;
269
 
#drop table bug19145c;
 
198
create table bug19145a (e enum('a','b','c')          default 'b' , s set('x', 'y', 'z')          default 'y' ) engine=MyISAM;
 
199
create table bug19145b (e enum('a','b','c')          default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
 
200
 
 
201
create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
 
202
 
 
203
# Invalid default value for 's'
 
204
--error 1067
 
205
create table bug19145setnotnulldefaultnull (e enum('a','b','c')          default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
 
206
 
 
207
# Invalid default value for 'e'
 
208
--error 1067
 
209
create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z')          default null) engine=MyISAM;
 
210
 
 
211
alter table bug19145a alter column e set default null;
 
212
alter table bug19145a alter column s set default null;
 
213
alter table bug19145a add column (i int);
 
214
 
 
215
alter table bug19145b alter column e set default null;
 
216
alter table bug19145b alter column s set default null;
 
217
alter table bug19145b add column (i int);
 
218
 
 
219
# Invalid default value for 'e'
 
220
--error 1067
 
221
alter table bug19145c alter column e set default null;
 
222
 
 
223
# Invalid default value for 's'
 
224
--error 1067
 
225
alter table bug19145c alter column s set default null;
 
226
alter table bug19145c add column (i int);
 
227
 
 
228
show create table bug19145a;
 
229
show create table bug19145b;
 
230
show create table bug19145c;
 
231
 
 
232
drop table bug19145a;
 
233
drop table bug19145b;
 
234
drop table bug19145c;
270
235
 
271
236
--echo # End of 4.1 tests
272
237
 
275
240
--echo #             precision > 0 && scale <= precision'
276
241
--echo #
277
242
 
278
 
CREATE TABLE t1 (a DECIMAL (1, 0) , b DECIMAL (1, 0) );
 
243
CREATE TABLE t1 (a DECIMAL (1, 0) ZEROFILL, b DECIMAL (1, 0) ZEROFILL);
279
244
INSERT INTO t1 (a, b) VALUES (0, 0);
280
245
 
281
246
CREATE TABLE t2 SELECT IFNULL(a, b) FROM t1;