~drizzle-trunk/drizzle/development

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