Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
1e3bd842
Commit
1e3bd842
authored
Dec 29, 2001
by
Sinisa@sinisa.nasamreza.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DATE,TIME and DATETIME SQL typecasts
parent
2977d218
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
1 deletion
+73
-1
mysql-test/r/create.result
mysql-test/r/create.result
+7
-0
mysql-test/t/create.test
mysql-test/t/create.test
+3
-0
sql/item_timefunc.h
sql/item_timefunc.h
+57
-1
sql/sql_yacc.yy
sql/sql_yacc.yy
+6
-0
No files found.
mysql-test/r/create.result
View file @
1e3bd842
...
...
@@ -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;
mysql-test/t/create.test
View file @
1e3bd842
...
...
@@ -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
;
sql/item_timefunc.h
View file @
1e3bd842
...
...
@@ -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
);
}
};
sql/sql_yacc.yy
View file @
1e3bd842
...
...
@@ -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 '(' ')'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment