List:Commits« Previous MessageNext Message »
From:Tatjana A Nuernberg Date:December 11 2007 9:12am
Subject:bk commit into 5.0 tree (tnurnberg:1.2560) BUG#31990
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of tnurnberg. When tnurnberg 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-11 10:12:05+01:00, tnurnberg@stripped +8 -0
  Bug#31990: MINUTE() and SECOND() return bogus results when used on a DATE
  
  HOUR(), MINUTE(), ... returned spurious results when used on a DATE-cast.
  This happened because DATE-cast object did not overload get_time() method
  in superclass Item. The default method was inappropriate here and
  misinterpreted the data.
  
  Patch adds missing method; get_time() on DATE-casts now returns SQL-NULL
  on NULL input, 0 otherwise. This coincides with the way DATE-columns
  behave.
  
  Also fixes similar bug in Date-Field now.

  mysql-test/r/cast.result@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +24 -0
    Show that HOUR(), MINUTE(), ... return sensible values when used
    on DATE-cast objects, namely NULL for NULL-dates and 0 otherwise.
    Show that this coincides with how DATE-columns behave.

  mysql-test/r/type_date.result@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +5 -0
    Show that HOUR(), MINUTE(), ... return sensible values when used
    on DATE-fields.

  mysql-test/t/cast.test@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +22 -0
    Show that HOUR(), MINUTE(), ... return sensible values when used
    on DATE-cast objects, namely NULL for NULL-dates and 0 otherwise.
    Show that this coincides with how DATE-columns behave.

  mysql-test/t/type_date.test@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +8 -0
    Show that HOUR(), MINUTE(), ... return sensible values when used
    on DATE-fields.

  sql/field.cc@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +7 -0
    Add get_time() method to DATE-field object to overload
    the method in Field superclass that would return spurious
    results. Return zero-result.

  sql/field.h@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +1 -0
    Add get_time() declaration to date-field class

  sql/item_timefunc.cc@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +7 -0
    Add get_time() method to DATE-cast object to overload
    the method in Item superclass that would return spurious
    results. Return zero-result; flag NULL if input was NULL.

  sql/item_timefunc.h@stripped, 2007-12-11 10:12:04+01:00, tnurnberg@stripped +1 -0
    Add get_time() declaration to DATE-cast object.

diff -Nrup a/mysql-test/r/cast.result b/mysql-test/r/cast.result
--- a/mysql-test/r/cast.result	2007-07-19 22:05:28 +02:00
+++ b/mysql-test/r/cast.result	2007-12-11 10:12:04 +01:00
@@ -414,4 +414,28 @@ NULL
 NULL
 20070719
 drop table t1;
+CREATE TABLE t1 (f1 DATE);
+INSERT INTO t1 VALUES ('2007-07-19'), (NULL);
+SELECT HOUR(f1),
+MINUTE(f1),
+SECOND(f1) FROM t1;
+HOUR(f1)	MINUTE(f1)	SECOND(f1)
+0	0	0
+NULL	NULL	NULL
+SELECT HOUR(CAST('2007-07-19' AS DATE)),
+MINUTE(CAST('2007-07-19' AS DATE)),
+SECOND(CAST('2007-07-19' AS DATE));
+HOUR(CAST('2007-07-19' AS DATE))	MINUTE(CAST('2007-07-19' AS DATE))	SECOND(CAST('2007-07-19' AS DATE))
+0	0	0
+SELECT HOUR(CAST(NULL AS DATE)),
+MINUTE(CAST(NULL AS DATE)),
+SECOND(CAST(NULL AS DATE));
+HOUR(CAST(NULL AS DATE))	MINUTE(CAST(NULL AS DATE))	SECOND(CAST(NULL AS DATE))
+NULL	NULL	NULL
+SELECT HOUR(NULL),
+MINUTE(NULL),
+SECOND(NULL);
+HOUR(NULL)	MINUTE(NULL)	SECOND(NULL)
+NULL	NULL	NULL
+DROP TABLE t1;
 End of 5.0 tests
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-22 18:32:16 +02:00
+++ b/mysql-test/r/type_date.result	2007-12-11 10:12:04 +01:00
@@ -214,4 +214,9 @@ INSERT INTO t1 VALUES ('0000-00-00');
 ERROR 22007: Incorrect date value: '0000-00-00' for column 'a' at row 1
 SET SQL_MODE=DEFAULT;
 DROP TABLE t1,t2;
+CREATE TABLE t1 SELECT curdate() AS f1;
+SELECT hour(f1), minute(f1), second(f1) FROM t1;
+hour(f1)	minute(f1)	second(f1)
+0	0	0
+DROP TABLE t1;
 End of 5.0 tests
