~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of date format functions
3
#
4
5
--disable_warnings
6
drop table if exists t1;
7
--enable_warnings
8
9
--replace_result ROW <format> STATEMENT <format> MIXED <format>
10
SHOW GLOBAL VARIABLES LIKE "%e_format";
11
--replace_result ROW <format> STATEMENT <format> MIXED <format>
12
SHOW SESSION VARIABLES LIKE "%e_format";
13
14
#
15
# Test setting a lot of different formats to see which formats are accepted and
16
# which aren't
17
#
18
19
SET time_format='%H%i%s';
20
SET time_format='%H:%i:%s.%f';
21
SET time_format='%h-%i-%s.%f%p';
22
SET time_format='%h:%i:%s.%f %p';
23
SET time_format='%h:%i:%s%p';
24
25
SET date_format='%Y%m%d';
26
SET date_format='%Y.%m.%d';
27
SET date_format='%d.%m.%Y';
28
SET date_format='%m-%d-%Y';
29
30
set datetime_format= '%Y%m%d%H%i%s';
31
set datetime_format= '%Y-%m-%d %H:%i:%s';
32
set datetime_format= '%m-%d-%y %H:%i:%s.%f';
33
set datetime_format= '%d-%m-%Y %h:%i:%s%p';
34
set datetime_format= '%H:%i:%s %Y-%m-%d';
35
set datetime_format= '%H:%i:%s.%f %m-%d-%Y';
36
set datetime_format= '%h:%i:%s %p %Y-%m-%d';
37
set datetime_format= '%h:%i:%s.%f %p %Y-%m-%d';
38
39
--replace_result ROW <format> STATEMENT <format> MIXED <format>
40
SHOW SESSION VARIABLES LIKE "%e_format";
41
42
--error 1231
43
SET time_format='%h:%i:%s';
44
--error 1231
45
SET time_format='%H %i:%s';
46
--error 1231
47
SET time_format='%H::%i:%s';
48
--error 1231
49
SET time_format='%H:%i:%s%f';
50
--error 1231
51
SET time_format='%H:%i.%f:%s';
52
--error 1231
53
SET time_format='%H:%i:%s%p';
54
--error 1231
55
SET time_format='%h:%i:%s.%f %p %Y-%m-%d';
56
--error 1231
57
SET time_format='%H%i%s.%f';
58
--error 1231
59
SET time_format='%H:%i-%s.%f';
60
--error 1231
61
SET date_format='%d.%m.%d';
62
--error 1231
63
SET datetime_format='%h.%m.%y %d.%i.%s';
64
--error 1231
65
set datetime_format= '%H:%i:%s.%f %p %Y-%m-%d';
66
67
#
68
# Test GLOBAL values
69
70
set GLOBAL datetime_format= '%H:%i:%s %Y-%m-%d';
71
SET SESSION datetime_format=default;
72
select @@global.datetime_format, @@session.datetime_format;
73
SET GLOBAL datetime_format=default;
74
SET SESSION datetime_format=default;
75
select @@global.datetime_format, @@session.datetime_format;
76
77
SET GLOBAL date_format=default;
78
SET GLOBAL time_format=default;
79
SET GLOBAL datetime_format=default;
80
SET time_format=default;
81
SET date_format=default;
82
SET datetime_format=default;
83
84
#
85
# The following tests will work only when we at some point will enable
86
# dynamic changing of formats
87
#
88
89
# SET date_format='%d.%m.%Y';
90
# select CAST('01.01.2001' as DATE) as a;
91
# SET datetime_format='%d.%m.%Y %H.%i.%s';
92
# select CAST('01.01.2001 05.12.06' as DATETIME) as a;
93
# SET time_format='%H.%i.%s';
94
# select CAST('05.12.06' as TIME) as a;
95
# 
96
# SET datetime_format='%d.%m.%Y %h:%i:%s %p';
97
# select CAST('01.01.2001 05:12:06AM' as DATETIME) as a;
98
# select CAST('01.01.2001 05:12:06 PM' as DATETIME) as a;
99
# 
100
# SET time_format='%h:%i:%s %p';
101
# select CAST('05:12:06 AM' as TIME) as a;
102
# select CAST('05:12:06.1234PM' as TIME) as a;
103
# 
104
# SET time_format='%h.%i.%s %p';
105
# SET date_format='%d.%m.%y';
106
# SET datetime_format='%d.%m.%y %h.%i.%s %p';
107
# select CAST('12-12-06' as DATE) as a;
108
# 
109
# select adddate('01.01.97 11.59.59.000001 PM', 10);
110
# select datediff('31.12.97 11.59:59.000001 PM','01.01.98');
111
# select weekofyear('31.11.97 11:59:59.000001 PM');
112
# select makedate(1997,1);
113
# select addtime('31.12.97 11.59.59.999999 PM', '1 1.1.1.000002');
114
# select maketime(23,11,12);
115
# select timediff('01.01.97 11:59:59.000001 PM','31.12.95 11:59:59.000002 PM');
116
# 
117
# SET time_format='%i:%s:%H';
118
# select cast(str_to_date('15-01-2001 12:59:59', '%d-%m-%Y %H:%i:%S') as TIME);
119
120
#
121
# Test of str_to_date
122
#
123
124
# PS doesn't support fraction of a seconds
125
--disable_ps_protocol
126
select str_to_date(concat('15-01-2001',' 2:59:58.999'),
127
	           concat('%d-%m-%Y',' ','%H:%i:%s.%f'));
