Commit f6f06ef7 authored by unknown's avatar unknown

WL#1253: LAST_DAY


mysql-test/r/func_time.result:
  Test for WL#1253: LAST_DAY
mysql-test/t/func_time.test:
  Test for WL#1253: LAST_DAY
parent 1ac15163
...@@ -468,6 +468,23 @@ select date_add(time,INTERVAL 1 SECOND) from t1; ...@@ -468,6 +468,23 @@ select date_add(time,INTERVAL 1 SECOND) from t1;
date_add(time,INTERVAL 1 SECOND) date_add(time,INTERVAL 1 SECOND)
2006-07-08 00:00:01 2006-07-08 00:00:01
drop table t1; drop table t1;
select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
last_day('2001-02-12');
f1 f2 f3 f4 f5 last_day(NULL) last_day('2001-02-12')
2000-02-29 2002-12-31 NULL 2003-04-30 2001-01-31 NULL 2001-02-28
create table t1 select last_day('2000-02-05') as a;
describe t1;
Field Type Null Key Default Extra
a date 0000-00-00
select * from t1;
a
2000-02-29
drop table t1;
select last_day('2000-02-05');
last_day('2000-02-05')
2000-02-29
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0; select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0 strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0
1 1
......
...@@ -224,6 +224,19 @@ select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1; ...@@ -224,6 +224,19 @@ select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
select date_add(time,INTERVAL 1 SECOND) from t1; select date_add(time,INTERVAL 1 SECOND) from t1;
drop table t1; drop table t1;
# test for last_day
select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
last_day('2001-02-12');
create table t1 select last_day('2000-02-05') as a;
describe t1;
select * from t1;
drop table t1;
select last_day('2000-02-05');
# Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that # Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that
# TZ variable set to GMT-3 # TZ variable set to GMT-3
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0; select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
......
...@@ -707,3 +707,8 @@ Item *create_func_str_to_date(Item* a,Item* b) ...@@ -707,3 +707,8 @@ Item *create_func_str_to_date(Item* a,Item* b)
{ {
return new Item_func_str_to_date(a, b); return new Item_func_str_to_date(a, b);
} }
Item *create_func_last_day(Item *a)
{
return new Item_func_last_day(a);
}
...@@ -150,3 +150,4 @@ Item *create_func_subtime(Item* a,Item* b); ...@@ -150,3 +150,4 @@ Item *create_func_subtime(Item* a,Item* b);
Item *create_func_timediff(Item* a,Item* b); Item *create_func_timediff(Item* a,Item* b);
Item *create_func_maketime(Item* a,Item* b,Item* c); Item *create_func_maketime(Item* a,Item* b,Item* c);
Item *create_func_str_to_date(Item* a,Item* b); Item *create_func_str_to_date(Item* a,Item* b);
Item *create_func_last_day(Item *a);
...@@ -2310,3 +2310,19 @@ String *Item_func_str_to_date::val_str(String *str) ...@@ -2310,3 +2310,19 @@ String *Item_func_str_to_date::val_str(String *str)
return str; return str;
return 0; return 0;
} }
String *Item_func_last_day::val_str(String *str)
{
TIME ltime;
if (!get_arg0_date(&ltime,0))
{
uint month_idx= ltime.month-1;
ltime.day= days_in_month[month_idx];
if ( month_idx == 1 && calc_days_in_year(ltime.year) == 366)
ltime.day+= 1;
if (!make_datetime(DATE_ONLY, &ltime, str))
return str;
}
return 0;
}
...@@ -809,3 +809,21 @@ class Item_func_str_to_date :public Item_date_func ...@@ -809,3 +809,21 @@ class Item_func_str_to_date :public Item_date_func
max_length=MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; max_length=MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
} }
}; };
class Item_func_last_day :public Item_str_func
{
public:
Item_func_last_day(Item *a) :Item_str_func(a) {}
String *val_str(String *str);
const char *func_name() const { return "last_day"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
void fix_length_and_dec()
{
decimals=0;
max_length=MAX_DATE_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
}
Field *tmp_table_field(TABLE *t_arg)
{
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
}
};
...@@ -552,6 +552,7 @@ static SYMBOL sql_functions[] = { ...@@ -552,6 +552,7 @@ static SYMBOL sql_functions[] = {
{ "IS_USED_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_used_lock)}, { "IS_USED_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_used_lock)},
{ "LAST_INSERT_ID", SYM(LAST_INSERT_ID),0,0}, { "LAST_INSERT_ID", SYM(LAST_INSERT_ID),0,0},
{ "ISSIMPLE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_issimple)}, { "ISSIMPLE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_issimple)},
{ "LAST_DAY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_last_day)},
{ "LCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)}, { "LCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)},
{ "LEAST", SYM(LEAST_SYM),0,0}, { "LEAST", SYM(LEAST_SYM),0,0},
{ "LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)}, { "LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)},
......
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