~drizzle-trunk/drizzle/development

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