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
7961bc4b
Commit
7961bc4b
authored
Feb 19, 2018
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
helper append_interval(String*)
parent
7e2c686b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
7 deletions
+83
-7
include/my_time.h
include/my_time.h
+1
-1
sql/sql_time.cc
sql/sql_time.cc
+79
-5
sql/sql_time.h
sql/sql_time.h
+3
-1
No files found.
include/my_time.h
View file @
7961bc4b
...
...
@@ -236,7 +236,7 @@ static inline void my_timeval_trunc(struct timeval *tv, uint decimals)
order of elements in 'interval_type_to_name' and 'interval_names'
arrays
See also interval_type_to_name, get_interval_value, interval_names
See also interval_type_to_name, get_interval_value, interval_names
, append_interval
*/
enum
interval_type
...
...
sql/sql_time.cc
View file @
7961bc4b
...
...
@@ -37,7 +37,7 @@
Order of elements in 'interval_type_to_name' should correspond to
the order of elements in 'interval_type' enum
See also interval_type, interval_names
See also interval_type, interval_names
, append_interval
*/
LEX_CSTRING
interval_type_to_name
[
INTERVAL_LAST
]
=
{
...
...
@@ -61,10 +61,84 @@ LEX_CSTRING interval_type_to_name[INTERVAL_LAST] = {
{
STRING_WITH_LEN
(
"HOUR_MICROSECOND"
)},
{
STRING_WITH_LEN
(
"MINUTE_MICROSECOND"
)},
{
STRING_WITH_LEN
(
"SECOND_MICROSECOND"
)}
};
};
/* Calc weekday from daynr */
/* Returns 0 for monday, 1 for tuesday .... */
int
append_interval
(
String
*
str
,
interval_type
int_type
,
const
INTERVAL
&
interval
)
{
char
buf
[
64
];
size_t
len
;
switch
(
int_type
)
{
case
INTERVAL_YEAR
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
year
);
break
;
case
INTERVAL_QUARTER
:
case
INTERVAL_MONTH
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
month
);
int_type
=
INTERVAL_MONTH
;
break
;
case
INTERVAL_WEEK
:
case
INTERVAL_DAY
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
day
);
int_type
=
INTERVAL_DAY
;
break
;
case
INTERVAL_HOUR
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
hour
);
break
;
case
INTERVAL_MINUTE
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
minute
);
break
;
case
INTERVAL_SECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
second
);
break
;
case
INTERVAL_MICROSECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u"
,
interval
.
second_part
);
break
;
case
INTERVAL_YEAR_MONTH
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u-%02u"
,
interval
.
day
,
interval
.
month
);
break
;
case
INTERVAL_DAY_HOUR
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u %u"
,
interval
.
day
,
interval
.
hour
);
break
;
case
INTERVAL_DAY_MINUTE
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u %u:%02u"
,
interval
.
day
,
interval
.
hour
,
interval
.
minute
);
break
;
case
INTERVAL_DAY_SECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u %u:%02u:%02u"
,
interval
.
day
,
interval
.
hour
,
interval
.
minute
,
interval
.
second
);
break
;
case
INTERVAL_HOUR_MINUTE
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u:%02u"
,
interval
.
hour
,
interval
.
minute
);
break
;
case
INTERVAL_HOUR_SECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u:%02u:%02u"
,
interval
.
hour
,
interval
.
minute
,
interval
.
second
);
break
;
case
INTERVAL_MINUTE_SECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u:%02u"
,
interval
.
minute
,
interval
.
second
);
break
;
case
INTERVAL_DAY_MICROSECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u %u:%02u:%02u.%06u"
,
interval
.
day
,
interval
.
hour
,
interval
.
minute
,
interval
.
second
,
interval
.
second_part
);
break
;
case
INTERVAL_HOUR_MICROSECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u:%02u:%02u.%06u"
,
interval
.
hour
,
interval
.
minute
,
interval
.
second
,
interval
.
second_part
);
break
;
case
INTERVAL_MINUTE_MICROSECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u:%02u.%06u"
,
interval
.
minute
,
interval
.
second
,
interval
.
second_part
);
break
;
case
INTERVAL_SECOND_MICROSECOND
:
len
=
my_snprintf
(
buf
,
sizeof
(
buf
),
"%u.%06u"
,
interval
.
second
,
interval
.
second_part
);
break
;
default:
DBUG_ASSERT
(
0
);
len
=
0
;
}
return
str
->
append
(
buf
,
len
)
||
str
->
append
(
' '
)
||
str
->
append
(
interval_type_to_name
+
int_type
);
}
/*
Calc weekday from daynr
Returns 0 for monday, 1 for tuesday ...
*/
int
calc_weekday
(
long
daynr
,
bool
sunday_first_day_of_week
)
{
...
...
@@ -902,7 +976,7 @@ void make_truncated_value_warning(THD *thd,
#define GET_PART(X, N) X % N ## LL; X/= N ## LL
bool
date_add_interval
(
MYSQL_TIME
*
ltime
,
interval_type
int_type
,
INTERVAL
interval
)
const
INTERVAL
&
interval
)
{
long
period
,
sign
;
...
...
sql/sql_time.h
View file @
7961bc4b
...
...
@@ -139,9 +139,11 @@ bool my_TIME_to_str(const MYSQL_TIME *ltime, String *str, uint dec);
/* MYSQL_TIME operations */
bool
date_add_interval
(
MYSQL_TIME
*
ltime
,
interval_type
int_type
,
INTERVAL
interval
);
const
INTERVAL
&
interval
);
bool
calc_time_diff
(
const
MYSQL_TIME
*
l_time1
,
const
MYSQL_TIME
*
l_time2
,
int
l_sign
,
longlong
*
seconds_out
,
long
*
microseconds_out
);
int
append_interval
(
String
*
str
,
interval_type
int_type
,
const
INTERVAL
&
interval
);
/**
Calculate time difference between two MYSQL_TIME values and
store the result as an out MYSQL_TIME value in MYSQL_TIMESTAMP_TIME format.
...
...
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