From e0f0507f999a35362e19ff0d80b3fd2565c83d7c Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Thu, 22 Mar 2007 12:24:56 +0400 Subject: [PATCH] bug #16546 (DATETIME + 0 not always coerced in the same way) fix for cast( AS DATETIME) + 0 operation. I just implemented Item_datetime_typecast::val() method as it is usually done in other classes. Should be fixed more radically in 5.0 --- mysql-test/r/type_datetime.result | 3 +++ mysql-test/t/type_datetime.test | 6 ++++++ sql/item_timefunc.h | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index f313a6b934b..64337bd2c2f 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -166,3 +166,6 @@ dt 0000-00-00 00:00:00 0000-00-00 00:00:00 drop table t1; +select cast('2006-12-05 22:10:10' as datetime) + 0; +cast('2006-12-05 22:10:10' as datetime) + 0 +20061205221010.000000 diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index 4b6741b4242..87b86b55fc9 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -113,4 +113,10 @@ insert into t1 values ("00-00-00"), ("00-00-00 00:00:00"); select * from t1; drop table t1; +# +# Bug #16546 DATETIME+0 not always coerced the same way +# +select cast('2006-12-05 22:10:10' as datetime) + 0; + + # End of 4.1 tests diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 45cad627c05..2383b4f86ac 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -751,12 +751,19 @@ public: String *val_str(String *str); const char *cast_type() const { return "datetime"; } enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } + void fix_length_and_dec() + { + Item_typecast_maybe_null::fix_length_and_dec(); + decimals= DATETIME_DEC; + } + Field *tmp_table_field(TABLE *t_arg) { return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin)); } bool result_as_longlong() { return TRUE; } longlong val_int(); + double val() { return (double) val_int(); } }; class Item_func_makedate :public Item_str_func