128
select STR_TO_DATE('2004.12.12 22.30.61','%Y.%m.%d %T');
129
--enable_ps_protocol
130
131
create table t1 (date char(30), format char(30) not null);
132
insert into t1 values
133
('2003-01-02 10:11:12', '%Y-%m-%d %H:%i:%S'),
134
('03-01-02 8:11:2.123456', '%y-%m-%d %H:%i:%S.%#'),
135
('0003-01-02 8:11:2.123456', '%Y-%m-%d %H:%i:%S.%#'),
136
('03-01-02 8:11:2.123456',   '%Y-%m-%d %H:%i:%S.%#'),
137
('2003-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p'),
138
('2003-01-02 01:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f%p'),
139
('2003-01-02 02:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f %p'),
140
('2003-01-02 12:11:12.12345 am', '%Y-%m-%d %h:%i:%S.%f%p'),
141
('2003-01-02 11:11:12Pm', '%Y-%m-%d %h:%i:%S%p'),
142
('10:20:10', '%H:%i:%s'),
143
('10:20:10', '%h:%i:%s.%f'),
144
('10:20:10', '%T'),
145
('10:20:10AM', '%h:%i:%s%p'),
146
('10:20:10AM', '%r'),
147
('10:20:10.44AM', '%h:%i:%s.%f%p'),
148
('15-01-2001 12:59:58', '%d-%m-%Y %H:%i:%S'),
149
('15 September 2001', '%d %M %Y'),
150
('15 SEPTEMB 2001', '%d %M %Y'),
151
('15 MAY 2001', '%d %b %Y'),
152
('15th May 2001', '%D %b %Y'),
153
('Sunday 15 MAY 2001', '%W %d %b %Y'),
154
('Sund 15 MAY 2001', '%W %d %b %Y'),
155
('Tuesday 00 2002', '%W %U %Y'),
156
('Thursday 53 1998', '%W %u %Y'),
157
('Sunday 01 2001', '%W %v %x'),
158
('Tuesday 52 2001', '%W %V %X'),
159
('060 2004', '%j %Y'),
160
('4 53 1998', '%w %u %Y'),
161
('15-01-2001', '%d-%m-%Y %H:%i:%S'),
162
('15-01-20', '%d-%m-%y'),
163
('15-2001-1', '%d-%Y-%c');
164
165
# PS doesn't support fractional seconds
166
--disable_ps_protocol
167
select date,format,str_to_date(date, format) as str_to_date from t1;
168
# Use as a string
169
select date,format,concat('',str_to_date(date, format)) as con from t1;
170
# Use as datetime
171
select date,format,cast(str_to_date(date, format) as datetime) as datetime from t1;
172
select date,format,DATE(str_to_date(date, format)) as date2 from t1;
173
select date,format,TIME(str_to_date(date, format)) as time from t1;
174
select date,format,concat(TIME(str_to_date(date, format))) as time2 from t1;
175
# Test small bug in %f handling
176
select concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d'));
177
178
# Test wrong dates or converion specifiers
179
180
truncate table t1;
181
insert into t1 values
182
('2003-01-02 10:11:12 PM', '%Y-%m-%d %H:%i:%S %p'),
183
('2003-01-02 10:11:12.123456', '%Y-%m-%d %h:%i:%S %p'),
184
('2003-01-02 10:11:12AM', '%Y-%m-%d %h:%i:%S.%f %p'),
185
('2003-01-02 10:11:12AN', '%Y-%m-%d %h:%i:%S%p'),
186
('2003-01-02 10:11:12 PM', '%y-%m-%d %H:%i:%S %p'),
187
('10:20:10AM', '%H:%i:%s%p'),
188
('15 Septembei 2001', '%d %M %Y'),
189
('15 Ju 2001', '%d %M %Y'),
190
('Sund 15 MA', '%W %d %b %Y'),
191
('Thursdai 12 1998', '%W %u %Y'),
192
('Sunday 01 2001', '%W %v %X'),
193
('Tuesday 52 2001', '%W %V %x'),
194
('Tuesday 52 2001', '%W %V %Y'),
195
('Tuesday 52 2001', '%W %u %x'),
196
('7 53 1998', '%w %u %Y'),
197
(NULL, get_format(DATE,'USA'));
198
select date,format,str_to_date(date, format) as str_to_date from t1;
199
select date,format,concat(str_to_date(date, format),'') as con from t1;
200
201
# Test 'maybe' date formats and 'strange but correct' results
202
203
truncate table t1;
204
insert into t1 values
205
('10:20:10AM', '%h:%i:%s'),
206
('2003-01-02 10:11:12', '%Y-%m-%d %h:%i:%S'),
207
('03-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p');
208
209
select date,format,str_to_date(date, format) as str_to_date from t1;
210
select date,format,concat(str_to_date(date, format),'') as con from t1;
211
212
drop table t1;
213
--enable_ps_protocol
214
215
#
216
# Test of get_format
217
#
218
219
select get_format(DATE, 'USA') as a;
220
select get_format(TIME, 'internal') as a;
221
select get_format(DATETIME, 'eur') as a;
222
select get_format(TIMESTAMP, 'eur') as a;
223
select get_format(DATE, 'TEST') as a;
224
select str_to_date('15-01-2001 12:59:59', GET_FORMAT(DATE,'USA'));
225
226
explain extended select makedate(1997,1), addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM"),cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME), maketime(23,11,12),microsecond("1997-12-31 23:59:59.000001");
227
228
#
229
# Test of date_format()
230
#
231
232
create table t1 (d date);
233
insert into t1 values ('2004-07-14'),('2005-07-14');
234
select date_format(d,"%d") from t1 order by 1;
235
drop table t1;
236
237
# PS doesn't support fractional seconds
238
--disable_ps_protocol
239
select str_to_date("2003-....01ABCD-02 10:11:12.0012", "%Y-%.%m%@-%d %H:%i:%S.%f") as a;
240
241
242
create table t1 select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
243
			str_to_date("10:11:12.0012", "%H:%i:%S.%f") as f2,
