diff options
author | unknown <tnurnberg@mysql.com/white.intern.koehntopp.de> | 2007-11-08 06:08:44 +0100 |
---|---|---|
committer | unknown <tnurnberg@mysql.com/white.intern.koehntopp.de> | 2007-11-08 06:08:44 +0100 |
commit | b1fc4b9e639ab6913df49bbd8c01103eaf14c81d (patch) | |
tree | db986cc0639f1d5c4413338e7ad1cca547a7e992 /sql | |
parent | 9e6bb07d3845566ffa7274bb14df544c8147f594 (diff) | |
download | mariadb-git-b1fc4b9e639ab6913df49bbd8c01103eaf14c81d.tar.gz |
Bug#31990: MINUTE() and SECOND() return bogus results when used on a DATE
HOUR(), MINUTE(), ... returned spurious results when used on a DATE-cast.
This happened because DATE-cast object did not overload get_time() method
in superclass Item. The default method was inappropriate here and
misinterpreted the data.
Patch adds missing method; get_time() on DATE-casts now returns SQL-NULL
on NULL input, 0 otherwise. This coincides with the way DATE-columns
behave.
mysql-test/r/cast.result:
Show that HOUR(), MINUTE(), ... return sensible values when used
on DATE-cast objects, namely NULL for NULL-dates and 0 otherwise.
Show that this coincides with how DATE-columns behave.
mysql-test/t/cast.test:
Show that HOUR(), MINUTE(), ... return sensible values when used
on DATE-cast objects, namely NULL for NULL-dates and 0 otherwise.
Show that this coincides with how DATE-columns behave.
sql/item_timefunc.cc:
Add get_time() method to DATE-cast object to overload
the method in Item superclass that would return spurious
results. Return zero-result; flag NULL if input was NULL.
sql/item_timefunc.h:
Add get_time() declaration to DATE-cast object.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_timefunc.cc | 7 | ||||
-rw-r--r-- | sql/item_timefunc.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index c1fa9dce038..7ed5e375f5b 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2645,6 +2645,13 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) } +bool Item_date_typecast::get_time(MYSQL_TIME *ltime) +{ + bzero((char *)ltime, sizeof(MYSQL_TIME)); + return args[0]->null_value; +} + + String *Item_date_typecast::val_str(String *str) { DBUG_ASSERT(fixed == 1); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index a5ecbc57e8d..b647e93b700 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -779,6 +779,7 @@ public: const char *func_name() const { return "cast_as_date"; } String *val_str(String *str); bool get_date(MYSQL_TIME *ltime, uint fuzzy_date); + bool get_time(MYSQL_TIME *ltime); const char *cast_type() const { return "date"; } enum_field_types field_type() const { return MYSQL_TYPE_DATE; } Field *tmp_table_field(TABLE *t_arg) |