diff options
author | unknown <Sinisa@sinisa.nasamreza.org> | 2001-12-29 20:56:50 +0200 |
---|---|---|
committer | unknown <Sinisa@sinisa.nasamreza.org> | 2001-12-29 20:56:50 +0200 |
commit | 19f4deb16b89ac6f771fdde1db5a2a106d8b33f7 (patch) | |
tree | 1bb77473ce3db09986b5ee160c69ca652a9744d7 /sql | |
parent | 049ded305c5838d69876ba3bef50241f4ae2558b (diff) | |
download | mariadb-git-19f4deb16b89ac6f771fdde1db5a2a106d8b33f7.tar.gz |
DATE,TIME and DATETIME SQL typecasts
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_timefunc.h | 58 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 6 |
2 files changed, 63 insertions, 1 deletions
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 0c42adb2bd2..b824174edf0 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -375,7 +375,6 @@ public: if (!t_arg) return result_field; return new Field_time(maybe_null, name, t_arg); } - }; enum interval_type { INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, @@ -414,3 +413,60 @@ class Item_extract :public Item_int_func const char *func_name() const { return "extract"; } void fix_length_and_dec(); }; + +class Item_date_typecast :public Item_str_func +{ +public: + Item_date_typecast(Item *a) :Item_str_func(a) {} + const char *func_name() const { return "date_typecast"; } + String *val_str(String *a) { return (args[0]->val_str(a)); } + void fix_length_and_dec() { max_length=args[0]->max_length; } + void print(String *str) { print_op(str); } + void make_field(Send_field *tmp_field) + { + init_make_field(tmp_field,FIELD_TYPE_DATE); + } + Field *tmp_table_field(TABLE *t_arg) + { + if (!t_arg) return result_field; + return new Field_date(maybe_null, name, t_arg); + } +}; + +class Item_time_typecast :public Item_str_func +{ +public: + Item_time_typecast(Item *a) :Item_str_func(a) {} + const char *func_name() const { return "time_typecast"; } + String *val_str(String *a) { return (args[0]->val_str(a)); } + void fix_length_and_dec() { max_length=args[0]->max_length; } + void print(String *str) { print_op(str); } + void make_field(Send_field *tmp_field) + { + init_make_field(tmp_field,FIELD_TYPE_TIME); + } + Field *tmp_table_field(TABLE *t_arg) + { + if (!t_arg) return result_field; + return new Field_time(maybe_null, name, t_arg); + } +}; + +class Item_datetime_typecast :public Item_str_func +{ +public: + Item_datetime_typecast(Item *a) :Item_str_func(a) {} + const char *func_name() const { return "datetime_typecast"; } + String *val_str(String *a) { return (args[0]->val_str(a)); } + void fix_length_and_dec() { max_length=args[0]->max_length; } + void print(String *str) { print_op(str); } + void make_field(Send_field *tmp_field) + { + init_make_field(tmp_field,FIELD_TYPE_DATETIME); + } + Field *tmp_table_field(TABLE *t_arg) + { + if (!t_arg) return result_field; + return new Field_datetime(maybe_null, name, t_arg); + } +}; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f7de9ce0b54..ed76982b12a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -486,6 +486,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); %left NEG '~' %right NOT %right BINARY +%right DATE_SYM +%right TIME_SYM +%right DATETIME %type <lex_str> IDENT TEXT_STRING REAL_NUM FLOAT_NUM NUM LONG_NUM HEX_NUM LEX_HOSTNAME @@ -1601,6 +1604,9 @@ simple_expr: { Select->ftfunc_list.push_back((Item_func_match *) ($$=new Item_func_match_bool(*$2,$5))); } | BINARY expr %prec NEG { $$= new Item_func_binary($2); } + | DATE_SYM expr { $$= new Item_date_typecast($2); } + | TIME_SYM expr { $$= new Item_time_typecast($2); } + | DATETIME expr { $$= new Item_datetime_typecast($2); } | CASE_SYM opt_expr WHEN_SYM when_list opt_else END { $$= new Item_func_case(* $4, $2, $5 ) } | FUNC_ARG0 '(' ')' |