Commit 1d9532cd authored by Alexander Barkov's avatar Alexander Barkov Committed by Marko Mäkelä

After-merge cleanup

parent 5ab70e7f
......@@ -1091,22 +1091,13 @@ longlong Item_func_yearweek::val_int()
}
static uint weekday_from_item(Item *item, bool *null_value, bool week_starts_on_sunday)
{
MYSQL_TIME ltime;
if ((*null_value= Datetime(current_thd, item,
TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE).
copy_to_mysql_time(&ltime, MYSQL_TIMESTAMP_DATETIME)))
return 0;
return calc_weekday(calc_daynr(ltime.year, ltime.month, ltime.day), week_starts_on_sunday) +
MY_TEST(week_starts_on_sunday);
}
longlong Item_func_weekday::val_int()
{
DBUG_ASSERT(fixed == 1);
return (longlong) weekday_from_item(args[0], &null_value, odbc_type);
Datetime dt(current_thd, args[0], TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE);
if ((null_value= !dt.is_valid_datetime()))
return 0;
return dt.weekday(odbc_type) + MY_TEST(odbc_type);
}
bool Item_func_dayname::fix_length_and_dec()
......@@ -1125,14 +1116,14 @@ bool Item_func_dayname::fix_length_and_dec()
String* Item_func_dayname::val_str(String* str)
{
DBUG_ASSERT(fixed == 1);
uint weekday= weekday_from_item(args[0], &null_value, false);
const char *day_name;
uint err;
Datetime dt(current_thd, args[0], TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE);
if (null_value)
if ((null_value= !dt.is_valid_datetime()))
return (String*) 0;
day_name= locale->day_names->type_names[weekday];
day_name= locale->day_names->type_names[dt.weekday(false)];
str->copy(day_name, (uint) strlen(day_name), &my_charset_utf8_bin,
collation.collation, &err);
return str;
......
......@@ -426,12 +426,12 @@ class Item_func_year :public Item_long_func_date_field
};
class Item_func_weekday :public Item_int_func
class Item_func_weekday :public Item_long_func
{
bool odbc_type;
public:
Item_func_weekday(THD *thd, Item *a, bool type_arg):
Item_int_func(thd, a), odbc_type(type_arg) { }
Item_long_func(thd, a), odbc_type(type_arg) { }
longlong val_int();
const char *func_name() const
{
......@@ -441,7 +441,6 @@ class Item_func_weekday :public Item_int_func
{
return type_handler()->Item_get_date(this, ltime, fuzzydate);
}
const Type_handler *type_handler() const { return &type_handler_long; }
bool fix_length_and_dec()
{
decimals= 0;
......
......@@ -292,6 +292,15 @@ class Temporal_with_date: protected MYSQL_TIME
{
protected:
void make_from_item(THD *thd, Item *item, sql_mode_t flags);
ulong daynr() const
{
return (ulong) ::calc_daynr((uint) year, (uint) month, (uint) day);
}
int weekday(bool sunday_first_day_of_week) const
{
return ::calc_weekday(daynr(), sunday_first_day_of_week);
}
Temporal_with_date(THD *thd, Item *item, sql_mode_t flags)
{
make_from_item(thd, item, flags);
......@@ -389,6 +398,11 @@ class Datetime: public Temporal_with_date
DBUG_ASSERT(is_valid_datetime_slow());
return hour == 0 && minute == 0 && second == 0 && second_part == 0;
}
int weekday(bool sunday_first_day_of_week) const
{
DBUG_ASSERT(is_valid_datetime_slow());
return Temporal_with_date::weekday(sunday_first_day_of_week);
}
const MYSQL_TIME *get_mysql_time() const
{
DBUG_ASSERT(is_valid_datetime_slow());
......
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