summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-10-15 17:46:25 +0400
committerAlexander Barkov <bar@mariadb.com>2018-10-15 17:46:25 +0400
commit22e75434e7bb0405a9e36c9c9f22b6f30f7206db (patch)
tree3ed1ff4450138aff7a77b9b4bc5e810da8aa0b6c /sql
parenta53b99bf1333722b8f30fdbba7d7a40ce2485976 (diff)
downloadmariadb-git-22e75434e7bb0405a9e36c9c9f22b6f30f7206db.tar.gz
MDEV-17434 EXTRACT(DAY FROM negative_time) returns wrong result
Diffstat (limited to 'sql')
-rw-r--r--sql/item_timefunc.cc4
-rw-r--r--sql/item_timefunc.h5
2 files changed, 7 insertions, 2 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 2fc5869d762..317495d354e 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2098,7 +2098,7 @@ bool Item_extract::fix_length_and_dec()
case INTERVAL_QUARTER: set_date_length(2); break; // 1..4
case INTERVAL_MONTH: set_date_length(2); break; // MM
case INTERVAL_WEEK: set_date_length(2); break; // 0..52
- case INTERVAL_DAY: set_date_length(2); break; // DD
+ case INTERVAL_DAY: set_day_length(2); break; // DD
case INTERVAL_DAY_HOUR: set_time_length(4); break; // DDhh
case INTERVAL_DAY_MINUTE: set_time_length(6); break; // DDhhmm
case INTERVAL_DAY_SECOND: set_time_length(8); break; // DDhhmmss
@@ -2148,7 +2148,7 @@ longlong Item_extract::val_int()
week_format= current_thd->variables.default_week_format;
return calc_week(&ltime, week_mode(week_format), &year);
}
- case INTERVAL_DAY: return ltime.day;
+ case INTERVAL_DAY: return ltime.day * neg;
case INTERVAL_DAY_HOUR: return (long) (ltime.day*100L+ltime.hour)*neg;
case INTERVAL_DAY_MINUTE: return (long) (ltime.day*10000L+
ltime.hour*100L+
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index c1e77eae5bc..59031c69c6a 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -978,6 +978,11 @@ class Item_extract :public Item_int_func
max_length= length; //QQ: see above
date_value= true;
}
+ void set_day_length(uint32 length)
+ {
+ max_length= length + 1/*sign*/; // e.g. '-24:00:00' -> -1
+ date_value= true;
+ }
void set_time_length(uint32 length)
{
max_length= length + 1/*sign*/;