diff options
author | Gleb Shchepa <gshchepa@mysql.com> | 2010-03-22 12:33:25 +0400 |
---|---|---|
committer | Gleb Shchepa <gshchepa@mysql.com> | 2010-03-22 12:33:25 +0400 |
commit | 8feadddbe437556fe4f8c054fa9c749f77dd20ca (patch) | |
tree | 7605195836ec87045c9ab8d5a1c2c1ac97d26761 /sql | |
parent | e66128972db8f9484411468ffc7e3f3ede9c3265 (diff) | |
download | mariadb-git-8feadddbe437556fe4f8c054fa9c749f77dd20ca.tar.gz |
Bug #49910: Behavioural change in SELECT/WHERE on YEAR(4) data type
(Original patch by Sinisa Milivojevic)
The YEAR(4) value of 2000 was equal to the "bad" YEAR(4) value of 0000.
The get_year_value() function has been modified to not adjust bad
YEAR(4) value to 2000.
mysql-test/r/type_year.result:
Test case for bug #49910.
mysql-test/t/type_year.test:
Test case for bug #49910.
sql/item_cmpfunc.cc:
Bug #49910: Behavioural change in SELECT/WHERE on YEAR(4) data type
The get_year_value() function has been modified to not adjust bad
YEAR(4) value to 2000.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_cmpfunc.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index cd3f18fe1eb..6e38220abd1 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1190,12 +1190,21 @@ get_year_value(THD *thd, Item ***item_arg, Item **cache_arg, /* Coerce value to the 19XX form in order to correctly compare YEAR(2) & YEAR(4) types. + Here we are converting all item values but YEAR(4) fields since + 1) YEAR(4) already has a regular YYYY form and + 2) we don't want to convert zero/bad YEAR(4) values to the + value of 2000. */ - if (value < 70) - value+= 100; - if (value <= 1900) - value+= 1900; - + Item *real_item= item->real_item(); + if (!(real_item->type() == Item::FIELD_ITEM && + ((Item_field *)real_item)->field->type() == MYSQL_TYPE_YEAR && + ((Item_field *)real_item)->field->field_length == 4)) + { + if (value < 70) + value+= 100; + if (value <= 1900) + value+= 1900; + } /* Convert year to DATETIME of form YYYY-00-00 00:00:00 (YYYY0000000000). */ value*= 10000000000LL; |