1
by brian
clean slate |
1 |
# This script tests our own time zone support functions |
2 |
||
3 |
# Preparing playground |
|
4 |
--disable_warnings
|
|
5 |
drop table if exists t1, t2; |
|
6 |
drop function if exists f1; |
|
7 |
--enable_warnings
|
|
8 |
||
9 |
||
10 |
#
|
|
11 |
# Let us first check +HH:MM style timezones |
|
12 |
#
|
|
13 |
create table t1 (ts timestamp); |
|
14 |
||
15 |
set time_zone='+00:00'; |
|
16 |
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp()); |
|
17 |
insert into t1 (ts) values ('2003-03-30 02:30:00'); |
|
18 |
||
19 |
set time_zone='+10:30'; |
|
20 |
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp()); |
|
21 |
insert into t1 (ts) values ('2003-03-30 02:30:00'); |
|
22 |
||
23 |
set time_zone='-10:00'; |
|
24 |
select unix_timestamp(utc_timestamp())-unix_timestamp(current_timestamp()); |
|
25 |
insert into t1 (ts) values ('2003-03-30 02:30:00'); |
|
26 |
||
27 |
# Here we will get different results |
|
28 |
select * from t1; |
|
29 |
||
30 |
drop table t1; |
|
31 |
||
32 |
||
33 |
#
|
|
34 |
# Let us try DB specified time zones |
|
35 |
#
|
|
36 |
select Name from mysql.time_zone_name where Name in |
|
37 |
('UTC','Universal','MET','Europe/Moscow','leap/Europe/Moscow'); |
|
38 |
||
39 |
create table t1 (i int, ts timestamp); |
|
40 |
||
41 |
set time_zone='MET'; |
|
42 |
||
43 |
# We check common date time value and non existent or ambiguios values |
|
44 |
# Normal value without DST |
|
45 |
insert into t1 (i, ts) values |
|
46 |
(unix_timestamp('2003-03-01 00:00:00'),'2003-03-01 00:00:00'); |
|
47 |
# Values around and in spring time-gap |
|
48 |
insert into t1 (i, ts) values |
|
49 |
(unix_timestamp('2003-03-30 01:59:59'),'2003-03-30 01:59:59'), |
|
50 |
(unix_timestamp('2003-03-30 02:30:00'),'2003-03-30 02:30:00'), |
|
51 |
(unix_timestamp('2003-03-30 03:00:00'),'2003-03-30 03:00:00'); |
|
52 |
# Values around and in spring time-gap |
|
53 |
insert into t1 (i, ts) values |
|
54 |
(unix_timestamp(20030330015959),20030330015959), |
|
55 |
(unix_timestamp(20030330023000),20030330023000), |
|
56 |
(unix_timestamp(20030330030000),20030330030000); |
|
57 |
# Normal value with DST |
|
58 |
insert into t1 (i, ts) values |
|
59 |
(unix_timestamp('2003-05-01 00:00:00'),'2003-05-01 00:00:00'); |
|
60 |
# Ambiguos values (also check for determenism) |
|
61 |
insert into t1 (i, ts) values |
|
62 |
(unix_timestamp('2003-10-26 01:00:00'),'2003-10-26 01:00:00'), |
|
63 |
(unix_timestamp('2003-10-26 02:00:00'),'2003-10-26 02:00:00'), |
|
64 |
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'), |
|
65 |
(unix_timestamp('2003-10-26 04:00:00'),'2003-10-26 04:00:00'), |
|
66 |
(unix_timestamp('2003-10-26 02:59:59'),'2003-10-26 02:59:59'); |
|
67 |
||
68 |
set time_zone='UTC'; |
|
69 |
||
70 |
select * from t1; |
|
71 |
||
72 |
truncate table t1; |
|
73 |
||
74 |
# Simple check for 'Europe/Moscow' time zone just for showing that it works |
|
75 |
set time_zone='Europe/Moscow'; |
|
76 |
insert into t1 (i, ts) values |
|
77 |
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'), |
|
78 |
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'), |
|
79 |
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'), |
|
80 |
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00'); |
|
81 |
select * from t1; |
|
82 |
truncate table t1; |
|
83 |
||
84 |
||
85 |
#
|
|
86 |
# Check for time zone with leap seconds |
|
87 |
# Values in ts column must be the same but values in i column should |
|
88 |
# differ from corresponding values for Europe/Moscow a bit. |
|
89 |
#
|
|
90 |
set time_zone='leap/Europe/Moscow'; |
|
91 |
insert into t1 (i, ts) values |
|
92 |
(unix_timestamp('2004-01-01 00:00:00'),'2004-01-01 00:00:00'), |
|
93 |
(unix_timestamp('2004-03-28 02:30:00'),'2004-03-28 02:30:00'), |
|
94 |
(unix_timestamp('2004-08-01 00:00:00'),'2003-08-01 00:00:00'), |
|
95 |
(unix_timestamp('2004-10-31 02:30:00'),'2004-10-31 02:30:00'); |
|
96 |
select * from t1; |
|
97 |
truncate table t1; |
|
98 |
# Let us test leap jump |
|
99 |
insert into t1 (i, ts) values |
|
100 |
(unix_timestamp('1981-07-01 03:59:59'),'1981-07-01 03:59:59'), |
|
101 |
(unix_timestamp('1981-07-01 04:00:00'),'1981-07-01 04:00:00'); |
|
102 |
select * from t1; |
|
103 |
# Additional 60ieth second! |
|
104 |
select from_unixtime(362793609); |
|
105 |
||
106 |
drop table t1; |
|
107 |
||
108 |
||
109 |
#
|
|
110 |
# Let us test range for TIMESTAMP |
|
111 |
#
|
|
112 |
create table t1 (ts timestamp); |
|
113 |
set time_zone='UTC'; |
|
114 |
insert into t1 values ('0000-00-00 00:00:00'),('1969-12-31 23:59:59'), |
|
115 |
('1970-01-01 00:00:00'),('1970-01-01 00:00:01'), |
|
116 |
('2038-01-19 03:14:07'),('2038-01-19 03:14:08'); |
|
117 |
select * from t1; |
|
118 |
truncate table t1; |
|
119 |
# MET time zone has range shifted by one hour |
|
120 |
set time_zone='MET'; |
|
121 |
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 00:30:00'), |
|
122 |
('1970-01-01 01:00:00'),('1970-01-01 01:00:01'), |
|
123 |
('2038-01-19 04:14:07'),('2038-01-19 04:14:08'); |
|
124 |
select * from t1; |
|
125 |
truncate table t1; |
|
126 |
# same for +01:30 time zone |
|
127 |
set time_zone='+01:30'; |
|
128 |
insert into t1 values ('0000-00-00 00:00:00'),('1970-01-01 01:00:00'), |
|
129 |
('1970-01-01 01:30:00'),('1970-01-01 01:30:01'), |
|
130 |
('2038-01-19 04:44:07'),('2038-01-19 04:44:08'); |
|
131 |
select * from t1; |
|
132 |
||
133 |
drop table t1; |
|
134 |
||
135 |
||
136 |
#
|
|
137 |
# Test of show variables |
|
138 |
#
|
|
139 |
show variables like 'time_zone'; |
|
140 |
set time_zone = default; |
|
141 |
show variables like 'time_zone'; |
|
142 |
||
143 |
||
144 |
#
|
|
145 |
# Let us try some invalid time zone specifications |
|
146 |
#
|
|
147 |
--error 1298 |
|
148 |
set time_zone= '0'; |
|
149 |
--error 1298 |
|
150 |
set time_zone= '0:0'; |
|
151 |
--error 1298 |
|
152 |
set time_zone= '-20:00'; |
|
153 |
--error 1298 |
|
154 |
set time_zone= '+20:00'; |
|
155 |
--error 1298 |
|
156 |
set time_zone= 'Some/Unknown/Time/Zone'; |
|
157 |
||
158 |
||
159 |
# Let us check that aliases for time zones work and they are |
|
160 |
# case-insensitive |
|
161 |
select convert_tz(now(),'UTC', 'Universal') = now(); |
|
162 |
select convert_tz(now(),'utc', 'UTC') = now(); |
|
163 |
||
164 |
||
165 |
#
|
|
166 |
# Let us test CONVERT_TZ function (may be func_time.test is better place). |
|
167 |
#
|
|
168 |
select convert_tz('1917-11-07 12:00:00', 'MET', 'UTC'); |
|
169 |
select convert_tz('1970-01-01 01:00:00', 'MET', 'UTC'); |
|
170 |
select convert_tz('1970-01-01 01:00:01', 'MET', 'UTC'); |
|
171 |
select convert_tz('2003-03-01 00:00:00', 'MET', 'UTC'); |
|
172 |
select convert_tz('2003-03-30 01:59:59', 'MET', 'UTC'); |
|
173 |
select convert_tz('2003-03-30 02:30:00', 'MET', 'UTC'); |
|
174 |
select convert_tz('2003-03-30 03:00:00', 'MET', 'UTC'); |
|
175 |
select convert_tz('2003-05-01 00:00:00', 'MET', 'UTC'); |
|
176 |
select convert_tz('2003-10-26 01:00:00', 'MET', 'UTC'); |
|
177 |
select convert_tz('2003-10-26 02:00:00', 'MET', 'UTC'); |
|
178 |
select convert_tz('2003-10-26 02:59:59', 'MET', 'UTC'); |
|
179 |
select convert_tz('2003-10-26 04:00:00', 'MET', 'UTC'); |
|
180 |
select convert_tz('2038-01-19 04:14:07', 'MET', 'UTC'); |
|
181 |
select convert_tz('2038-01-19 04:14:08', 'MET', 'UTC'); |
|
182 |
select convert_tz('2103-01-01 04:00:00', 'MET', 'UTC'); |
|
183 |
||
184 |
# Let us test variable time zone argument |
|
185 |
create table t1 (tz varchar(3)); |
|
186 |
insert into t1 (tz) values ('MET'), ('UTC'); |
|
187 |
select tz, convert_tz('2003-12-31 00:00:00',tz,'UTC'), convert_tz('2003-12-31 00:00:00','UTC',tz) from t1 order by tz; |
|
188 |
drop table t1; |
|
189 |
||
190 |
# Parameters to CONVERT_TZ() what should give NULL |
|
191 |
select convert_tz('2003-12-31 04:00:00', NULL, 'UTC'); |
|
192 |
select convert_tz('2003-12-31 04:00:00', 'SomeNotExistingTimeZone', 'UTC'); |
|
193 |
select convert_tz('2003-12-31 04:00:00', 'MET', 'SomeNotExistingTimeZone'); |
|
194 |
select convert_tz('2003-12-31 04:00:00', 'MET', NULL); |
|
195 |
select convert_tz( NULL, 'MET', 'UTC'); |
|
196 |
||
197 |
#
|
|
198 |
# Test for bug #4508 "CONVERT_TZ() function with new time zone as param |
|
199 |
# crashes server." (Was caused by improperly worked mechanism of time zone |
|
200 |
# dynamical loading). |
|
201 |
#
|
|
202 |
create table t1 (ts timestamp); |
|
203 |
set timestamp=1000000000; |
|
204 |
insert into t1 (ts) values (now()); |
|
205 |
select convert_tz(ts, @@time_zone, 'Japan') from t1; |
|
206 |
drop table t1; |
|
207 |
||
208 |
#
|
|
209 |
# Test for bug #7705 "CONVERT_TZ() crashes with subquery/WHERE on index |
|
210 |
# column". Queries in which one of time zone arguments of CONVERT_TZ() is |
|
211 |
# determined as constant only at val() stage (not at fix_fields() stage), |
|
212 |
# should not crash server. |
|
213 |
#
|
|
214 |
select convert_tz('2005-01-14 17:00:00', 'UTC', custTimeZone) from (select 'UTC' as custTimeZone) as tmp; |
|
215 |
||
216 |
#
|
|
217 |
# Test for bug #7899 "CREATE TABLE .. SELECT .. and CONVERT_TZ() function |
|
218 |
# does not work well together". The following statement should return only |
|
219 |
# one NULL row and not result of full join. |
|
220 |
#
|
|
221 |
create table t1 select convert_tz(NULL, NULL, NULL); |
|
222 |
select * from t1; |
|
223 |
drop table t1; |
|
224 |
||
225 |
# End of 4.1 tests |
|
226 |
||
227 |
#
|
|
228 |
# Test for bug #11081 "Using a CONVERT_TZ function in a stored function |
|
229 |
# or trigger fails". |
|
230 |
#
|
|
231 |
SET GLOBAL log_bin_trust_function_creators = 1; |
|
232 |
||
233 |
create table t1 (ldt datetime, udt datetime); |
|
234 |
create function f1(i datetime) returns datetime |
|
235 |
return convert_tz(i, 'UTC', 'Europe/Moscow'); |
|
236 |
create trigger t1_bi before insert on t1 for each row |
|
237 |
set new.udt:= convert_tz(new.ldt, 'Europe/Moscow', 'UTC'); |
|
238 |
# This should work without errors |
|
239 |
insert into t1 (ldt) values ('2006-04-19 16:30:00'); |
|
240 |
select * from t1; |
|
241 |
# This should work without errors as well |
|
242 |
select ldt, f1(udt) as ldt2 from t1; |
|
243 |
drop table t1; |
|
244 |
drop function f1; |
|
245 |
||
246 |
SET GLOBAL log_bin_trust_function_creators = 0; |
|
247 |
||
248 |
# End of 5.0 tests |
|
249 |
||
250 |
||
251 |
#
|
|
252 |
# BUG#9953: CONVERT_TZ requires mysql.time_zone_name to be locked |
|
253 |
# BUG#19339: CONVERT_TZ(): overly aggressive in locking time_zone_name |
|
254 |
# table |
|
255 |
#
|
|
256 |
--disable_warnings
|
|
257 |
DROP TABLE IF EXISTS t1; |
|
258 |
--enable_warnings
|
|
259 |
||
260 |
CREATE TABLE t1 (t TIMESTAMP); |
|
261 |
INSERT INTO t1 VALUES (NULL), (NULL); |
|
262 |
||
263 |
LOCK TABLES t1 WRITE; |
|
264 |
||
265 |
# The following two queries should not return error that time zone |
|
266 |
# tables aren't locked. We use IS NULL below to supress timestamp |
|
267 |
# result.
|
|
268 |
SELECT CONVERT_TZ(NOW(), 'UTC', 'Europe/Moscow') IS NULL; |
|
269 |
UPDATE t1 SET t = CONVERT_TZ(t, 'UTC', 'Europe/Moscow'); |
|
270 |
||
271 |
UNLOCK TABLES; |
|
272 |
||
273 |
DROP TABLE t1; |
|
274 |
||
275 |
||
276 |
--echo End of 5.1 tests |