~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
--disable_warnings
2
drop table if exists t1, test;
3
--enable_warnings
4
5
6
#
7
# time functions
8
#
9
select extract(DAY_MICROSECOND FROM "1999-01-02 10:11:12.000123");
10
select extract(HOUR_MICROSECOND FROM "1999-01-02 10:11:12.000123");
11
select extract(MINUTE_MICROSECOND FROM "1999-01-02 10:11:12.000123");
12
select extract(SECOND_MICROSECOND FROM "1999-01-02 10:11:12.000123");
13
select extract(MICROSECOND FROM "1999-01-02 10:11:12.000123");
14
select date_format("1997-12-31 23:59:59.000002", "%f");
15
16
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000 99:99:99.999999" DAY_MICROSECOND);
17
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99:99.999999" HOUR_MICROSECOND);
18
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99.999999" MINUTE_MICROSECOND);
19
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000.999999" SECOND_MICROSECOND);
20
select date_add("1997-12-31 23:59:59.000002",INTERVAL "999999" MICROSECOND);
21
22
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1 1:1:1.000002" DAY_MICROSECOND);
23
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1:1.000002" HOUR_MICROSECOND);
24
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1.000002" MINUTE_MICROSECOND);
25
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1.000002" SECOND_MICROSECOND);
26
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "000002" MICROSECOND);
27
28
#Date functions
29
select adddate("1997-12-31 23:59:59.000001", 10);
30
select subdate("1997-12-31 23:59:59.000001", 10);
31
32
select datediff("1997-12-31 23:59:59.000001","1997-12-30");
33
select datediff("1997-11-30 23:59:59.000001","1997-12-31");
34
SET @@SQL_MODE="ALLOW_INVALID_DATES";
35
select datediff("1997-11-31 23:59:59.000001","1997-12-31");
36
SET @@SQL_MODE="";
37
38
# This will give a warning
39
select datediff("1997-11-31 23:59:59.000001","1997-12-31");
40
select datediff("1997-11-30 23:59:59.000001",null);
41
42
select weekofyear("1997-11-30 23:59:59.000001");
43
44
select makedate(03,1);
45
select makedate('0003',1);
46
select makedate(1997,1);
47
select makedate(1997,0);
48
select makedate(9999,365);
49
select makedate(9999,366);
50
select makedate(100,1);
51
52
#Time functions
53
54
select addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002");
55
select subtime("1997-12-31 23:59:59.000001", "1 1:1:1.000002");
56
select addtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
57
select subtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
58
select subtime("01:00:00.999999", "02:00:00.999998");
59
select subtime("02:01:01.999999", "01:01:01.999999");
60
61
# PS doesn't support fractional seconds
62
--disable_ps_protocol
63
select timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002");
64
select timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002");
65
select timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002");
66
select timediff("1997-12-31 23:59:59.000001","23:59:59.000001");
67
select timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.000001");
68
select timediff("2005-01-11 15:48:49.999999", "2005-01-11 15:48:50");
69
--enable_ps_protocol
70
71
select maketime(10,11,12);
72
select maketime(25,11,12);
73
select maketime(-25,11,12);
74
75
# Extraction functions
76
77
# PS doesn't support fractional seconds
78
--disable_ps_protocol
79
select timestamp("2001-12-01", "01:01:01.999999");
80
select timestamp("2001-13-01", "01:01:01.000001");
81
select timestamp("2001-12-01", "25:01:01");
82
select timestamp("2001-12-01 01:01:01.000100");
83
select timestamp("2001-12-01");
84
select day("1997-12-31 23:59:59.000001");
85
select date("1997-12-31 23:59:59.000001");
86
select date("1997-13-31 23:59:59.000001");
87
select time("1997-12-31 23:59:59.000001");
88
select time("1997-12-31 25:59:59.000001");
89
select microsecond("1997-12-31 23:59:59.000001");
90
--enable_ps_protocol
91
92
create table t1 
93
select makedate(1997,1) as f1,
94
   addtime(cast("1997-12-31 23:59:59.000001" as datetime), "1 1:1:1.000002") as f2,
95
   addtime(cast("23:59:59.999999" as time) , "1 1:1:1.000002") as f3,
96
   timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002") as f4,
97
   timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002") as f5,
98
   maketime(10,11,12) as f6,
99
   timestamp(cast("2001-12-01" as date), "01:01:01") as f7,
100
   date("1997-12-31 23:59:59.000001") as f8,
101
   time("1997-12-31 23:59:59.000001") as f9;
102
describe t1;
103
# PS doesn't support fractional seconds
104
--disable_ps_protocol
105
select * from t1;
106
--enable_ps_protocol
107
108
create table test(t1 datetime, t2 time, t3 time, t4 datetime);
109
insert into test values 
110
('2001-01-01 01:01:01', '01:01:01', null, '2001-02-01 01:01:01'),
111
('2001-01-01 01:01:01', '-01:01:01', '-23:59:59', "1997-12-31 23:59:59.000001"),
112
('1997-12-31 23:59:59.000001', '-23:59:59', '-01:01:01', '2001-01-01 01:01:01'),
113
('2001-01-01 01:01:01', '01:01:01', '-1 01:01:01', null),
114
('2001-01-01 01:01:01', '-01:01:01', '1 01:01:01', '2001-01-01 01:01:01'),
115
('2001-01-01 01:01:01', null, '-1 01:01:01', null),
116
(null, null, null, null),
117
('2001-01-01 01:01:01', '01:01:01', '1 01:01:01', '2001-01-01 01:01:01');
118
119
SELECT ADDTIME(t1,t2) As ttt, ADDTIME(t2, t3) As qqq from test;
120
# PS doesn't support fractional seconds
121
--disable_ps_protocol
122
SELECT TIMEDIFF(t1, t4) As ttt, TIMEDIFF(t2, t3) As qqq,
123
       TIMEDIFF(t3, t2) As eee, TIMEDIFF(t2, t4) As rrr from test;
124
--enable_ps_protocol
125
126
drop table t1, test;
127
128
select addtime("-01:01:01.01", "-23:59:59.1") as a;
129
select microsecond("1997-12-31 23:59:59.01") as a;
130
select microsecond(19971231235959.01) as a;
131
select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a;
132
# PS doesn't support fractional seconds
133
--disable_ps_protocol
134
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f");
135
--enable_ps_protocol
136
137
# End of 4.1 tests