summaryrefslogtreecommitdiff
path: root/sql/item_func.h
diff options
context:
space:
mode:
authorevgen@moonbone.local <>2007-05-04 18:57:10 +0400
committerevgen@moonbone.local <>2007-05-04 18:57:10 +0400
commit239f727b7e58dd4dd7d89906baf6858605185c15 (patch)
treefbb263973b2c407217562f421ca1423cf5ea650b /sql/item_func.h
parent1a0cf6db7ca901547c667ac3d2d3c11db28a8eec (diff)
downloadmariadb-git-239f727b7e58dd4dd7d89906baf6858605185c15.tar.gz
Bug#27759: Wrong DATE/DATETIME comparison in LEAST()/GREATEST() functions.
The LEAST/GREATEST functions compared DATE/DATETIME values as strings which in some cases could lead to a wrong result. A new member function called cmp_datetimes() is added to the Item_func_min_max class. It compares arguments in DATETIME context and returns index of the least/greatest argument. The Item_func_min_max::fix_length_and_dec() function now detects when arguments should be compared in DATETIME context and sets the newly added flag compare_as_dates. It indicates that the cmp_datetimes() function should be called to get a correct result. Item_func_min_max::val_xxx() methods are corrected to call the cmp_datetimes() function when needed. Objects of the Item_splocal class now stores and reports correct original field type.
Diffstat (limited to 'sql/item_func.h')
-rw-r--r--sql/item_func.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/sql/item_func.h b/sql/item_func.h
index ec5d6bcda02..99e5328c39c 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -693,15 +693,23 @@ class Item_func_min_max :public Item_func
Item_result cmp_type;
String tmp_value;
int cmp_sign;
+ /* TRUE <=> arguments should be compared in the DATETIME context. */
+ bool compare_as_dates;
+ /* An item used for issuing warnings while string to DATETIME conversion. */
+ Item *datetime_item;
+ THD *thd;
+
public:
Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
- cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg) {}
+ cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(FALSE),
+ datetime_item(0) {}
double val_real();
longlong val_int();
String *val_str(String *);
my_decimal *val_decimal(my_decimal *);
void fix_length_and_dec();
enum Item_result result_type () const { return cmp_type; }
+ uint cmp_datetimes(ulonglong *value);
};
class Item_func_min :public Item_func_min_max