~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/t/type_date.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# test of problem with date fields
 
3
#
 
4
--disable_warnings
 
5
drop table if exists t1,t2;
 
6
--enable_warnings
 
7
 
 
8
create table t1 (a char(16), b date, c datetime);
 
9
insert into t1 SET a='test 2000-01-01', b='2000-01-01', c='2000-01-01';
 
10
select * from t1 where c = '2000-01-01';
 
11
select * from t1 where b = '2000-01-01';
 
12
drop table t1;
 
13
 
 
14
#
 
15
# problem with date conversions
 
16
#
 
17
 
 
18
CREATE TABLE t1 (name char(6),cdate date);
 
19
INSERT INTO t1 VALUES ('name1','1998-01-01');
 
20
INSERT INTO t1 VALUES ('name2','1998-01-01');
 
21
INSERT INTO t1 VALUES ('name1','1998-01-02');
 
22
INSERT INTO t1 VALUES ('name2','1998-01-02');
 
23
CREATE TABLE t2 (cdate date, note char(6));
 
24
INSERT INTO t2 VALUES ('1998-01-01','note01');
 
25
INSERT INTO t2 VALUES ('1998-01-02','note02');
 
26
select name,t1.cdate,note from t1,t2 where t1.cdate=t2.cdate and t1.cdate='1998-01-01';
 
27
drop table t1,t2;
 
28
 
 
29
#
 
30
# Date and BETWEEN
 
31
#
 
32
 
 
33
CREATE TABLE t1 ( datum DATE );
 
34
INSERT INTO t1 VALUES ( "2000-1-1" );
 
35
INSERT INTO t1 VALUES ( "2000-1-2" );
 
36
INSERT INTO t1 VALUES ( "2000-1-3" );
 
37
INSERT INTO t1 VALUES ( "2000-1-4" );
 
38
INSERT INTO t1 VALUES ( "2000-1-5" );
 
39
SELECT * FROM t1 WHERE datum BETWEEN cast("2000-1-2" as date) AND cast("2000-1-4" as date);
 
40
SELECT * FROM t1 WHERE datum BETWEEN cast("2000-1-2" as date) AND datum - INTERVAL 100 DAY;
 
41
DROP TABLE t1;
 
42
 
 
43
#
 
44
# test of max(date) and having
 
45
#
 
46
 
 
47
CREATE TABLE t1 (
 
48
  user_id char(10),
 
49
  summa int(11),
 
50
  rdate date
 
51
);
 
52
INSERT INTO t1 VALUES ('aaa',100,'1998-01-01');
 
53
INSERT INTO t1 VALUES ('aaa',200,'1998-01-03');
 
54
INSERT INTO t1 VALUES ('bbb',50,'1998-01-02');
 
55
INSERT INTO t1 VALUES ('bbb',200,'1998-01-04');
 
56
select max(rdate) as s from t1 where rdate < '1998-01-03' having s> "1998-01-01";
 
57
select max(rdate) as s from t1 having s="1998-01-04";
 
58
select max(rdate+0) as s from t1 having s="19980104";
 
59
drop table t1;
 
60
 
 
61
#
 
62
# Test of date and not null
 
63
#
 
64
 
 
65
create table t1 (date date);  
 
66
insert into t1 values ("2000-08-10"),("2000-08-11");
 
67
select date_add(date,INTERVAL 1 DAY),date_add(date,INTERVAL 1 SECOND) from t1;
 
68
drop table t1;
 
69
 
 
70
#
 
71
# Test problem with DATE_FORMAT
 
72
#
 
73
 
 
74
CREATE TABLE t1(AFIELD INT);
 
75
INSERT INTO t1 VALUES(1);
 
76
CREATE TABLE t2(GMT  VARCHAR(32));
 
77
INSERT INTO t2 VALUES('GMT-0800');
 
78
SELECT DATE_FORMAT("2002-03-06 10:11:12", CONCAT('%a, %d %M %Y %H:%i:%s ' ,  t2.GMT)) FROM t1, t2 GROUP BY t1.AFIELD;
 
79
INSERT INTO t1 VALUES(1);
 
80
SELECT DATE_FORMAT("2002-03-06 10:11:12", CONCAT('%a, %d %M %Y %H:%i:%s ' ,  t2.GMT)), DATE_FORMAT("2002-03-06 10:11:12",  CONCAT('%a, %d %M %Y %H:%i:%s ' ,  t2.GMT)) FROM t1,t2 GROUP BY t1.AFIELD;
 
81
drop table t1,t2;
 
82
 
 
83
#
 
84
# Multiple SELECT DATE_FORMAT gave incorrect results (Bug #4036)
 
85
#
 
86
 
 
87
CREATE TABLE t1 (f1 time default NULL, f2 time default NULL);
 
88
INSERT INTO t1 (f1, f2) VALUES ('09:00', '12:00');
 
89
SELECT DATE_FORMAT(f1, "%l.%i %p") , DATE_FORMAT(f2, "%l.%i %p") FROM t1;
 
90
DROP TABLE t1;
 
91
 
 
92
#
 
93
# Bug 4937: different date -> string conversion when using SELECT ... UNION
 
94
# and INSERT ... SELECT ... UNION
 
95
#
 
96
 
 
97
CREATE TABLE t1 (f1 DATE);
 
98
CREATE TABLE t2 (f2 VARCHAR(8));
 
99
CREATE TABLE t3 (f2 CHAR(8));
 
100
 
 
101
INSERT INTO t1 VALUES ('1978-11-26');
 
102
INSERT INTO t2 SELECT f1+0 FROM t1;
 
103
INSERT INTO t2 SELECT f1+0 FROM t1 UNION SELECT f1+0 FROM t1;
 
104
INSERT INTO t3 SELECT f1+0 FROM t1;
 
105
INSERT INTO t3 SELECT f1+0 FROM t1 UNION SELECT f1+0 FROM t1;
 
106
SELECT * FROM t2;
 
107
SELECT * FROM t3;
 
108
 
 
109
DROP TABLE t1, t2, t3;
 
110
 
 
111
# Test that setting YEAR to invalid string results in default value, not
 
112
# 2000. (Bug #6067)
 
113
CREATE TABLE t1 (y YEAR);
 
114
INSERT INTO t1 VALUES ('abc');
 
115
SELECT * FROM t1;
 
116
DROP TABLE t1;
 
117
 
 
118
#
 
119
# Bug#21677: Wrong result when comparing a DATE and a DATETIME in BETWEEN
 
120
#
 
121
create table t1(start_date date, end_date date);
 
122
insert into t1 values ('2000-01-01','2000-01-02');
 
123
select 1 from t1 where cast('2000-01-01 12:01:01' as datetime) between start_date and end_date;
 
124
drop table t1;
 
125
# End of 4.1 tests
 
126
 
 
127
#
 
128
# Bug #23093: Implicit conversion of 9912101 to date does not match
 
129
# cast(9912101 as date)
 
130
#
 
131
select @d:=1111;
 
132
select year(@d), month(@d), day(@d), cast(@d as date);
 
133
select @d:=011111;
 
134
select year(@d), month(@d), day(@d), cast(@d as date);
 
135
select @d:=1311;
 
136
select year(@d), month(@d), day(@d), cast(@d as date);
 
137
create table t1 (d  date , dt datetime , ts timestamp);
 
138
insert into t1 values (9912101,9912101,9912101);
 
139
insert into t1 values (11111,11111,11111);
 
140
select * from t1;
 
141
drop table t1;
 
142
 
 
143
#
 
144
# Bug #30942: select str_to_date from derived table returns varying results
 
145
#
 
146
CREATE TABLE t1 (
 
147
  a INT
 
148
);
 
149
 
 
150
INSERT INTO t1 VALUES (1);
 
151
INSERT INTO t1 VALUES (NULL);
 
152
 
 
153
SELECT str_to_date( '', a ) FROM t1;
 