diff -Nrup a/mysql-test/t/cast.test b/mysql-test/t/cast.test
--- a/mysql-test/t/cast.test	2007-07-19 22:05:09 +02:00
+++ b/mysql-test/t/cast.test	2007-12-11 10:12:04 +01:00
@@ -246,4 +246,26 @@ INSERT INTO t1(d1) VALUES ('2007-07-19 0
 SELECT cast(date(d1) as signed) FROM t1;
 drop table t1;
 
+#
+# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE
+#
+
+# Show that HH:MM:SS of a DATE are 0, and that it's the same for columns
+# and typecasts (NULL in, NULL out).
+CREATE TABLE t1 (f1 DATE);
+INSERT INTO t1 VALUES ('2007-07-19'), (NULL);
+SELECT HOUR(f1),
+       MINUTE(f1),
+       SECOND(f1) FROM t1;
+SELECT HOUR(CAST('2007-07-19' AS DATE)),
+       MINUTE(CAST('2007-07-19' AS DATE)),
+       SECOND(CAST('2007-07-19' AS DATE));
+SELECT HOUR(CAST(NULL AS DATE)),
+       MINUTE(CAST(NULL AS DATE)),
+       SECOND(CAST(NULL AS DATE));
+SELECT HOUR(NULL),
+       MINUTE(NULL),
+       SECOND(NULL);
+DROP TABLE t1;
+
 --echo End of 5.0 tests
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-22 18:32:16 +02:00
+++ b/mysql-test/t/type_date.test	2007-12-11 10:12:04 +01:00
@@ -190,4 +190,12 @@ INSERT INTO t1 VALUES ('0000-00-00');
 SET SQL_MODE=DEFAULT;
 DROP TABLE t1,t2;
 
+#
+# Bug #31990: MINUTE() and SECOND() return bogus results when used on a DATE
+#
+
+CREATE TABLE t1 SELECT curdate() AS f1;
+SELECT hour(f1), minute(f1), second(f1) FROM t1;
+DROP TABLE t1;
+
 --echo End of 5.0 tests
diff -Nrup a/sql/field.cc b/sql/field.cc
--- a/sql/field.cc	2007-10-23 15:48:55 +02:00
+++ b/sql/field.cc	2007-12-11 10:12:04 +01:00
@@ -5194,6 +5194,13 @@ String *Field_date::val_str(String *val_
 }
 
 
+bool Field_date::get_time(MYSQL_TIME *ltime)
+{
+  bzero((char *)ltime, sizeof(MYSQL_TIME));
+  return 0;
+}
+
+
 int Field_date::cmp(const char *a_ptr, const char *b_ptr)
 {
   int32 a,b;
diff -Nrup a/sql/field.h b/sql/field.h
--- a/sql/field.h	2007-10-10 15:26:00 +02:00
+++ b/sql/field.h	2007-12-11 10:12:04 +01:00
@@ -933,6 +933,7 @@ public:
   double val_real(void);
   longlong val_int(void);
   String *val_str(String*,String *);
+  bool get_time(MYSQL_TIME *ltime);
   bool send_binary(Protocol *protocol);
   int cmp(const char *,const char*);
   void sort_string(char *buff,uint length);
diff -Nrup a/sql/item_timefunc.cc b/sql/item_timefunc.cc
--- a/sql/item_timefunc.cc	2007-10-18 14:19:03 +02:00
+++ b/sql/item_timefunc.cc	2007-12-11 10:12:04 +01:00
@@ -2645,6 +2645,13 @@ bool Item_date_typecast::get_date(MYSQL_
 }
 
 
+bool Item_date_typecast::get_time(MYSQL_TIME *ltime)
+{
+  bzero((char *)ltime, sizeof(MYSQL_TIME));
+  return args[0]->null_value;
+}
+
+
 String *Item_date_typecast::val_str(String *str)
 {
   DBUG_ASSERT(fixed == 1);
diff -Nrup a/sql/item_timefunc.h b/sql/item_timefunc.h
--- a/sql/item_timefunc.h	2007-10-23 15:48:56 +02:00
+++ b/sql/item_timefunc.h	2007-12-11 10:12:04 +01:00
@@ -779,6 +779,7 @@ public:
   const char *func_name() const { return "cast_as_date"; }
   String *val_str(String *str);
   bool get_date(MYSQL_TIME *ltime, uint fuzzy_date);
+  bool get_time(MYSQL_TIME *ltime);
   const char *cast_type() const { return "date"; }
   enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
   Field *tmp_table_field(TABLE *t_arg)
Thread
bk commit into 5.0 tree (tnurnberg:1.2560) BUG#31990Tatjana A Nuernberg11 Dec