From 45db1c24b06517b8ead23af9b455daf9db5ebe44 Mon Sep 17 00:00:00 2001 From: "gvb@phoenix.(none)" <> Date: Fri, 13 Jan 2006 14:42:46 +0100 Subject: [PATCH 1/4] fix for bug#15828 problem was not checking 2nd parameter of str_to_date against NULL --- mysql-test/r/date_formats.result | 6 ++++++ mysql-test/t/date_formats.test | 7 +++++++ sql/item_timefunc.cc | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 34a2dedd976..b2dc1f7a67b 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -464,3 +464,9 @@ d1 d2 02 February 01 January drop table t1; +select str_to_date( 1, NULL ); +str_to_date( 1, NULL ) +NULL +select str_to_date( NULL, 1 ); +str_to_date( NULL, 1 ) +NULL diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 6d501865d2c..dd31f1509c0 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -268,4 +268,11 @@ insert into t1 (f1) values ("2005-01-01"); insert into t1 (f1) values ("2005-02-01"); select date_format(f1, "%m") as d1, date_format(f1, "%M") as d2 from t1 order by date_format(f1, "%M"); drop table t1; + +# +# Bug #15828 +# +select str_to_date( 1, NULL ); +select str_to_date( NULL, 1 ); + # End of 4.1 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index eb58b180ed7..d060612c9f6 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2750,7 +2750,7 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; - if ((const_item= args[1]->const_item())) + if ((const_item= args[1]->const_item()) && !args[1]->null_value) { format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), From 421eededd316ef07b14f06a9bfd36e1f19b35d5b Mon Sep 17 00:00:00 2001 From: "gvb@phoenix.(none)" <> Date: Sat, 14 Jan 2006 09:53:12 +0100 Subject: [PATCH 2/4] item_timefunc.cc: fix for bug#15828 after review --- sql/item_timefunc.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index d060612c9f6..be8c5d2ad15 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2750,7 +2750,8 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; - if ((const_item= args[1]->const_item()) && !args[1]->null_value) + if (!args[1]->null_value && (const_item= args[1]->const_item())) + //if ((const_item= args[1]->const_item()) && !args[1]->null_value) { format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), From 8885c80da2cf5d8ac852ecbc289c62f8a5c3ff69 Mon Sep 17 00:00:00 2001 From: "gvb@phoenix.(none)" <> Date: Sat, 14 Jan 2006 16:06:51 +0100 Subject: [PATCH 3/4] item_timefunc.cc: fix for bug #15828 after review --- sql/item_timefunc.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index be8c5d2ad15..b5a9064c960 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2751,7 +2751,6 @@ void Item_func_str_to_date::fix_length_and_dec() max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; if (!args[1]->null_value && (const_item= args[1]->const_item())) - //if ((const_item= args[1]->const_item()) && !args[1]->null_value) { format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), From 8c69d6abaf9eaf731e7e589b2c3c498543003101 Mon Sep 17 00:00:00 2001 From: "gvb@phoenix.(none)" <> Date: Mon, 16 Jan 2006 15:46:37 +0100 Subject: [PATCH 4/4] date_formats.test: fix for bug #15828 after review doing val_str now before testing of null value secures the function for null values returned by dynamic functions - the fix before was incomplete andy covered constant null values --- mysql-test/r/date_formats.result | 3 +++ mysql-test/t/date_formats.test | 2 +- sql/item_timefunc.cc | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index b2dc1f7a67b..014eeed27e7 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -470,3 +470,6 @@ NULL select str_to_date( NULL, 1 ); str_to_date( NULL, 1 ) NULL +select str_to_date( 1, IF(1=1,NULL,NULL) ); +str_to_date( 1, IF(1=1,NULL,NULL) ) +NULL diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index dd31f1509c0..78b4482a94a 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -274,5 +274,5 @@ drop table t1; # select str_to_date( 1, NULL ); select str_to_date( NULL, 1 ); - +select str_to_date( 1, IF(1=1,NULL,NULL) ); # End of 4.1 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index b5a9064c960..d6b57464d59 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2750,9 +2750,9 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_STRING; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; + format= args[1]->val_str(&format_str); if (!args[1]->null_value && (const_item= args[1]->const_item())) { - format= args[1]->val_str(&format_str); cached_format_type= get_date_time_result_type(format->ptr(), format->length()); switch (cached_format_type) {