2
# Tests for the MICROSECOND() function
4
# The Drizzle MICROSECOND() function differs from the MySQL MICROSECOND()
5
# function in these ways:
7
# * Does not accept invalid parameters. This results in an error
11
# MICROSECOND() on a NULL should produce
13
SELECT MICROSECOND(NULL);
16
# Test improper argument list
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
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);
29
# Test invalid dates passed to MICROSECOND
30
# produce an error, not a NULL or anything
34
SELECT MICROSECOND("xxx");
39
# The following are all bad dates, with no possibility of interpreting
40
# the values as TIME-only components.
43
SELECT MICROSECOND("0000-00-00"); # No 0000-00-00 dates!...
45
SELECT MICROSECOND("0000-01-01"); # No zero year parts
47
SELECT MICROSECOND("0001-00-01"); # No zero month parts
49
SELECT MICROSECOND("0001-01-00"); # No zero day parts
51
SELECT MICROSECOND("2000-02-30"); # No Feb 30th!
53
SELECT MICROSECOND("1900-02-29"); # Not a leap MICROSECOND since not divisible evenly by 400...
55
SELECT MICROSECOND('1976-15-15'); # No 15th month!
57
SELECT MICROSECOND('23:59:70'); # No 70th second!
59
SELECT MICROSECOND('23:70:59'); # No 70th minute!
61
SELECT MICROSECOND('26:00:00'); # No 26th hour!
63
SELECT MICROSECOND('26:00:00.9999999'); # Microseconds are 6 places, not 7
65
# A good date, which cannot be interpreted as a TIME component. Should return 0.
66
SELECT MICROSECOND("2009-01-12");
68
# A good date, which should output 0 since no TIME component - Test of 2 digit year conversion...
69
SELECT MICROSECOND("70-12-31");
71
# A good date in the common USA format, should output 0 since no TIME component
72
SELECT MICROSECOND('07/31/2009');
74
# A good datetime, should output 0 since no sub-second component
75
SELECT MICROSECOND("2008-11-30 03:30:15");
77
# A good datetime, should output 0 since no sub-second component
78
SELECT MICROSECOND("2008-11-30T03:30:15");
80
# A good datetime, should output 123456
81
SELECT MICROSECOND("2008-11-30T03:30:15.123456");
83
# A good datetime, should output 0 since no sub-second component
84
SELECT MICROSECOND("20081130033015");
86
# A good datetime, should output 123456
87
SELECT MICROSECOND("20081130033015.123456");
89
# A good datetime, should output 123450
90
SELECT MICROSECOND("20081130033015.12345");
92
# A good datetime, should output 123400
93
SELECT MICROSECOND("20081130033015.1234");
95
# A good datetime, should output 123000
96
SELECT MICROSECOND("20081130033015.123");
98
# A good datetime, should output 120000
99
SELECT MICROSECOND("20081130033015.12");
101
# A good datetime, should output 100000
102
SELECT MICROSECOND("20081130033015.1");
104
# A good datetime, interpreted int->string, should output 0 since no sub-second component
105
SELECT MICROSECOND(20081130033015);
107
# A good datetime, interpreted int->string, should output 123456
108
SELECT MICROSECOND(20081130033015.123456);
110
# A good datetime, interpreted int->string, should output 123450
111
SELECT MICROSECOND(20081130033015.12345);
113
# A good datetime, interpreted int->string, should output 123400
114
SELECT MICROSECOND(20081130033015.1234);
116
# A good datetime, interpreted int->string, should output 123000
117
SELECT MICROSECOND(20081130033015.123);
119
# A good datetime, interpreted int->string, should output 120000
120
SELECT MICROSECOND(20081130033015.12);
122
# A good datetime, interpreted int->string, should output 100000
123
SELECT MICROSECOND(20081130033015.1);
125
# A good time (according to MySQL, not Jay Pipes...), should output 0 since no sub-second component
126
SELECT MICROSECOND(231115);
128
# A good time (according to MySQL, not Jay Pipes...), should output 0 since no sub-second component
129
SELECT MICROSECOND("231115");
131
# A good time, should output 0 since no sub-second component
132
SELECT MICROSECOND("23:59:59");
134
# A good time, should output 123456
135
SELECT MICROSECOND("23:59:59.123456");
137
# Now test field values of different types
141
DROP TABLE IF EXISTS t1;
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
154
# Should all output 0 since no current way to store microsecond :(
155
INSERT INTO t1 VALUES (
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"
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;