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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
5709ed20
Commit
5709ed20
authored
Jul 08, 2003
by
gluh@gluh.mysql.r18.ru
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SAPDB date/time finctions
parent
e6eef748
Changes
12
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
238 additions
and
236 deletions
+238
-236
mysql-test/r/cast.result
mysql-test/r/cast.result
+2
-2
mysql-test/r/func_sapdb.result
mysql-test/r/func_sapdb.result
+9
-3
mysql-test/t/func_sapdb.test
mysql-test/t/func_sapdb.test
+4
-2
sql/item_create.cc
sql/item_create.cc
+2
-2
sql/item_timefunc.cc
sql/item_timefunc.cc
+162
-160
sql/item_timefunc.h
sql/item_timefunc.h
+18
-64
sql/mysql_priv.h
sql/mysql_priv.h
+2
-0
sql/protocol.cc
sql/protocol.cc
+13
-0
sql/sql_string.cc
sql/sql_string.cc
+17
-0
sql/sql_string.h
sql/sql_string.h
+2
-0
sql/sql_yacc.yy
sql/sql_yacc.yy
+6
-3
sql/time.cc
sql/time.cc
+1
-0
No files found.
mysql-test/r/cast.result
View file @
5709ed20
...
...
@@ -44,10 +44,10 @@ t1 CREATE TABLE `t1` (
drop table t1;
select cast("2001-1-1" as date) = "2001-01-01";
cast("2001-1-1" as date) = "2001-01-01"
0
1
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"
0
1
select cast("1:2:3" as TIME) = "1:02:03";
cast("1:2:3" as TIME) = "1:02:03"
0
...
...
mysql-test/r/func_sapdb.result
View file @
5709ed20
...
...
@@ -101,8 +101,8 @@ timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002")
select timediff("1997-12-31 23:59:59.000001","23:59:59.000001");
timediff("1997-12-31 23:59:59.000001","23:59:59.000001")
NULL
select timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.1");
timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.1")
select timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.
00000
1");
timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.
00000
1")
-00:00:00.000001
select maketime(10,11,12);
maketime(10,11,12)
...
...
@@ -122,6 +122,12 @@ NULL
select timestamp("2001-12-01", "25:01:01");
timestamp("2001-12-01", "25:01:01")
2001-12-02 01:01:01
select timestamp("2001-12-01 01:01:01.000100");
timestamp("2001-12-01 01:01:01.000100")
2001-12-01 01:01:01.000100
select timestamp("2001-12-01");
timestamp("2001-12-01")
2001-12-01 00:00:00
select day("1997-12-31 23:59:59.000001");
day("1997-12-31 23:59:59.000001")
31
...
...
@@ -147,7 +153,7 @@ addtime(cast("23:59:59.999999" as time) , "1 1:1:1.000002") as f3,
timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002") as f4,
timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002") as f5,
maketime(10,11,12) as f6,
timestamp(
"2001-12-01"
, "01:01:01") as f7,
timestamp(
cast("2001-12-01" as date)
, "01:01:01") as f7,
date("1997-12-31 23:59:59.000001") as f8,
time("1997-12-31 23:59:59.000001") as f9;
describe t1;
...
...
mysql-test/t/func_sapdb.test
View file @
5709ed20
...
...
@@ -51,7 +51,7 @@ select timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002");
select
timediff
(
"1997-12-31 23:59:59.000001"
,
"1997-12-30 01:01:01.000002"
);
select
timediff
(
"1997-12-30 23:59:59.000001"
,
"1997-12-31 23:59:59.000002"
);
select
timediff
(
"1997-12-31 23:59:59.000001"
,
"23:59:59.000001"
);
select
timediff
(
"2000:01:01 00:00:00"
,
"2000:01:01 00:00:00.1"
);
select
timediff
(
"2000:01:01 00:00:00"
,
"2000:01:01 00:00:00.
00000
1"
);
select
maketime
(
10
,
11
,
12
);
select
maketime
(
25
,
11
,
12
);
...
...
@@ -61,6 +61,8 @@ select maketime(-25,11,12);
select
timestamp
(
"2001-12-01"
,
"01:01:01.999999"
);
select
timestamp
(
"2001-13-01"
,
"01:01:01.000001"
);
select
timestamp
(
"2001-12-01"
,
"25:01:01"
);
select
timestamp
(
"2001-12-01 01:01:01.000100"
);
select
timestamp
(
"2001-12-01"
);
select
day
(
"1997-12-31 23:59:59.000001"
);
select
date
(
"1997-12-31 23:59:59.000001"
);
select
date
(
"1997-13-31 23:59:59.000001"
);
...
...
@@ -75,7 +77,7 @@ select makedate(1997,1) as f1,
timediff
(
"1997-12-31 23:59:59.000001"
,
"1997-12-30 01:01:01.000002"
)
as
f4
,
timediff
(
"1997-12-30 23:59:59.000001"
,
"1997-12-31 23:59:59.000002"
)
as
f5
,
maketime
(
10
,
11
,
12
)
as
f6
,
timestamp
(
"2001-12-01"
,
"01:01:01"
)
as
f7
,
timestamp
(
cast
(
"2001-12-01"
as
date
)
,
"01:01:01"
)
as
f7
,
date
(
"1997-12-31 23:59:59.000001"
)
as
f8
,
time
(
"1997-12-31 23:59:59.000001"
)
as
f9
;
describe
t1
;
...
...
sql/item_create.cc
View file @
5709ed20
...
...
@@ -709,12 +709,12 @@ Item *create_func_makedate(Item* a,Item* b)
Item
*
create_func_addtime
(
Item
*
a
,
Item
*
b
)
{
return
new
Item_func_add_time
(
a
,
b
,
0
);
return
new
Item_func_add_time
(
a
,
b
,
0
,
0
);
}
Item
*
create_func_subtime
(
Item
*
a
,
Item
*
b
)
{
return
new
Item_func_add_time
(
a
,
b
,
1
);
return
new
Item_func_add_time
(
a
,
b
,
0
,
1
);
}
Item
*
create_func_timediff
(
Item
*
a
,
Item
*
b
)
...
...
sql/item_timefunc.cc
View file @
5709ed20
This diff is collapsed.
Click to expand it.
sql/item_timefunc.h
View file @
5709ed20
...
...
@@ -557,6 +557,8 @@ class Item_date_typecast :public Item_typecast
{
public:
Item_date_typecast
(
Item
*
a
)
:
Item_typecast
(
a
)
{}
String
*
val_str
(
String
*
str
);
bool
get_date
(
TIME
*
ltime
,
bool
fuzzy_date
);
const
char
*
func_name
()
const
{
return
"date"
;
}
enum_field_types
field_type
()
const
{
return
MYSQL_TYPE_DATE
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
...
...
@@ -571,6 +573,8 @@ class Item_time_typecast :public Item_typecast
{
public:
Item_time_typecast
(
Item
*
a
)
:
Item_typecast
(
a
)
{}
String
*
val_str
(
String
*
str
);
bool
get_time
(
TIME
*
ltime
);
const
char
*
func_name
()
const
{
return
"time"
;
}
enum_field_types
field_type
()
const
{
return
MYSQL_TYPE_TIME
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
...
...
@@ -585,6 +589,7 @@ class Item_datetime_typecast :public Item_typecast
{
public:
Item_datetime_typecast
(
Item
*
a
)
:
Item_typecast
(
a
)
{}
String
*
val_str
(
String
*
str
);
const
char
*
func_name
()
const
{
return
"datetime"
;
}
enum_field_types
field_type
()
const
{
return
MYSQL_TYPE_DATETIME
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
...
...
@@ -604,7 +609,7 @@ class Item_func_makedate :public Item_str_func
void
fix_length_and_dec
()
{
decimals
=
0
;
max_length
=
8
*
my_charset_bin
.
mbmaxlen
;
max_length
=
8
*
MY_CHARSET_BIN_MB_MAXLEN
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
...
...
@@ -613,18 +618,26 @@ class Item_func_makedate :public Item_str_func
}
};
class
Item_func_add_time
:
public
Item_str_func
{
const
bool
is_date
;
int
sign
;
enum_field_types
cached_field_type
;
public:
Item_func_add_time
(
Item
*
a
,
Item
*
b
,
bool
neg_arg
)
:
Item_str_func
(
a
,
b
)
{
sign
=
neg_arg
?
-
1
:
1
;
}
Item_func_add_time
(
Item
*
a
,
Item
*
b
,
bool
type_arg
,
bool
neg_arg
)
:
Item_str_func
(
a
,
b
)
,
is_date
(
type_arg
)
{
sign
=
neg_arg
?
-
1
:
1
;
}
String
*
val_str
(
String
*
str
);
const
char
*
func_name
()
const
{
return
"addtime"
;
}
enum_field_types
field_type
()
const
{
return
cached_field_type
;
}
void
fix_length_and_dec
();
/*
TODO:
Change this when we support
microseconds in TIME/DATETIME
*/
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
{
...
...
@@ -647,7 +660,7 @@ class Item_func_timediff :public Item_str_func
void
fix_length_and_dec
()
{
decimals
=
0
;
max_length
=
17
*
my_charset_bin
.
mbmaxlen
;
max_length
=
17
*
MY_CHARSET_BIN_MB_MAXLEN
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
...
...
@@ -667,66 +680,7 @@ class Item_func_maketime :public Item_str_func
void
fix_length_and_dec
()
{
decimals
=
0
;
max_length
=
8
*
my_charset_bin
.
mbmaxlen
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
{
return
(
new
Field_time
(
maybe_null
,
name
,
t_arg
,
&
my_charset_bin
));
}
};
class
Item_func_timestamp
:
public
Item_str_func
{
public:
Item_func_timestamp
(
Item
*
a
,
Item
*
b
)
:
Item_str_func
(
a
,
b
)
{}
String
*
val_str
(
String
*
str
);
const
char
*
func_name
()
const
{
return
"timestamp"
;
}
enum_field_types
field_type
()
const
{
return
MYSQL_TYPE_DATETIME
;
}
void
fix_length_and_dec
()
{
decimals
=
0
;
max_length
=
26
*
my_charset_bin
.
mbmaxlen
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
{
return
(
new
Field_datetime
(
maybe_null
,
name
,
t_arg
,
&
my_charset_bin
));
}
};
class
Item_func_date
:
public
Item_str_func
{
public:
Item_func_date
(
Item
*
a
)
:
Item_str_func
(
a
)
{}
String
*
val_str
(
String
*
str
);
const
char
*
func_name
()
const
{
return
"date"
;
}
enum_field_types
field_type
()
const
{
return
MYSQL_TYPE_DATE
;
}
void
fix_length_and_dec
()
{
decimals
=
0
;
max_length
=
10
*
my_charset_bin
.
mbmaxlen
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
{
return
(
new
Field_date
(
maybe_null
,
name
,
t_arg
,
&
my_charset_bin
));
}
};
class
Item_func_time
:
public
Item_str_func
{
public:
Item_func_time
(
Item
*
a
)
:
Item_str_func
(
a
)
{}
String
*
val_str
(
String
*
str
);
const
char
*
func_name
()
const
{
return
"time"
;
}
enum_field_types
field_type
()
const
{
return
MYSQL_TYPE_TIME
;
}
void
fix_length_and_dec
()
{
decimals
=
0
;
max_length
=
15
*
my_charset_bin
.
mbmaxlen
;
max_length
=
8
*
MY_CHARSET_BIN_MB_MAXLEN
;
}
Field
*
tmp_table_field
()
{
return
result_field
;
}
Field
*
tmp_table_field
(
TABLE
*
t_arg
)
...
...
sql/mysql_priv.h
View file @
5709ed20
...
...
@@ -224,6 +224,8 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
#define RAID_BLOCK_SIZE 1024
#define MY_CHARSET_BIN_MB_MAXLEN 1
#ifdef EXTRA_DEBUG
/*
Sync points allow us to force the server to reach a certain line of code
...
...
sql/protocol.cc
View file @
5709ed20
...
...
@@ -823,6 +823,13 @@ bool Protocol_simple::store(Field *field)
}
/*
TODO:
Second_part format ("%06") needs to change when
we support 0-6 decimals for time.
*/
bool
Protocol_simple
::
store
(
TIME
*
tm
)
{
#ifndef DEBUG_OFF
...
...
@@ -863,6 +870,12 @@ bool Protocol_simple::store_date(TIME *tm)
}
/*
TODO:
Second_part format ("%06") needs to change when
we support 0-6 decimals for time.
*/
bool
Protocol_simple
::
store_time
(
TIME
*
tm
)
{
#ifndef DEBUG_OFF
...
...
sql/sql_string.cc
View file @
5709ed20
...
...
@@ -390,6 +390,23 @@ bool String::append(IO_CACHE* file, uint32 arg_length)
return
FALSE
;
}
bool
String
::
append_with_prefill
(
const
char
*
s
,
uint32
arg_length
,
uint32
full_length
,
char
fill_char
)
{
int
t_length
=
arg_length
>
full_length
?
arg_length
:
full_length
;
if
(
realloc
(
str_length
+
t_length
))
return
TRUE
;
t_length
=
full_length
-
arg_length
;
if
(
t_length
>
0
)
{
bfill
(
Ptr
+
str_length
,
t_length
,
fill_char
);
str_length
=
str_length
+
t_length
;
}
append
(
s
,
arg_length
);
return
FALSE
;
}
uint32
String
::
numchars
()
{
return
str_charset
->
cset
->
numchars
(
str_charset
,
Ptr
,
Ptr
+
str_length
);
...
...
sql/sql_string.h
View file @
5709ed20
...
...
@@ -189,6 +189,8 @@ class String
bool
append
(
const
char
*
s
,
uint32
arg_length
=
0
);
bool
append
(
const
char
*
s
,
uint32
arg_length
,
CHARSET_INFO
*
cs
);
bool
append
(
IO_CACHE
*
file
,
uint32
arg_length
);
bool
append_with_prefill
(
const
char
*
s
,
uint32
arg_length
,
uint32
full_length
,
char
fill_char
);
int
strstr
(
const
String
&
search
,
uint32
offset
=
0
);
// Returns offset to substring or -1
int
strstr_case
(
const
String
&
s
,
uint32
offset
=
0
);
int
strrstr
(
const
String
&
search
,
uint32
offset
=
0
);
// Returns offset to substring or -1
...
...
sql/sql_yacc.yy
View file @
5709ed20
...
...
@@ -2381,7 +2381,7 @@ simple_expr:
Lex->safe_to_cache_query=0;
}
| DATE_SYM '(' expr ')'
{ $$= new Item_
func_date
($3); }
{ $$= new Item_
date_typecast
($3); }
| DAY_SYM '(' expr ')'
{ $$= new Item_func_dayofmonth($3); }
| ELT_FUNC '(' expr ',' expr_list ')'
...
...
@@ -2580,9 +2580,11 @@ simple_expr:
| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_substr_index($3,$5,$7); }
| TIME_SYM '(' expr ')'
{ $$= new Item_func_time($3); }
{ $$= new Item_time_typecast($3); }
| TIMESTAMP '(' expr ')'
{ $$= new Item_datetime_typecast($3); }
| TIMESTAMP '(' expr ',' expr ')'
{ $$= new Item_func_
timestamp($3, $5
); }
{ $$= new Item_func_
add_time($3, $5, 1, 0
); }
| TRIM '(' expr ')'
{ $$= new Item_func_trim($3); }
| TRIM '(' LEADING expr FROM expr ')'
...
...
@@ -4427,6 +4429,7 @@ keyword:
| MEDIUM_SYM {}
| MERGE_SYM {}
| MEMORY_SYM {}
| MICROSECOND_SYM {}
| MINUTE_SYM {}
| MIN_ROWS {}
| MODIFY_SYM {}
...
...
sql/time.cc
View file @
5709ed20
...
...
@@ -432,6 +432,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
l_time
->
minute
=
date
[
4
];
l_time
->
second
=
date
[
5
];
l_time
->
second_part
=
date
[
6
];
l_time
->
neg
=
0
;
DBUG_RETURN
(
l_time
->
time_type
=
(
number_of_fields
<=
3
?
TIMESTAMP_DATE
:
TIMESTAMP_FULL
));
}
...
...
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