List:Commits« Previous MessageNext Message »
From:mhansson Date:December 18 2007 10:04am
Subject:bk commit into 5.0 tree (mhansson:1.2546) BUG#24525
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of martin. When martin 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@stripped, 2007-12-18 11:04:47+01:00, mhansson@stripped +5 -0
  Bug#24525: ADDDATE returns string value
  
  When DATETIME values are compared to constants, the constants should be 
  converted to TIMESTAMP. But this depended on field_type, which is 
  MYSQL_TYPE_STRING for ADDDATE when invoked with a string. 
  Fixed by adding a property comparison_type to Item class that defaults to 
  the field_type, but overriding it for Item_date_func to always return TIMESTAMP.

  mysql-test/r/type_date.result@stripped, 2007-12-18 11:04:42+01:00, mhansson@stripped +32 -0
    Bug#24525: Test caseh

  mysql-test/t/type_date.test@stripped, 2007-12-18 11:04:42+01:00, mhansson@stripped +15 -0
    Bug#24525: Test result

  sql/item.cc@stripped, 2007-12-18 11:04:42+01:00, mhansson@stripped +1 -1
    Bug#24525: Changed basis for is_datetime.

  sql/item.h@stripped, 2007-12-18 11:04:42+01:00, mhansson@stripped +17 -0
    Bug#24525: Added get_comparison_type

  sql/item_timefunc.h@stripped, 2007-12-18 11:04:43+01:00, mhansson@stripped +1 -0
    Bug#24525: 

diff -Nrup a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result
--- a/mysql-test/r/type_date.result	2007-10-04 09:15:24 +02:00
+++ b/mysql-test/r/type_date.result	2007-12-18 11:04:42 +01:00
@@ -146,3 +146,35 @@ str_to_date( '', a )
 0000-00-00 00:00:00
 NULL
 DROP TABLE t1;
+SELECT ADDDATE('2006-11-30 9:00:00',0) = '2006-11-30 9';
+ADDDATE('2006-11-30 9:00:00',0) = '2006-11-30 9'
+1
+SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00')='2004-01-01 22';
+CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00')='2004-01-01 22'
+1
+SELECT CURDATE()=CONCAT(CURDATE(),' ');
+CURDATE()=CONCAT(CURDATE(),' ')
+1
+SELECT DATE('2006-11-03') = '2006-11-3';
+DATE('2006-11-03') = '2006-11-3'
+1
+SELECT DATE_ADD('2006-11-30 9:00:00',INTERVAL 0 HOUR) = '2006-11-30 9';
+DATE_ADD('2006-11-30 9:00:00',INTERVAL 0 HOUR) = '2006-11-30 9'
+1
+SELECT DATE_SUB('2006-11-30 9:00:00',INTERVAL 0 HOUR) = '2006-11-30 9';
+DATE_SUB('2006-11-30 9:00:00',INTERVAL 0 HOUR) = '2006-11-30 9'
+1
+SELECT TIMESTAMP('2006-11-30 9:00:00') = '2006-11-30 9';
+TIMESTAMP('2006-11-30 9:00:00') = '2006-11-30 9'
+1
+SELECT LAST_DAY('2003-02-05') = '2003-2-28';
+LAST_DAY('2003-02-05') = '2003-2-28'
+1
+SELECT STR_TO_DATE('04/31/2004', '%m/%d/%Y') = ' 2004-04-31';
+STR_TO_DATE('04/31/2004', '%m/%d/%Y') = ' 2004-04-31'
+1
+SELECT TIMESTAMPADD(MINUTE,1,'2003-01-02') =
+'2003-01-02 00:01';
+TIMESTAMPADD(MINUTE,1,'2003-01-02') =
+'2003-01-02 00:01'
+1
diff -Nrup a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test
--- a/mysql-test/t/type_date.test	2007-10-04 09:15:25 +02:00
+++ b/mysql-test/t/type_date.test	2007-12-18 11:04:42 +01:00
@@ -149,3 +149,18 @@ INSERT INTO t1 VALUES (NULL);
 
 SELECT str_to_date( '', a ) FROM t1;
 DROP TABLE t1;
