summaryrefslogtreecommitdiff
path: root/mysql-test/r/type_datetime.result
diff options
context:
space:
mode:
authorunknown <evgen@sunlight.local>2007-09-22 11:49:27 +0400
committerunknown <evgen@sunlight.local>2007-09-22 11:49:27 +0400
commitebaa05efa757c475161cb5c7f0a1adcbe9f59ff3 (patch)
tree354465c5c2b1cc824b9633a001e2a7af0fd7657e /mysql-test/r/type_datetime.result
parentffdc5b93025c487297635848d9f791822fdf09b5 (diff)
downloadmariadb-git-ebaa05efa757c475161cb5c7f0a1adcbe9f59ff3.tar.gz
Bug#27216: functions with parameters of different date types may return wrong
type of the result. There are several functions that accept parameters of different types. The result field type of such functions was determined based on the aggregated result type of its arguments. As the DATE and the DATETIME types are represented by the STRING type, the result field type of the affected functions was always STRING for DATE/DATETIME arguments. The affected functions are COALESCE, IF, IFNULL, CASE, LEAST/GREATEST, CASE. Now the affected functions aggregate the field types of their arguments rather than their result types and return the result of aggregation as their result field type. The cached_field_type member variable is added to the number of classes to hold the aggregated result field type. The str_to_date() function's result field type now defaults to the MYSQL_TYPE_DATETIME. The agg_field_type() function is added. It aggregates field types with help of the Field::field_type_merge() function. The create_table_from_items() function now uses the item->tmp_table_field_from_field_type() function to get the proper field when the item is a function with a STRING result type. libmysql/libmysql.c: Bug#27216: functions with parameters of different date types may return wrong type of the result. The client library now accepts the NEWDATE type as a string. sql/item_cmpfunc.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. Now the fix_length_and_dec functions of the Item_func_ifnull,Item_func_if, Item_func_case, Item_func_coalesce classes are use agg_field_type function to find out the type of their result field. sql/item_cmpfunc.h: Bug#27216: functions with parameters of different date types may return wrong type of the result. The cached_field type is added to the Item_func_case, Item_func_if and Item_func_coalesce classes. The field_type function is added to the Item_func_ifnull, Item_func_if, Item_func_coalesce, Item_func_case classes. sql/item_func.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The Item_func_min_max::fix_length_and_dec function now uses the agg_field_type function to find out the correct type of the result field. sql/item_func.h: Bug#27216: functions with parameters of different date types may return wrong type of the result. The cached_field_type variable is added to the Item_func_min_max class. sql/item_timefunc.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The result of the str_to_date function now defaults to the DATETIME type. sql/mysql_priv.h: Bug#27216: functions with parameters of different date types may return wrong type of the result. The prototype of the agg_field_type function is added. sql/protocol.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The Protocol_simple::store function is now used to store fields of NEWDATE type. sql/sql_insert.cc: Bug#27216: functions with parameters of different date types may return wrong type of the result. The create_table_from_items function now uses the tmp_table_field_from_field_type function to get field for items with the STRING result type. mysql-test/r/date_formats.result: A test case result corrected after fixing bug#27216. mysql-test/r/type_datetime.result: Added a test case for the bug#27216: functions with parameters of different date types may return wrong type of the result. mysql-test/t/type_datetime.test: Added a test case for the bug#27216: functions with parameters of different date types may return wrong type of the result.
Diffstat (limited to 'mysql-test/r/type_datetime.result')
-rw-r--r--mysql-test/r/type_datetime.result61
1 files changed, 61 insertions, 0 deletions
diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result
index 9e47b5da2b6..c58ce3401fb 100644
--- a/mysql-test/r/type_datetime.result
+++ b/mysql-test/r/type_datetime.result
@@ -427,3 +427,64 @@ f1
Warnings:
Warning 1292 Incorrect datetime value: '2007010100000' for column 'f1' at row 1
drop table t1;
+#
+# Bug#27216: functions with parameters of different date types may
+# return wrong type of the result.
+#
+create table t1 (f1 date, f2 datetime, f3 varchar(20));
+create table t2 as select coalesce(f1,f1) as f4 from t1;
+desc t2;
+Field Type Null Key Default Extra
+f4 date YES NULL
+create table t3 as select coalesce(f1,f2) as f4 from t1;
+desc t3;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t4 as select coalesce(f2,f2) as f4 from t1;
+desc t4;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t5 as select coalesce(f1,f3) as f4 from t1;
+desc t5;
+Field Type Null Key Default Extra
+f4 varbinary(20) YES NULL
+create table t6 as select coalesce(f2,f3) as f4 from t1;
+desc t6;
+Field Type Null Key Default Extra
+f4 varbinary(20) YES NULL
+create table t7 as select coalesce(makedate(1997,1),f2) as f4 from t1;
+desc t7;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t8 as select coalesce(cast('01-01-01' as datetime),f2) as f4
+from t1;
+desc t8;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t9 as select case when 1 then cast('01-01-01' as date)
+when 0 then cast('01-01-01' as date) end as f4 from t1;
+desc t9;
+Field Type Null Key Default Extra
+f4 date YES NULL
+create table t10 as select case when 1 then cast('01-01-01' as datetime)
+when 0 then cast('01-01-01' as datetime) end as f4 from t1;
+desc t10;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t11 as select if(1, cast('01-01-01' as datetime),
+cast('01-01-01' as date)) as f4 from t1;
+desc t11;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t12 as select least(cast('01-01-01' as datetime),
+cast('01-01-01' as date)) as f4 from t1;
+desc t12;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+create table t13 as select ifnull(cast('01-01-01' as datetime),
+cast('01-01-01' as date)) as f4 from t1;
+desc t13;
+Field Type Null Key Default Extra
+f4 datetime YES NULL
+drop tables t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13;
+###################################################################