~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/t/type_date.test

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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,
 
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
# Bug 4937: different date -> string conversion when using SELECT ... UNION
 
85
# and INSERT ... SELECT ... UNION
 
86
#
 
87
 
 
88
CREATE TABLE t1 (f1 DATE);
 
89
CREATE TABLE t2 (f2 VARCHAR(8));
 
90
CREATE TABLE t3 (f2 CHAR(8));
 
91
 
 
92
INSERT INTO t1 VALUES ('1978-11-26');
 
93
INSERT INTO t2 SELECT f1+0 FROM t1;
 
94
INSERT INTO t2 SELECT f1+0 FROM t1 UNION SELECT f1+0 FROM t1;
 
95
INSERT INTO t3 SELECT f1+0 FROM t1;
 
96
INSERT INTO t3 SELECT f1+0 FROM t1 UNION SELECT f1+0 FROM t1;
 
97
SELECT * FROM t2;
 
98
SELECT * FROM t3;
 
99
 
 
100
DROP TABLE t1, t2, t3;
 
101
 
 
102
#
 
103
# Bug#21677: Wrong result when comparing a DATE and a DATETIME in BETWEEN
 
104
#
 
105
create table t1(start_date date, end_date date);
 
106
insert into t1 values ('2000-01-01','2000-01-02');
 
107
select 1 from t1 where cast('2000-01-01 12:01:01' as datetime) between start_date and end_date;
 
108
drop table t1;
 
109
# End of 4.1 tests
 
110
 
 
111
#
 
112
# Bug #23093: Implicit conversion of 9912101 to date does not match
 
113
# cast(9912101 as date)
 
114
#
 
115
select @d:=1111;
 
116
select year(@d), month(@d), day(@d), cast(@d as date);
 
117
select @d:=011111;
 
118
select year(@d), month(@d), day(@d), cast(@d as date);
 
119
select @d:=1311;
 
120
--error 1686 # Invalid datetime of 1311
 
121
select year(@d), month(@d), day(@d), cast(@d as date);
 
122
create table t1 (d  date , dt datetime , ts timestamp);
 
123
-- error 1686 # Bad dates
 
124
insert into t1 values (9912101,9912101,9912101);
 
125
insert into t1 values (11111,11111,11111);
 
126
select * from t1;
 
127
drop table t1;
 
128
 
 
129
#
 
130
# Bug #31221: Optimizer incorrectly identifies impossible WHERE clause
 
131
#
 
132
 
 
133
CREATE TABLE t1 (a DATE, b int, PRIMARY KEY (a,b));
 
134
INSERT INTO t1 VALUES (DATE(NOW()), 1);
 
135
SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
136
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
137
INSERT INTO t1 VALUES (DATE(NOW()), 2);
 
138
SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
139
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
140
SELECT COUNT(*) FROM t1 WHERE a = NOW() AND b = 1;
 
141
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW() AND b = 1;
 
142
# This bombs for some reason...commenting out for now.
 
143
# JRP - 2009-02-10
 
144
# ALTER TABLE t1 DROP PRIMARY KEY;
 
145
#SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
146
#EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
 
147
 
 
148
DROP TABLE t1;
 
149
 
 
150
#
 
151
# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE
 
152
#
 
153
 
 
154
CREATE TABLE t1 SELECT curdate() AS f1;
 
155
SELECT hour(f1), minute(f1), second(f1) FROM t1;
 
156
DROP TABLE t1;
 
157
 
 
158
--echo End of 5.0 tests