2
# Tests for the MONTH() function
4
# The Drizzle MONTH() function differs from the MySQL MONTH()
5
# function in these ways:
7
# * Does not accept invalid parameters. This results in an error
11
# MONTH() on a NULL should produce
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 MONTH 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 MONTH a keyword before being a function symbol
29
# Test invalid dates passed to MONTH
30
# produce an error, not a NULL or anything
38
SELECT MONTH("0000-00-00"); # No 0000-00-00 dates!...
40
SELECT MONTH("0000-01-01"); # No zero year parts
42
SELECT MONTH("0001-00-01"); # No zero month parts
44
SELECT MONTH("0001-01-00"); # No zero day parts
46
SELECT MONTH("2000-02-30"); # No Feb 30th!
48
SELECT MONTH("1900-02-29"); # Not a leap MONTH since not divisible evenly by 400...
50
SELECT MONTH('1976-15-15'); # No 15th month!
52
# A good date, which should output 1
53
SELECT MONTH("2009-01-12");
55
# A good date, which should output 1999 - Test of 1 digit MONTH conversion...
56
SELECT MONTH("99-1-31");
58
# A good date, which should output 9
59
SELECT MONTH("0001-09-30");
61
# A good date, which should output 12
62
SELECT MONTH("9999-12-31");
64
# A good date in the common USA format, should output 7
65
SELECT MONTH('07/31/2009');
68
# Tests for alternate DATETIME syntaxes
69
# in string and numeric formats. All should
72
SELECT MONTH('20090916');
73
SELECT MONTH('20090916091528');
74
SELECT MONTH("20090916091528.000000");
75
SELECT MONTH('09-09-16');
76
SELECT MONTH('09.09.16');
77
SELECT MONTH('09/09/16');
78
SELECT MONTH('09-09-16');
79
SELECT MONTH('09-9-2');
80
SELECT MONTH(20090916);
81
SELECT MONTH(20090916091528);
82
--error 1686 # Don't yet support DOUBLE -> DATETIME.
83
SELECT MONTH(20090916091528.000000);
85
# Now test field values of different types
89
DROP TABLE IF EXISTS t1;
93
, date_fld DATE NOT NULL
94
, datetime_fld DATETIME NOT NULL
95
, timestamp_fld TIMESTAMP NOT NULL
96
, char_fld CHAR(22) NOT NULL
97
, varchar_fld VARCHAR(22) NOT NULL
98
, text_fld TEXT NOT NULL
99
, blob_fld BLOB NOT NULL
102
INSERT INTO t1 VALUES (
105
, "2007-11-30 16:30:19"
106
, "2007-11-30T16:30:19"
107
, "2007-11-30 16:30:19"
108
, "2007-11-30 16:30:19"
109
, "2007-11-30T16:30:19"
110
, "2007-11-30T16:30:19"
113
# Should all output 11
114
SELECT MONTH(int_fld) FROM t1;
115
SELECT MONTH(date_fld) FROM t1;
116
SELECT MONTH(datetime_fld) FROM t1;
117
SELECT MONTH(timestamp_fld) FROM t1;
118
SELECT MONTH(char_fld) FROM t1;
119
SELECT MONTH(varchar_fld) FROM t1;
120
SELECT MONTH(text_fld) FROM t1;
121
SELECT MONTH(blob_fld) FROM t1;