Commit f7b039cc authored by unknown's avatar unknown

fix for wrong QUARTER calculation in EXTRACT() (Bug #18100)



mysql-test/r/func_time.result:
  expected test results for bug #18100 added
mysql-test/t/func_time.test:
  test case for bug #18100 added
sql/item_timefunc.cc:
  wrong formula for EXTRACT QUARTER, now uses the same calculus as the QUARTER()
  function
parent 2f2607fa
...@@ -360,6 +360,42 @@ extract(SECOND FROM "1999-01-02 10:11:12") ...@@ -360,6 +360,42 @@ extract(SECOND FROM "1999-01-02 10:11:12")
select extract(MONTH FROM "2001-02-00"); select extract(MONTH FROM "2001-02-00");
extract(MONTH FROM "2001-02-00") extract(MONTH FROM "2001-02-00")
2 2
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
quarter
1
SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter;
quarter
1
SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter;
quarter
1
SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter;
quarter
2
SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter;
quarter
2
SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter;
quarter
2
SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter;
quarter
3
SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter;
quarter
3
SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter;
quarter
3
SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter;
quarter
4
SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter;
quarter
4
SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter;
quarter
4
SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND; SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND;
"1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND
1968-01-20 03:14:08 1968-01-20 03:14:08
......
...@@ -139,6 +139,24 @@ select extract(MINUTE_SECOND FROM "10:11:12"); ...@@ -139,6 +139,24 @@ select extract(MINUTE_SECOND FROM "10:11:12");
select extract(SECOND FROM "1999-01-02 10:11:12"); select extract(SECOND FROM "1999-01-02 10:11:12");
select extract(MONTH FROM "2001-02-00"); select extract(MONTH FROM "2001-02-00");
#
# test EXTRACT QUARTER (Bug #18100)
#
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter;
SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter;
# #
# Test big intervals (Bug #3498) # Test big intervals (Bug #3498)
# #
......
...@@ -2213,7 +2213,7 @@ longlong Item_extract::val_int() ...@@ -2213,7 +2213,7 @@ longlong Item_extract::val_int()
switch (int_type) { switch (int_type) {
case INTERVAL_YEAR: return ltime.year; case INTERVAL_YEAR: return ltime.year;
case INTERVAL_YEAR_MONTH: return ltime.year*100L+ltime.month; case INTERVAL_YEAR_MONTH: return ltime.year*100L+ltime.month;
case INTERVAL_QUARTER: return ltime.month/3 + 1; case INTERVAL_QUARTER: return (ltime.month+2)/3;
case INTERVAL_MONTH: return ltime.month; case INTERVAL_MONTH: return ltime.month;
case INTERVAL_WEEK: case INTERVAL_WEEK:
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment