~drizzle-trunk/drizzle/development

813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
1
#
2
# Tests for the MICROSECOND() function
3
#
4
# The Drizzle MICROSECOND() function differs from the MySQL MICROSECOND()
5
# function in these ways:
6
#
7
#  * Does not accept invalid parameters.  This results in an error
8
#    in Drizzle.
9
#
10
11
# MICROSECOND() on a NULL should produce
12
# a NULL.
13
SELECT MICROSECOND(NULL);
14
15
# 
16
# Test improper argument list 
17
#
18
# 1 arg is required.
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
19
--error ER_PARSE_ERROR 
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
20
# Wrong parameter count...but unfortunately produces 1064 Syntax Error due to limitations of 
21
# the SQL parser, which considers MICROSECOND a keyword before being a function symbol
22
SELECT MICROSECOND();
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
23
--error ER_PARSE_ERROR
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
24
# Wrong parameter count...but unfortunately produces 1064 Syntax Error due to limitations of 
25
# the SQL parser, which considers MICROSECOND a keyword before being a function symbol
26
SELECT MICROSECOND(1, 0);
27
28
# 
29
# Test invalid dates passed to MICROSECOND
30
# produce an error, not a NULL or anything
31
# else...
32
#
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
33
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
34
SELECT MICROSECOND("xxx");
35
36
# 
37
# Indy, bad dates!
38
#
39
# The following are all bad dates, with no possibility of interpreting
40
# the values as TIME-only components.
41
#
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
42
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
43
SELECT MICROSECOND("0000-00-00"); # No 0000-00-00 dates!...
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
44
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
45
SELECT MICROSECOND("0000-01-01"); # No zero year parts
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
46
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
47
SELECT MICROSECOND("0001-00-01"); # No zero month parts
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
48
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
49
SELECT MICROSECOND("0001-01-00"); # No zero day parts
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
50
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
51
SELECT MICROSECOND("2000-02-30"); # No Feb 30th!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
52
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
53
SELECT MICROSECOND("1900-02-29"); # Not a leap MICROSECOND since not divisible evenly by 400...
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
54
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
55
SELECT MICROSECOND('1976-15-15'); # No 15th month!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
56
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
57
SELECT MICROSECOND('23:59:70'); # No 70th second!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
58
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
59
SELECT MICROSECOND('23:70:59'); # No 70th minute!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
60
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
61
SELECT MICROSECOND('26:00:00'); # No 26th hour!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
62
--error ER_INVALID_DATETIME_VALUE
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
63
SELECT MICROSECOND('26:00:00.9999999'); # Microseconds are 6 places, not 7
64
65
# A good date, which cannot be interpreted as a TIME component.  Should return 0.
66
SELECT MICROSECOND("2009-01-12");
67
68
# A good date, which should output 0 since no TIME component - Test of 2 digit year conversion...
69
SELECT MICROSECOND("70-12-31");
70
71
# A good date in the common USA format, should output 0 since no TIME component
72
SELECT MICROSECOND('07/31/2009');
73
74
# A good datetime, should output 0 since no sub-second component
75
SELECT MICROSECOND("2008-11-30 03:30:15");
76
77
# A good datetime, should output 0 since no sub-second component
78
SELECT MICROSECOND("2008-11-30T03:30:15");
79
80
# A good datetime, should output 123456
81
SELECT MICROSECOND("2008-11-30T03:30:15.123456");
82
83
# A good datetime, should output 0 since no sub-second component
84
SELECT MICROSECOND("20081130033015");
85
86
# A good datetime, should output 123456
87
SELECT MICROSECOND("20081130033015.123456");
88
813.1.19 by Jay Pipes
To remain in compatibility with MySQL, added ability to interpret
89
# A good datetime, should output 123450
90
SELECT MICROSECOND("20081130033015.12345");
91
92
# A good datetime, should output 123400
93
SELECT MICROSECOND("20081130033015.1234");
94
95
# A good datetime, should output 123000
96
SELECT MICROSECOND("20081130033015.123");
97
98
# A good datetime, should output 120000
99
SELECT MICROSECOND("20081130033015.12");
100
101
# A good datetime, should output 100000
102
SELECT MICROSECOND("20081130033015.1");
103
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
104
# A good datetime, interpreted int->string, should output 0 since no sub-second component
105
SELECT MICROSECOND(20081130033015);
106
813.1.19 by Jay Pipes
To remain in compatibility with MySQL, added ability to interpret
107
# A good datetime, interpreted int->string, should output 123456
108
SELECT MICROSECOND(20081130033015.123456);
109
110
# A good datetime, interpreted int->string, should output 123450
111
SELECT MICROSECOND(20081130033015.12345);
112
113
# A good datetime, interpreted int->string, should output 123400
114
SELECT MICROSECOND(20081130033015.1234);
115
116
# A good datetime, interpreted int->string, should output 123000
117
SELECT MICROSECOND(20081130033015.123);
118
119
# A good datetime, interpreted int->string, should output 120000
120
SELECT MICROSECOND(20081130033015.12);
121
122
# A good datetime, interpreted int->string, should output 100000
123
SELECT MICROSECOND(20081130033015.1);
124
813.1.17 by Jay Pipes
Fixes MICROSECOND() to use new Temporal system and throw appropriate errors on bad datetimes. Adds new microsecond.test case. Still to do: don't have microseconds thrown away by DATETIME type... :)
125
# A good time (according to MySQL, not Jay Pipes...), should output 0 since no sub-second component
126
SELECT MICROSECOND(231115);
127
128
# A good time (according to MySQL, not Jay Pipes...), should output 0 since no sub-second component
129
SELECT MICROSECOND("231115");
130
131
# A good time, should output 0 since no sub-second component
132
SELECT MICROSECOND("23:59:59");
133
134
# A good time, should output 123456
135
SELECT MICROSECOND("23:59:59.123456");
136
137
# Now test field values of different types
138
139
USE test;
140
--disable_warnings
141
DROP TABLE IF EXISTS t1;
142
--enable_warnings
143
CREATE TABLE t1 (
144
  int_fld INT NOT NULL
145
, date_fld DATE NOT NULL
146
, datetime_fld DATETIME NOT NULL
147
, timestamp_fld TIMESTAMP NOT NULL
148
, char_fld CHAR(22) NOT NULL
149
, varchar_fld VARCHAR(22) NOT NULL
150
, text_fld TEXT NOT NULL
151
, blob_fld BLOB NOT NULL
152
);
153
154
# Should all output 0 since no current way to store microsecond :(
155
INSERT INTO t1 VALUES (
156
20071130
157
, "2007-11-30"
158
, "2007-11-30 16:30:19"
159
, "2007-11-30T16:30:19"
160
, "2007-11-30 16:30:19"
161
, "2007-11-30 16:30:19"
162
, "2007-11-30T16:30:19"
163
, "2007-11-30T16:30:19"
164
);
165
166
SELECT MICROSECOND(int_fld) FROM t1;
167
SELECT MICROSECOND(date_fld) FROM t1;
168
SELECT MICROSECOND(datetime_fld) FROM t1;
169
SELECT MICROSECOND(timestamp_fld) FROM t1;
170
SELECT MICROSECOND(char_fld) FROM t1;
171
SELECT MICROSECOND(varchar_fld) FROM t1;
172
SELECT MICROSECOND(text_fld) FROM t1;
173
SELECT MICROSECOND(blob_fld) FROM t1;
174
175
DROP TABLE t1;
176