154
DROP TABLE t1;
 
155
 
 
156
 
 
157
#
 
158
# Bug #31221: Optimizer incorrectly identifies impossible WHERE clause
 
159
#
 
160
 
 
161
CREATE TABLE t1 (a DATE, b int, PRIMARY KEY (a,b));
 
162
INSERT INTO t1 VALUES (DATE(NOW()), 1);
 
163
SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
164
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
165
INSERT INTO t1 VALUES (DATE(NOW()), 2);
 
166
SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
167
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
168
SELECT COUNT(*) FROM t1 WHERE a = NOW() AND b = 1;
 
169
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW() AND b = 1;
 
170
ALTER TABLE t1 DROP PRIMARY KEY;
 
171
SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
172
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
173
 
 
174
DROP TABLE t1;
 
175
 
 
176
#
 
177
# Bug #28687: Search fails on '0000-00-00' date after sql_mode change
 
178
#
 
179
 
 
180
CREATE TABLE t1 (a DATE);
 
181
CREATE TABLE t2 (a DATE);
 
182
CREATE INDEX i ON t1 (a);
 
183
INSERT INTO t1 VALUES ('0000-00-00'),('0000-00-00');
 
184
INSERT INTO t2 VALUES ('0000-00-00'),('0000-00-00');
 
185
SELECT * FROM t1 WHERE a = '0000-00-00';
 
186
SELECT * FROM t2 WHERE a = '0000-00-00';
 
187
SET SQL_MODE=TRADITIONAL;
 
188
EXPLAIN SELECT * FROM t1 WHERE a = '0000-00-00';
 
189
SELECT * FROM t1 WHERE a = '0000-00-00';
 
190
SELECT * FROM t2 WHERE a = '0000-00-00';
 
191
--error ER_TRUNCATED_WRONG_VALUE
 
192
INSERT INTO t1 VALUES ('0000-00-00');
 
193
SET SQL_MODE=DEFAULT;
 
194
DROP TABLE t1,t2;
 
195
 
 
196
#
 
197
# Bug #31928: Search fails on '1000-00-00' date after sql_mode change
 
198
#
 
199
 
 
200
CREATE TABLE t1 (a DATE);
 
201
CREATE TABLE t2 (a DATE);
 
202
CREATE INDEX i ON t1 (a);
 
203
INSERT INTO t1 VALUES ('1000-00-00'),('1000-00-00');
 
204
INSERT INTO t2 VALUES ('1000-00-00'),('1000-00-00');
 
205
SELECT * FROM t1 WHERE a = '1000-00-00';
 
206
SELECT * FROM t2 WHERE a = '1000-00-00';
 
207
SET SQL_MODE=TRADITIONAL;
 
208
EXPLAIN SELECT * FROM t1 WHERE a = '1000-00-00';
 
209
SELECT * FROM t1 WHERE a = '1000-00-00';
 
210
SELECT * FROM t2 WHERE a = '1000-00-00';
 
211
--error ER_TRUNCATED_WRONG_VALUE
 
212
INSERT INTO t1 VALUES ('1000-00-00');
 
213
SET SQL_MODE=DEFAULT;
 
214
DROP TABLE t1,t2;
 
215
 
 
216
#
 
217
# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE
 
218
#
 
219
 
 
220
CREATE TABLE t1 SELECT curdate() AS f1;
 
221
SELECT hour(f1), minute(f1), second(f1) FROM t1;
 
222
DROP TABLE t1;
 
223
 
 
224
--echo End of 5.0 tests
 
225
 
 
226
#
 
227
# Bug#32021: Using Date 000-00-01 in WHERE causes wrong result
 
228
#
 
229
create table t1 (a date, primary key (a))engine=memory;
 
230
insert into t1 values ('0000-01-01'), ('0000-00-01'), ('0001-01-01');
 
231
select * from t1 where a between '0000-00-01' and '0000-00-02';
 
232
drop table t1;
 
233
 
 
234
--echo End of 5.1 tests