summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <Sinisa@sinisa.nasamreza.org>2001-12-29 20:56:50 +0200
committerunknown <Sinisa@sinisa.nasamreza.org>2001-12-29 20:56:50 +0200
commit51e3375b0d112990a9f6bc3d6151bdf977fffc45 (patch)
tree1bb77473ce3db09986b5ee160c69ca652a9744d7
parentf7c69e6dc5da8f76e2f08193edf868455ce617db (diff)
downloadmariadb-git-51e3375b0d112990a9f6bc3d6151bdf977fffc45.tar.gz
DATE,TIME and DATETIME SQL typecasts
-rw-r--r--mysql-test/r/create.result7
-rw-r--r--mysql-test/t/create.test3
-rw-r--r--sql/item_timefunc.h58
-rw-r--r--sql/sql_yacc.yy6
4 files changed, 73 insertions, 1 deletions
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result
index da0cb693be9..21c2f1efaf4 100644
--- a/mysql-test/r/create.result
+++ b/mysql-test/r/create.result
@@ -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;
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test
index d07c1b920d4..b5282757c51 100644
--- a/mysql-test/t/create.test
+++ b/mysql-test/t/create.test
@@ -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;
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 '(' ')'