From: Date: April 11 2006 1:14pm Subject: bk commit into 5.0 tree (ramil:1.2146) BUG#14360 List-Archive: http://lists.mysql.com/commits/4781 X-Bug: 14360 Message-Id: <200604111114.k3BBE4IR022913@myoffice.izhnet.ru> Below is the list of changes that have just been committed into a local 5.0 repository of ram. When ram does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2146 06/04/11 16:13:57 ramil@stripped +4 -0 Fix for bug #14360: Date Between Interval Broken. sql/item_timefunc.h 1.64 06/04/11 16:13:48 ramil@stripped +1 -0 Fix for bug #14360: Date Between Interval Broken. - Item_date_add_interval::eq() introduced. sql/item_timefunc.cc 1.105 06/04/11 16:13:48 ramil@stripped +35 -0 Fix for bug #14360: Date Between Interval Broken. - Item_date_add_interval::eq() introduced. mysql-test/t/innodb.test 1.129 06/04/11 16:13:48 ramil@stripped +12 -0 Fix for bug #14360: Date Between Interval Broken. - test case. mysql-test/r/innodb.result 1.159 06/04/11 16:13:48 ramil@stripped +9 -0 Fix for bug #14360: Date Between Interval Broken. - test case. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: ramil # Host: myoffice.izhnet.ru # Root: /usr/home/ram/work/5.0.b14360 --- 1.104/sql/item_timefunc.cc 2006-04-07 14:15:10 +05:00 +++ 1.105/sql/item_timefunc.cc 2006-04-11 16:13:48 +05:00 @@ -2125,6 +2125,41 @@ longlong Item_date_add_interval::val_int ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second; } + + +bool Item_date_add_interval::eq(const Item *item, bool binary_cmp) const +{ + INTERVAL interval, other_interval; + String val= value; // Because of const + + if (this == item) + return TRUE; + + if ((item->type() != FUNC_ITEM) || + (arg_count != ((Item_func*) item)->arg_count) || + (func_name() != ((Item_func*) item)->func_name())) + return FALSE; + + Item_date_add_interval *other= (Item_date_add_interval*) item; + + if ((int_type != other->int_type) || + (!args[0]->eq(other->args[0], binary_cmp)) || + (get_interval_value(args[1], int_type, &val, &interval))) + return FALSE; + + val= other->value; + + if ((get_interval_value(other->args[1], other->int_type, &val, + &other_interval)) || + ((date_sub_interval ^ interval.neg) ^ + (other->date_sub_interval ^ other_interval.neg))) + return FALSE; + + // Assume comparing same types here due to earlier check + return memcmp(&interval, &other_interval, sizeof(INTERVAL)) == 0; +} + + static const char *interval_names[]= { "year", "quarter", "month", "day", "hour", --- 1.63/sql/item_timefunc.h 2005-11-10 18:13:07 +04:00 +++ 1.64/sql/item_timefunc.h 2006-04-11 16:13:48 +05:00 @@ -656,6 +656,7 @@ public: double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); } longlong val_int(); bool get_date(TIME *res, uint fuzzy_date); + bool eq(const Item *item, bool binary_cmp) const; void print(String *str); }; --- 1.158/mysql-test/r/innodb.result 2006-04-10 23:43:56 +05:00 +++ 1.159/mysql-test/r/innodb.result 2006-04-11 16:13:48 +05:00 @@ -3232,3 +3232,12 @@ drop trigger t2t; drop trigger t3t; drop trigger t4t; drop table t1, t2, t3, t4, t5; +create table t1(a date) engine=innodb; +create table t2(a date, key(a)) engine=innodb; +insert into t1 values('2005-10-01'); +insert into t2 values('2005-10-01'); +select * from t1, t2 +where t2.a between t1.a - interval 2 day and t1.a + interval 2 day; +a a +2005-10-01 2005-10-01 +drop table t1, t2; --- 1.128/mysql-test/t/innodb.test 2006-03-30 01:17:31 +05:00 +++ 1.129/mysql-test/t/innodb.test 2006-04-11 16:13:48 +05:00 @@ -2127,3 +2127,15 @@ drop table t1, t2, t3, t4, t5; connection default; disconnect a; disconnect b; + +# +# Bug #14360: problem with intervals +# + +create table t1(a date) engine=innodb; +create table t2(a date, key(a)) engine=innodb; +insert into t1 values('2005-10-01'); +insert into t2 values('2005-10-01'); +select * from t1, t2 + where t2.a between t1.a - interval 2 day and t1.a + interval 2 day; +drop table t1, t2;