diff options
author | Alexander Barkov <bar@mariadb.org> | 2014-06-06 10:29:52 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2014-06-06 10:29:52 +0400 |
commit | 216fbe2af3c8dc81f492af79dee61d6a3d333678 (patch) | |
tree | 8fc7a2b00b5fe229d79d2b4216d236debd201fa1 /sql | |
parent | d8edb88cb15c3341a7686eb5909dde6deac16674 (diff) | |
download | mariadb-git-216fbe2af3c8dc81f492af79dee61d6a3d333678.tar.gz |
MDEV-6102 Comparison between TIME and DATETIME does not use CURRENT_DATE
MDEV-6101 Hybrid functions do not add CURRENT_DATE when converting TIME to DATETIME
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.h | 25 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 19 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 6 |
3 files changed, 38 insertions, 12 deletions
diff --git a/sql/field.h b/sql/field.h index cbd9175f26c..46ec491270b 100644 --- a/sql/field.h +++ b/sql/field.h @@ -94,6 +94,31 @@ inline uint get_set_pack_length(int elements) /** + Tests if field type is temporal and has date part, + i.e. represents DATE, DATETIME or TIMESTAMP types in SQL. + + @param type Field type, as returned by field->type(). + @retval true If field type is temporal type with date part. + @retval false If field type is not temporal type with date part. +*/ +inline bool is_temporal_type_with_date(enum_field_types type) +{ + switch (type) + { + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + return true; + case MYSQL_TYPE_DATETIME2: + case MYSQL_TYPE_TIMESTAMP2: + DBUG_ASSERT(0); // field->real_type() should not get to here. + default: + return false; + } +} + + +/** Recognizer for concrete data type (called real_type for some reason), returning true if it is one of the TIMESTAMP types. */ diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 2c4218279d7..289668f24ca 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -900,9 +900,11 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, { MYSQL_TIME ltime; uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES; - if (f_type == MYSQL_TYPE_TIME) - fuzzydate|= TIME_TIME_ONLY; - if (item->get_date(<ime, fuzzydate)) + if ((item->field_type() == MYSQL_TYPE_TIME && + is_temporal_type_with_date(warn_item->field_type())) ? + item->get_date_with_conversion(<ime, fuzzydate) : + item->get_date(<ime, fuzzydate | + (f_type == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))) value= 0; /* invalid date */ else value= pack_time(<ime); @@ -2559,9 +2561,9 @@ Item_func_ifnull::str_op(String *str) bool Item_func_ifnull::date_op(MYSQL_TIME *ltime, uint fuzzydate) { DBUG_ASSERT(fixed == 1); - if (!args[0]->get_date(ltime, fuzzydate & ~TIME_FUZZY_DATES)) + if (!args[0]->get_date_with_conversion(ltime, fuzzydate & ~TIME_FUZZY_DATES)) return (null_value= false); - if (!args[1]->get_date(ltime, fuzzydate & ~TIME_FUZZY_DATES)) + if (!args[1]->get_date_with_conversion(ltime, fuzzydate & ~TIME_FUZZY_DATES)) return (null_value= false); bzero((char*) ltime,sizeof(*ltime)); return null_value= !(fuzzydate & TIME_FUZZY_DATES); @@ -2752,7 +2754,7 @@ bool Item_func_if::date_op(MYSQL_TIME *ltime, uint fuzzydate) { DBUG_ASSERT(fixed == 1); Item *arg= args[0]->val_bool() ? args[1] : args[2]; - return (null_value= arg->get_date(ltime, fuzzydate)); + return (null_value= arg->get_date_with_conversion(ltime, fuzzydate)); } @@ -2997,7 +2999,7 @@ bool Item_func_case::date_op(MYSQL_TIME *ltime, uint fuzzydate) Item *item= find_item(&dummy_str); if (!item) return (null_value= true); - return (null_value= item->get_date(ltime, fuzzydate)); + return (null_value= item->get_date_with_conversion(ltime, fuzzydate)); } @@ -3315,7 +3317,8 @@ bool Item_func_coalesce::date_op(MYSQL_TIME *ltime,uint fuzzydate) null_value= 0; for (uint i= 0; i < arg_count; i++) { - bool res= args[i]->get_date(ltime, fuzzydate & ~TIME_FUZZY_DATES); + bool res= args[i]->get_date_with_conversion(ltime, + fuzzydate & ~TIME_FUZZY_DATES); if (!args[i]->null_value) return res; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index bd1dd6d89fb..5fddad56028 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1300,13 +1300,11 @@ bool get_interval_value(Item *args,interval_type int_type, INTERVAL *interval) interval->neg= my_decimal2seconds(val, &second, &second_part); if (second == LONGLONG_MAX) { - char buff[DECIMAL_MAX_STR_LENGTH]; - int length= sizeof(buff); - decimal2string(val, buff, &length, 0, 0, 0); + ErrConvDecimal err(val); push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE, ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL", - buff); + err.ptr()); return true; } |