mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / t / func_sapdb.test
blob1292c4757323515440c1236acae6a06a74ccc6ef
1 --disable_warnings
2 drop table if exists t1, test;
3 --enable_warnings
7 # time functions
9 select extract(DAY_MICROSECOND FROM "1999-01-02 10:11:12.000123");
10 select extract(HOUR_MICROSECOND FROM "1999-01-02 10:11:12.000123");
11 select extract(MINUTE_MICROSECOND FROM "1999-01-02 10:11:12.000123");
12 select extract(SECOND_MICROSECOND FROM "1999-01-02 10:11:12.000123");
13 select extract(MICROSECOND FROM "1999-01-02 10:11:12.000123");
14 select date_format("1997-12-31 23:59:59.000002", "%f");
16 select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000 99:99:99.999999" DAY_MICROSECOND);
17 select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99:99.999999" HOUR_MICROSECOND);
18 select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99.999999" MINUTE_MICROSECOND);
19 select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000.999999" SECOND_MICROSECOND);
20 select date_add("1997-12-31 23:59:59.000002",INTERVAL "999999" MICROSECOND);
22 select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1 1:1:1.000002" DAY_MICROSECOND);
23 select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1:1.000002" HOUR_MICROSECOND);
24 select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1.000002" MINUTE_MICROSECOND);
25 select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1.000002" SECOND_MICROSECOND);
26 select date_sub("1998-01-01 00:00:00.000001",INTERVAL "000002" MICROSECOND);
28 #Date functions
29 select adddate("1997-12-31 23:59:59.000001", 10);
30 select subdate("1997-12-31 23:59:59.000001", 10);
32 select datediff("1997-12-31 23:59:59.000001","1997-12-30");
33 select datediff("1997-11-30 23:59:59.000001","1997-12-31");
34 SET @@SQL_MODE="ALLOW_INVALID_DATES";
35 select datediff("1997-11-31 23:59:59.000001","1997-12-31");
36 SET @@SQL_MODE="";
38 # This will give a warning
39 select datediff("1997-11-31 23:59:59.000001","1997-12-31");
40 select datediff("1997-11-30 23:59:59.000001",null);
42 select weekofyear("1997-11-30 23:59:59.000001");
44 select makedate(03,1);
45 select makedate('0003',1);
46 select makedate(1997,1);
47 select makedate(1997,0);
48 select makedate(9999,365);
49 select makedate(9999,366);
50 select makedate(100,1);
52 #Time functions
54 select addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002");
55 select subtime("1997-12-31 23:59:59.000001", "1 1:1:1.000002");
56 select addtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
57 select subtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
58 select subtime("01:00:00.999999", "02:00:00.999998");
59 select subtime("02:01:01.999999", "01:01:01.999999");
61 # PS doesn't support fractional seconds
62 --disable_ps_protocol
63 select timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002");
64 select timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002");
65 select timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002");
66 select timediff("1997-12-31 23:59:59.000001","23:59:59.000001");
67 select timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.000001");
68 select timediff("2005-01-11 15:48:49.999999", "2005-01-11 15:48:50");
69 --enable_ps_protocol
71 select maketime(10,11,12);
72 select maketime(25,11,12);
73 select maketime(-25,11,12);
75 # Extraction functions
77 # PS doesn't support fractional seconds
78 --disable_ps_protocol
79 select timestamp("2001-12-01", "01:01:01.999999");
80 select timestamp("2001-13-01", "01:01:01.000001");
81 select timestamp("2001-12-01", "25:01:01");
82 select timestamp("2001-12-01 01:01:01.000100");
83 select timestamp("2001-12-01");
84 select day("1997-12-31 23:59:59.000001");
85 select date("1997-12-31 23:59:59.000001");
86 select date("1997-13-31 23:59:59.000001");
87 select time("1997-12-31 23:59:59.000001");
88 select time("1997-12-31 25:59:59.000001");
89 select microsecond("1997-12-31 23:59:59.000001");
90 --enable_ps_protocol
92 create table t1 
93 select makedate(1997,1) as f1,
94    addtime(cast("1997-12-31 23:59:59.000001" as datetime), "1 1:1:1.000002") as f2,
95    addtime(cast("23:59:59.999999" as time) , "1 1:1:1.000002") as f3,
96    timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002") as f4,
97    timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002") as f5,
98    maketime(10,11,12) as f6,
99    timestamp(cast("2001-12-01" as date), "01:01:01") as f7,
100    date("1997-12-31 23:59:59.000001") as f8,
101    time("1997-12-31 23:59:59.000001") as f9;
102 describe t1;
103 # PS doesn't support fractional seconds
104 --disable_ps_protocol
105 select * from t1;
106 --enable_ps_protocol
108 create table test(t1 datetime, t2 time, t3 time, t4 datetime);
109 insert into test values 
110 ('2001-01-01 01:01:01', '01:01:01', null, '2001-02-01 01:01:01'),
111 ('2001-01-01 01:01:01', '-01:01:01', '-23:59:59', "1997-12-31 23:59:59.000001"),
112 ('1997-12-31 23:59:59.000001', '-23:59:59', '-01:01:01', '2001-01-01 01:01:01'),
113 ('2001-01-01 01:01:01', '01:01:01', '-1 01:01:01', null),
114 ('2001-01-01 01:01:01', '-01:01:01', '1 01:01:01', '2001-01-01 01:01:01'),
115 ('2001-01-01 01:01:01', null, '-1 01:01:01', null),
116 (null, null, null, null),
117 ('2001-01-01 01:01:01', '01:01:01', '1 01:01:01', '2001-01-01 01:01:01');
119 SELECT ADDTIME(t1,t2) As ttt, ADDTIME(t2, t3) As qqq from test;
120 # PS doesn't support fractional seconds
121 --disable_ps_protocol
122 SELECT TIMEDIFF(t1, t4) As ttt, TIMEDIFF(t2, t3) As qqq,
123        TIMEDIFF(t3, t2) As eee, TIMEDIFF(t2, t4) As rrr from test;
124 --enable_ps_protocol
126 drop table t1, test;
128 select addtime("-01:01:01.01", "-23:59:59.1") as a;
129 select microsecond("1997-12-31 23:59:59.01") as a;
130 select microsecond(19971231235959.01) as a;
131 select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a;
132 # PS doesn't support fractional seconds
133 --disable_ps_protocol
134 select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f");
135 --enable_ps_protocol
137 # End of 4.1 tests
142 # Bug#37553: MySql Error Compare TimeDiff & Time
145 # calculations involving negative time values ignored sign
146 select timediff('2008-09-29 20:10:10','2008-09-30 20:10:10'),time('00:00:00');
147 select timediff('2008-09-29 20:10:10','2008-09-30 20:10:10')>time('00:00:00');
148 select timediff('2008-09-29 20:10:10','2008-09-30 20:10:10')<time('00:00:00');
150 # show that conversion to DECIMAL no longer drops sign
151 SELECT CAST(time('-73:42:12') AS DECIMAL);
156 # Bug#42525 - TIMEDIFF function
159 SELECT TIMEDIFF(TIME('17:00:00'),TIME('17:00:00'))=TIME('00:00:00') AS 1Eq,
160        TIMEDIFF(TIME('17:59:00'),TIME('17:00:00'))=TIME('00:00:00') AS 1NEq1,
161        TIMEDIFF(TIME('18:00:00'),TIME('17:00:00'))=TIME('00:00:00') AS 1NEq2,
162        TIMEDIFF(TIME('17:00:00'),TIME('17:00:00'))=     '00:00:00'  AS 2Eq,
163        TIMEDIFF(TIME('17:59:00'),TIME('17:00:00'))=     '00:00:00'  AS 2NEq1,
164        TIMEDIFF(TIME('18:00:00'),TIME('17:00:00'))=     '00:00:00'  AS 2NEq2,
165        TIMEDIFF(TIME('17:00:00'),TIME('17:00:00'))=TIME(0)          AS 3Eq,
166        TIMEDIFF(TIME('17:59:00'),TIME('17:00:00'))=TIME(0)          AS 3NEq1,
167        TIMEDIFF(TIME('18:00:00'),TIME('17:00:00'))=TIME(0)          AS 3NEq2,
168        TIME(0) AS Time0, TIME('00:00:00') AS Time00, '00:00:00' AS Literal0000,
169        TIMEDIFF(TIME('17:59:00'),TIME('17:00:00')),
170        TIMEDIFF(TIME('17:00:00'),TIME('17:59:00'));
172 # End of 5.0 tests