Commit b1ae4e7e authored by Alexander Barkov's avatar Alexander Barkov

MDEV-16864 Implement class Item_func_timestamp

parent 2bbee0e1
......@@ -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));
......
......@@ -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);
}
......
......@@ -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.
......
......@@ -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 @@ class Item_func_makedate :public Item_datefunc
};
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(&ltime2) ||
Sec6_add(dt.get_mysql_time(), &ltime2, 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); }
};
......
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment