Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bb240dd7
提交
bb240dd7
authored
2月 09, 2018
作者:
Stéphane Eintrazi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update code style
上级
9ca0e68e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
49 行增加
和
33 行删除
+49
-33
Function.java
h2/src/main/org/h2/expression/Function.java
+49
-33
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
bb240dd7
...
...
@@ -108,12 +108,17 @@ public class Function extends Expression implements FunctionCall {
SECOND
=
114
,
WEEK
=
115
,
YEAR
=
116
,
CURRENT_DATE
=
117
,
CURRENT_TIME
=
118
,
CURRENT_TIMESTAMP
=
119
,
EXTRACT
=
120
,
FORMATDATETIME
=
121
,
PARSEDATETIME
=
122
,
ISO_YEAR
=
123
,
ISO_WEEK
=
124
,
ISO_DAY_OF_WEEK
=
125
,
EPOCH
=
127
;
ISO_WEEK
=
124
,
ISO_DAY_OF_WEEK
=
125
;
/**
* Pseudo function for {@code EXTRACT(MILLISECOND FROM ...)}.
*/
public
static
final
int
MILLISECOND
=
126
;
/**
* PSeudo function for {@code EXTRACT(EPOCH FROM ...)}.
*/
public
static
final
int
EPOCH
=
127
;
public
static
final
int
DATABASE
=
150
,
USER
=
151
,
CURRENT_USER
=
152
,
IDENTITY
=
153
,
SCOPE_IDENTITY
=
154
,
AUTOCOMMIT
=
155
,
...
...
@@ -1497,45 +1502,56 @@ public class Function extends Expression implements FunctionCall {
break
;
case
EXTRACT:
{
int
field
=
getDatePart
(
v0
.
getString
());
// Normal case when we don't retrieve the EPOCH time
if
(
field
!=
EPOCH
)
{
result
=
ValueInt
.
get
(
DateTimeUtils
.
getDatePart
(
v1
,
field
));
result
=
ValueInt
.
get
(
getDatePart
(
v1
,
field
));
}
else
{
// Case where we retrieve the EPOCH time.
// First we retrieve the dateValue and his time in nanoseconds.
long
[]
a
=
DateTimeUtils
.
dateAndTimeFromValue
(
v1
);
// Case where we retrieve the EPOCH time.
// First we retrieve the dateValue and his time in nanoseconds.
long
[]
a
=
DateTimeUtils
.
dateAndTimeFromValue
(
v1
);
long
dateValue
=
a
[
0
];
long
timeNanos
=
a
[
1
];
// We compute the time in nanoseconds and the total number of days.
BigDecimal
timeNanosBigDecimal
=
new
BigDecimal
(
timeNanos
);
BigDecimal
numberOfDays
=
new
BigDecimal
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
));
BigDecimal
nanosSeconds
=
new
BigDecimal
(
1_000_000_000
);
BigDecimal
seconds
=
new
BigDecimal
(
60
);
BigDecimal
secondsPerDay
=
new
BigDecimal
(
DateTimeUtils
.
SECONDS_PER_DAY
);
BigDecimal
timeNanosBigDecimal
=
new
BigDecimal
(
timeNanos
);
BigDecimal
numberOfDays
=
new
BigDecimal
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
));
BigDecimal
nanosSeconds
=
new
BigDecimal
(
1_000_000_000
);
BigDecimal
secondsPerDay
=
new
BigDecimal
(
DateTimeUtils
.
SECONDS_PER_DAY
);
// Case where the value is of type time e.g. '10:00:00'
if
(
v1
instanceof
ValueTime
)
{
// In order to retrieve the EPOCH time we only have to convert the time
// in nanoseconds (previously retrieved) in seconds.
result
=
ValueDecimal
.
get
(
timeNanosBigDecimal
.
divide
(
nanosSeconds
));
}
else
if
(
v1
instanceof
ValueDate
)
{
// Case where the value is of type date '2000:01:01', we have to retrieve the total
// number of days and multiply it by the number of seconds in a day.
result
=
ValueDecimal
.
get
(
numberOfDays
.
multiply
(
secondsPerDay
));
}
else
if
(
v1
instanceof
ValueTimestampTimeZone
)
{
// Case where the value is a of type ValueTimestampTimeZone ('2000:01:01 10:00:00+05).
// We retrieve the time zone offset in minute
ValueTimestampTimeZone
v
=
(
ValueTimestampTimeZone
)
v1
;
BigDecimal
timeZoneOffsetMins
=
new
BigDecimal
(
v
.
getTimeZoneOffsetMins
());
// Sum the time in nanoseconds and the total number of days in seconds
// and adding the timeZone offset in seconds.
result
=
ValueDecimal
.
get
(
timeNanosBigDecimal
.
divide
(
nanosSeconds
)
.
add
(
numberOfDays
.
multiply
(
secondsPerDay
))
.
add
(
timeZoneOffsetMins
.
multiply
(
seconds
).
negate
()));
}
else
{
// By default, we have the date and the time ('2000:01:01 10:00:00) if no type is given.
// We just have to sum the time in nanoseconds and the total number of days in seconds.
result
=
ValueDecimal
.
get
(
timeNanosBigDecimal
.
divide
(
nanosSeconds
).
add
(
numberOfDays
.
multiply
(
secondsPerDay
)));
}
if
(
v1
instanceof
ValueTime
)
{
// In order to retrieve the EPOCH time we only have to convert the time
// in nanoseconds (previously retrieved) in seconds.
result
=
ValueDecimal
.
get
(
timeNanosBigDecimal
.
divide
(
nanosSeconds
));
}
else
if
(
v1
instanceof
ValueDate
)
{
// Case where the value is of type date '2000:01:01', we have to retrieve the total
// number of days and multiply it by the number of seconds in a day.
result
=
ValueDecimal
.
get
(
numberOfDays
.
multiply
(
secondsPerDay
));
}
else
if
(
v1
instanceof
ValueTimestampTimeZone
)
{
// Case where the value is a of type ValueTimestampTimeZone ('2000:01:01 10:00:00+05).
// We retrieve the time zone offset in minute
ValueTimestampTimeZone
v
=
(
ValueTimestampTimeZone
)
v1
;
BigDecimal
timeZoneOffsetSeconds
=
new
BigDecimal
(
v
.
getTimeZoneOffsetMins
()
*
60
);
// Sum the time in nanoseconds and the total number of days in seconds
// and adding the timeZone offset in seconds.
result
=
ValueDecimal
.
get
(
timeNanosBigDecimal
.
divide
(
nanosSeconds
)
.
add
(
numberOfDays
.
multiply
(
secondsPerDay
))
.
subtract
(
timeZoneOffsetSeconds
));
}
else
{
// By default, we have the date and the time ('2000:01:01 10:00:00) if no type is given.
// We just have to sum the time in nanoseconds and the total number of days in seconds.
result
=
ValueDecimal
.
get
(
timeNanosBigDecimal
.
divide
(
nanosSeconds
).
add
(
numberOfDays
.
multiply
(
secondsPerDay
)));
}
}
break
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论