diff options
-rw-r--r-- | mysql-test/main/gis.result | 12 | ||||
-rw-r--r-- | sql/item_create.cc | 4 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 24 | ||||
-rw-r--r-- | sql/item_timefunc.h | 46 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 2 |
6 files changed, 50 insertions, 40 deletions
diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result index 01e724eed87..886b1b5f6a8 100644 --- a/mysql-test/main/gis.result +++ b/mysql-test/main/gis.result @@ -4128,17 +4128,17 @@ ERROR HY000: Illegal parameter data types geometry and interval for operation 'd SELECT INTERVAL 10 DAY + POINT(1,1); ERROR HY000: Illegal parameter data types geometry and interval for operation 'date_add_interval' SELECT ADDTIME(POINT(1,1), '10:10:10'); -ERROR HY000: Illegal parameter data types geometry and varchar for operation 'add_time' +ERROR HY000: Illegal parameter data types geometry and varchar for operation 'addtime' SELECT ADDTIME('10:10:10', POINT(1,1)); -ERROR HY000: Illegal parameter data types varchar and geometry for operation 'add_time' +ERROR HY000: Illegal parameter data types varchar and geometry for operation 'addtime' SELECT ADDTIME(POINT(1,1), TIME'10:10:10'); -ERROR HY000: Illegal parameter data types geometry and time for operation 'add_time' +ERROR HY000: Illegal parameter data types geometry and time for operation 'addtime' SELECT ADDTIME(TIME'10:10:10', POINT(1,1)); -ERROR HY000: Illegal parameter data types time and geometry for operation 'add_time' +ERROR HY000: Illegal parameter data types time and geometry for operation 'addtime' SELECT ADDTIME(POINT(1,1), TIMESTAMP'2001-01-01 10:10:10'); -ERROR HY000: Illegal parameter data types geometry and datetime for operation 'add_time' +ERROR HY000: Illegal parameter data types geometry and datetime for operation 'addtime' SELECT ADDTIME(TIMESTAMP'2001-01-01 10:10:10', POINT(1,1)); -ERROR HY000: Illegal parameter data types datetime and geometry for operation 'add_time' +ERROR HY000: Illegal parameter data types datetime and geometry for operation 'addtime' SELECT STR_TO_DATE(POINT(1,1),'%M %d,%Y'); ERROR HY000: Illegal parameter data types geometry and varchar for operation 'str_to_date' SELECT STR_TO_DATE('2001-01-01', POINT(1,1)); diff --git a/sql/item_create.cc b/sql/item_create.cc index 80cb830c584..d9b007d4728 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -3636,7 +3636,7 @@ Create_func_addtime Create_func_addtime::s_singleton; Item* Create_func_addtime::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_add_time(thd, arg1, arg2, 0, 0); + return new (thd->mem_root) Item_func_add_time(thd, arg1, arg2, false); } @@ -6657,7 +6657,7 @@ Create_func_subtime Create_func_subtime::s_singleton; Item* Create_func_subtime::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_add_time(thd, arg1, arg2, 0, 1); + return new (thd->mem_root) Item_func_add_time(thd, arg1, arg2, true); } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index f040e8a4a41..789297f0c7f 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2698,8 +2698,7 @@ bool Item_func_add_time::fix_length_and_dec() arg0_field_type= args[0]->field_type(); if (arg0_field_type == MYSQL_TYPE_DATE || arg0_field_type == MYSQL_TYPE_DATETIME || - arg0_field_type == MYSQL_TYPE_TIMESTAMP || - is_date) + arg0_field_type == MYSQL_TYPE_TIMESTAMP) { uint dec= MY_MAX(args[0]->datetime_precision(), args[1]->time_precision()); set_handler(&type_handler_datetime2); @@ -2767,27 +2766,6 @@ bool Item_func_add_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) } -void Item_func_add_time::print(String *str, enum_query_type query_type) -{ - if (is_date) - { - DBUG_ASSERT(sign > 0); - str->append(STRING_WITH_LEN("timestamp(")); - } - else - { - if (sign > 0) - str->append(STRING_WITH_LEN("addtime(")); - else - str->append(STRING_WITH_LEN("subtime(")); - } - args[0]->print(str, query_type); - str->append(','); - args[1]->print(str, query_type); - str->append(')'); -} - - /** TIMEDIFF(t,s) is a time function that calculates the time value between a start and end time. diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 58392dacceb..a7bdbc8a76b 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -667,6 +667,8 @@ class Item_datetimefunc :public Item_temporal_func public: Item_datetimefunc(THD *thd): Item_temporal_func(thd) {} Item_datetimefunc(THD *thd, Item *a): Item_temporal_func(thd, a) {} + Item_datetimefunc(THD *thd, Item *a, Item *b): + Item_temporal_func(thd, a, b) {} Item_datetimefunc(THD *thd, Item *a, Item *b, Item *c): Item_temporal_func(thd, a, b ,c) {} const Type_handler *type_handler() const { return &type_handler_datetime2; } @@ -1229,19 +1231,49 @@ public: }; +class Item_func_timestamp :public Item_datetimefunc +{ + bool check_arguments() const + { + return args[0]->check_type_can_return_date(func_name()) || + args[1]->check_type_can_return_time(func_name()); + } +public: + Item_func_timestamp(THD *thd, Item *a, Item *b) + :Item_datetimefunc(thd, a, b) + { } + const char *func_name() const { return "timestamp"; } + bool fix_length_and_dec() + { + uint dec= MY_MAX(args[0]->datetime_precision(), args[1]->time_precision()); + fix_attributes_datetime(dec); + maybe_null= true; + return false; + } + bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) + { + Datetime dt(current_thd, args[0], 0); + MYSQL_TIME ltime2; + return (null_value= (!dt.is_valid_datetime() || + args[1]->get_time(<ime2) || + Sec6_add(dt.get_mysql_time(), <ime2, 1). + to_datetime(ltime))); + } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_timestamp>(thd, this); } +}; + + class Item_func_add_time :public Item_temporal_hybrid_func { - const bool is_date; int sign; - public: - Item_func_add_time(THD *thd, Item *a, Item *b, bool type_arg, bool neg_arg): - Item_temporal_hybrid_func(thd, a, b), is_date(type_arg) - { sign= neg_arg ? -1 : 1; } + Item_func_add_time(THD *thd, Item *a, Item *b, bool neg_arg) + :Item_temporal_hybrid_func(thd, a, b), sign(neg_arg ? -1 : 1) + { } bool fix_length_and_dec(); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date); - void print(String *str, enum_query_type query_type); - const char *func_name() const { return "add_time"; } + const char *func_name() const { return sign > 0 ? "addtime" : "subtime"; } Item *get_copy(THD *thd) { return get_item_copy<Item_func_add_time>(thd, this); } }; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index c484af0fb78..cf894325ba5 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -10216,7 +10216,7 @@ function_call_keyword_timestamp: } | TIMESTAMP '(' expr ',' expr ')' { - $$= new (thd->mem_root) Item_func_add_time(thd, $3, $5, 1, 0); + $$= new (thd->mem_root) Item_func_timestamp(thd, $3, $5); if (unlikely($$ == NULL)) MYSQL_YYABORT; } diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 6397654bc7d..ef12b9c0c53 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -10413,7 +10413,7 @@ function_call_keyword_timestamp: } | TIMESTAMP '(' expr ',' expr ')' { - $$= new (thd->mem_root) Item_func_add_time(thd, $3, $5, 1, 0); + $$= new (thd->mem_root) Item_func_timestamp(thd, $3, $5); if (unlikely($$ == NULL)) MYSQL_YYABORT; } |