Commit 51e3375b authored by unknown's avatar unknown

DATE,TIME and DATETIME SQL typecasts

parent f7c69e6d
......@@ -86,4 +86,11 @@ c date 0000-00-00
d bigint(17) 0
e double(18,1) 0.0
f bigint(17) 0
drop table t2;
create table t2 select DATE "2001-12-29" as d, TIME "20:45:11" as t, DATETIME "2001-12-29 20:45:11" as dt;
describe t2;
Field Type Null Key Default Extra
d date 0000-00-00
t time 00:00:00
dt datetime 0000-00-00 00:00:00
drop table t1,t2;
......@@ -77,4 +77,7 @@ describe t2;
drop table t2;
create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f;
describe t2;
drop table t2;
create table t2 select DATE "2001-12-29" as d, TIME "20:45:11" as t, DATETIME "2001-12-29 20:45:11" as dt;
describe t2;
drop table t1,t2;
......@@ -375,7 +375,6 @@ class Item_func_sec_to_time :public Item_str_func
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);
}
};
......@@ -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 '(' ')'
......
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