244
			str_to_date("2003-01-02", "%Y-%m-%d") as f3,
245
			str_to_date("02", "%d") as f4, str_to_date("02 10", "%d %H") as f5;
246
describe t1;
247
select * from t1;
248
drop table t1;
249
250
create table t1 select "02 10" as a, "%d %H" as b;
251
select str_to_date(a,b) from t1;
252
create table t2 select str_to_date(a,b) from t1;
253
describe t2;
254
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
255
       str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2,
256
       str_to_date("2003-01-02", "%Y-%m-%d") as f3,
257
       str_to_date("02 10:11:12", "%d %H:%i:%S.%f") as f4,
258
       str_to_date("02 10:11:12", "%d %H:%i:%S") as f5,
259
       str_to_date("02 10", "%d %f") as f6;
260
drop table t1, t2;
261
select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
262
       addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
263
       microsecond("1997-12-31 23:59:59.01XXXX") as f3;
264
265
select str_to_date("2003-04-05  g", "%Y-%m-%d") as f1,
266
       str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
267
--enable_ps_protocol
268
269
#
270
# Bug #14016 
271
#
272
create table t1 (f1 datetime);
273
insert into t1 (f1) values ("2005-01-01");
274
insert into t1 (f1) values ("2005-02-01");
275
select date_format(f1, "%m") as d1, date_format(f1, "%M") as d2 from t1 order by date_format(f1, "%M");
276
drop table t1;
277
278
#
279
# Bug #15828
280
#
281
select str_to_date( 1, NULL );
282
select str_to_date( NULL, 1 );
283
select str_to_date( 1, IF(1=1,NULL,NULL) );
284
285
#
286
# Bug#11326
287
# TIME_FORMAT using "%r" returns wrong hour using 24:00:00 in TIME column
288
#
289
# This tests that 24:00:00 does not return PM, when it should be AM.
290
# Some other values are being tested same time.
291
#
292
293
SELECT TIME_FORMAT("24:00:00", '%r');
294
SELECT TIME_FORMAT("00:00:00", '%r');
295
SELECT TIME_FORMAT("12:00:00", '%r');
296
SELECT TIME_FORMAT("15:00:00", '%r');
297
SELECT TIME_FORMAT("01:00:00", '%r');
298
SELECT TIME_FORMAT("25:00:00", '%r');
299
300
#
301
# Bug#11324
302
# TIME_FORMAT using "%l:%i" returns 36:00 with 24:00:00 in TIME column
303
#
304
# This tests that 24:00:00 does not change to "36:00 AM". Testing
305
# some other values same time.
306
#
307
308
SELECT TIME_FORMAT("00:00:00", '%l %p');
309
SELECT TIME_FORMAT("01:00:00", '%l %p');
310
SELECT TIME_FORMAT("12:00:00", '%l %p');
311
SELECT TIME_FORMAT("23:00:00", '%l %p');
312
SELECT TIME_FORMAT("24:00:00", '%l %p');
313
SELECT TIME_FORMAT("25:00:00", '%l %p');
314
315
#
316
# Bug#20729:  Bad date_format() call makes mysql server crash
317
#
318
SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896);
319
320
#
321
# Bug #22029: str_to_date returning NULL
322
#
323
324
select str_to_date('04 /30/2004', '%m /%d/%Y');
325
select str_to_date('04/30 /2004', '%m /%d /%Y');
326
select str_to_date('04/30/2004 ', '%m/%d/%Y ');
327
328
--echo "End of 4.1 tests"