+
+#
+# Bug #24525  	ADDDATE returns string value
+#
+SELECT ADDDATE('2006-11-30 9:00:00',0) = '2006-11-30 9';
+SELECT CONVERT_TZ('2004-01-01 12:00:00','+00:00','+10:00')='2004-01-01 22';
+SELECT CURDATE()=CONCAT(CURDATE(),' ');
+SELECT DATE('2006-11-03') = '2006-11-3';
+SELECT DATE_ADD('2006-11-30 9:00:00',INTERVAL 0 HOUR) = '2006-11-30 9';
+SELECT DATE_SUB('2006-11-30 9:00:00',INTERVAL 0 HOUR) = '2006-11-30 9';
+SELECT TIMESTAMP('2006-11-30 9:00:00') = '2006-11-30 9';
+SELECT LAST_DAY('2003-02-05') = '2003-2-28';
+SELECT STR_TO_DATE('04/31/2004', '%m/%d/%Y') = ' 2004-04-31';
+SELECT TIMESTAMPADD(MINUTE,1,'2003-01-02') =
+'2003-01-02 00:01';
diff -Nrup a/sql/item.cc b/sql/item.cc
--- a/sql/item.cc	2007-10-16 10:17:35 +02:00
+++ b/sql/item.cc	2007-12-18 11:04:42 +01:00
@@ -4234,7 +4234,7 @@ enum_field_types Item::field_type() cons
 
 bool Item::is_datetime()
 {
-  switch (field_type())
+  switch (get_comparison_type())
   {
     case MYSQL_TYPE_DATE:
     case MYSQL_TYPE_DATETIME:
diff -Nrup a/sql/item.h b/sql/item.h
--- a/sql/item.h	2007-10-16 10:19:00 +02:00
+++ b/sql/item.h	2007-12-18 11:04:42 +01:00
@@ -529,6 +529,14 @@ public:
   virtual Item_result cast_to_int_type() const { return result_type(); }
   virtual enum_field_types field_type() const;
   virtual enum Type type() const =0;
+  /**
+     Item's such as functions returning string representing dates, that do not
+     return MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME, or MYSQL_TYPE_TIMESTAMP as
+     their field_type (such as descendent classes of Item_date,
+     Item_date_func, or Item_date_typecast) need to specify this by overriding
+     this method and returning one of them.
+   */
+  virtual enum_field_types get_comparison_type() { return field_type(); }
   /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
   /*
     Return double precision floating point representation of item.
@@ -869,6 +877,15 @@ public:
     representation is more precise than the string one).
   */
   virtual bool result_as_longlong() { return FALSE; }
+  /**
+     @breif For Items where the other argument in a comparison should be cast to
+     TIMESTAMP before comparison, this method returns true.
+
+     A special case applies when comparing a TIMESTAMP or DATETIME value with
+     constant. The constant is converted to a timestamp before the comparison
+     is performed. This is done to be more ODBC-friendly. The rule applies only
+     to TIMESTAMP or DATETIME. 
+   */
   bool is_datetime();
   virtual Field::geometry_type get_geometry_type() const
     { return Field::GEOM_GEOMETRY; };
diff -Nrup a/sql/item_timefunc.h b/sql/item_timefunc.h
--- a/sql/item_timefunc.h	2007-10-09 15:25:24 +02:00
+++ b/sql/item_timefunc.h	2007-12-18 11:04:43 +01:00
@@ -378,6 +378,7 @@ public:
   {
     return save_date_in_field(field);
   }
+  enum_field_types get_comparison_type() { return MYSQL_TYPE_TIMESTAMP; }
 };
 
 
Thread
bk commit into 5.0 tree (mhansson:1.2546) BUG#24525mhansson18 Dec