~drizzle-trunk/drizzle/development

813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
1
#
2
# Tests for the YEAR() function
3
#
4
# The Drizzle YEAR() function differs from the MySQL YEAR()
5
# function in these ways:
6
#
7
#  * Does not accept invalid parameters.  This results in an error
8
#    in Drizzle.
9
#
10
11
# YEAR() on a NULL should produce
12
# a NULL.
13
SELECT YEAR(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.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
20
# Wrong parameter count...but unfortunately produces 1064 Syntax Error due to limitations of 
21
# the SQL parser, which considers YEAR a keyword before being a function symbol
22
SELECT YEAR();
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
23
--error ER_PARSE_ERROR
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
24
# Wrong parameter count...but unfortunately produces 1064 Syntax Error due to limitations of 
25
# the SQL parser, which considers YEAR a keyword before being a function symbol
26
SELECT YEAR(1, 0);
27
28
# 
29
# Test invalid dates passed to YEAR
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.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
34
SELECT YEAR("xxx");
35
36
# Indy, bad dates!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
37
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
38
SELECT YEAR("0000-00-00"); # No 0000-00-00 dates!...
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
39
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
40
SELECT YEAR("0000-01-01"); # No zero year parts
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
41
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
42
SELECT YEAR("0001-00-01"); # No zero month parts
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
43
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
44
SELECT YEAR("0001-01-00"); # No zero day parts
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
45
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
46
SELECT YEAR("2000-02-30"); # No Feb 30th!
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
47
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
48
SELECT YEAR("1900-02-29"); # Not a leap YEAR since not divisible evenly by 400...
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
49
--error ER_INVALID_DATETIME_VALUE
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
50
SELECT YEAR('1976-15-15'); # No 15th month!
51
52
# A good date, which should output 2009
53
SELECT YEAR("2009-01-12");
54
55
# A good date, which should output 1970 - Test of 2 digit YEAR conversion...
56
SELECT YEAR("70-12-31");
57
58
# A good date, which should output 1999 - Test of 2 digit YEAR conversion...
59
SELECT YEAR("99-12-31");
60
61
# A good date, which should output 2069 - Test of 2 digit YEAR conversion...
62
SELECT YEAR("69-12-31");
63
64
# A good date, which should output 1
65
SELECT YEAR("0001-12-31");
66
67
# A good date, which should output 9999
68
SELECT YEAR("9999-12-31");
69
70
# A good date in the common USA format, should output 2007
71
SELECT YEAR('07/31/2009');
72
73
# 
74
# Tests for alternate DATETIME syntaxes 
75
# in string and numeric formats. All should
76
# return 2009.
77
#
78
SELECT YEAR('20090916');
79
SELECT YEAR('20090916091528');
80
SELECT YEAR("20090916091528.000000");
81
SELECT YEAR('09-09-16');
82
SELECT YEAR('09.09.16');
83
SELECT YEAR('09/09/16');
84
SELECT YEAR('09-09-16');
85
SELECT YEAR('09-9-2');
86
SELECT YEAR(20090916);
87
SELECT YEAR(20090916091528);
813.1.19 by Jay Pipes
To remain in compatibility with MySQL, added ability to interpret
88
SELECT YEAR(20090916091528.000001);
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
89
90
# Now test field values of different types
91
92
USE test;
93
--disable_warnings
94
DROP TABLE IF EXISTS t1;
95
--enable_warnings
96
CREATE TABLE t1 (
97
  int_fld INT NOT NULL
98
, date_fld DATE NOT NULL
99
, datetime_fld DATETIME NOT NULL
100
, timestamp_fld TIMESTAMP NOT NULL
101
, char_fld CHAR(22) NOT NULL
102
, varchar_fld VARCHAR(22) NOT NULL
103
, text_fld TEXT NOT NULL
104
, blob_fld BLOB NOT NULL
105
);
106
813.1.8 by Jay Pipes
Fixes MONTH() function to use new Temporal system. Errors
107
# Should all output 2007
813.1.2 by Jay Pipes
First function cleanup for temporal handling: YEAR()
108
INSERT INTO t1 VALUES (
109
20071130
110
, "2007-11-30"
111
, "2007-11-30 16:30:19"
112
, "2007-11-30T16:30:19"
113
, "2007-11-30 16:30:19"
114
, "2007-11-30 16:30:19"
115
, "2007-11-30T16:30:19"
116
, "2007-11-30T16:30:19"
117
);
118
119
SELECT YEAR(int_fld) FROM t1;
120
SELECT YEAR(date_fld) FROM t1;
121
SELECT YEAR(datetime_fld) FROM t1;
122
SELECT YEAR(timestamp_fld) FROM t1;
123
SELECT YEAR(char_fld) FROM t1;
124
SELECT YEAR(varchar_fld) FROM t1;
125
SELECT YEAR(text_fld) FROM t1;
126
SELECT YEAR(blob_fld) FROM t1;
127
128
DROP TABLE t1;