summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorgluh@gluh.mysql.r18.ru <>2003-11-17 18:02:08 +0400
committergluh@gluh.mysql.r18.ru <>2003-11-17 18:02:08 +0400
commit5ade64831eabf6c5e99df9890f7c8fded2b710d0 (patch)
tree1938e6b15b2f83f5ed4daaaf3037a102080b9eb6 /sql
parenta1199c7749954679b278591046b86ffeb65be0e1 (diff)
downloadmariadb-git-5ade64831eabf6c5e99df9890f7c8fded2b710d0.tar.gz
WL#1253: LAST_DAY
Diffstat (limited to 'sql')
-rw-r--r--sql/item_create.cc5
-rw-r--r--sql/item_create.h1
-rw-r--r--sql/item_timefunc.cc16
-rw-r--r--sql/item_timefunc.h18
-rw-r--r--sql/lex.h3
5 files changed, 42 insertions, 1 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 5c44d8b00ff..0195f0c24bc 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -707,3 +707,8 @@ Item *create_func_str_to_date(Item* a,Item* b)
{
return new Item_func_str_to_date(a, b);
}
+
+Item *create_func_last_day(Item *a)
+{
+ return new Item_func_last_day(a);
+}
diff --git a/sql/item_create.h b/sql/item_create.h
index 5d6cbe1d58f..083868d87a6 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -150,3 +150,4 @@ Item *create_func_subtime(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_str_to_date(Item* a,Item* b);
+Item *create_func_last_day(Item *a);
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index cf71f2b3bef..bcb7ddb1054 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2310,3 +2310,19 @@ String *Item_func_str_to_date::val_str(String *str)
return str;
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;
+}
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index ef7fa1abfa0..a81b9f28d92 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -809,3 +809,21 @@ public:
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));
+ }
+};
diff --git a/sql/lex.h b/sql/lex.h
index 7f3328fa7cb..fd13af348d1 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -551,7 +551,8 @@ static SYMBOL sql_functions[] = {
{ "IS_FREE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_free_lock)},
{ "IS_USED_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_used_lock)},
{ "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)},
{ "LEAST", SYM(LEAST_SYM),0,0},
{ "LENGTH", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_length)},