Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
7fed46d6
提交
7fed46d6
authored
2月 05, 2018
作者:
Stéphane Eintrazi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add epoch in extract function
上级
bcd56eb9
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
13 行删除
+20
-13
Function.java
h2/src/main/org/h2/expression/Function.java
+13
-12
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+5
-1
testSimple.in.txt
h2/src/test/org/h2/test/scripts/testSimple.in.txt
+2
-0
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
7fed46d6
...
...
@@ -106,7 +106,7 @@ 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
;
ISO_WEEK
=
124
,
ISO_DAY_OF_WEEK
=
125
,
EPOCH
=
126
;
public
static
final
int
DATABASE
=
150
,
USER
=
151
,
CURRENT_USER
=
152
,
IDENTITY
=
153
,
SCOPE_IDENTITY
=
154
,
AUTOCOMMIT
=
155
,
...
...
@@ -191,6 +191,7 @@ public class Function extends Expression implements FunctionCall {
DATE_PART
.
put
(
"S"
,
Calendar
.
SECOND
);
DATE_PART
.
put
(
"MILLISECOND"
,
Calendar
.
MILLISECOND
);
DATE_PART
.
put
(
"MS"
,
Calendar
.
MILLISECOND
);
DATE_PART
.
put
(
"EPOCH"
,
EPOCH
);
// SOUNDEX_INDEX
String
index
=
"7AEIOUY8HW1BFPV2CGJKQSXZ3DT4L5MN6R"
;
...
...
@@ -837,22 +838,22 @@ public class Function extends Expression implements FunctionCall {
break
;
}
case
DAY_OF_MONTH:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
DAY_OF_MONTH
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
DAY_OF_MONTH
));
break
;
case
DAY_OF_WEEK:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
DAY_OF_WEEK
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
DAY_OF_WEEK
));
break
;
case
DAY_OF_YEAR:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
DAY_OF_YEAR
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
DAY_OF_YEAR
));
break
;
case
HOUR:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
HOUR_OF_DAY
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
HOUR_OF_DAY
));
break
;
case
MINUTE:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
MINUTE
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
MINUTE
));
break
;
case
MONTH:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
MONTH
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
MONTH
));
break
;
case
MONTH_NAME:
{
SimpleDateFormat
monthName
=
new
SimpleDateFormat
(
"MMMM"
,
...
...
@@ -862,16 +863,16 @@ public class Function extends Expression implements FunctionCall {
break
;
}
case
QUARTER:
result
=
Value
Int
.
get
((
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
MONTH
)
-
1
)
/
3
+
1
);
result
=
Value
Long
.
get
((
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
MONTH
)
-
1
)
/
3
+
1
);
break
;
case
SECOND:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
SECOND
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
SECOND
));
break
;
case
WEEK:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
WEEK_OF_YEAR
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
WEEK_OF_YEAR
));
break
;
case
YEAR:
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
YEAR
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v0
,
Calendar
.
YEAR
));
break
;
case
ISO_YEAR:
result
=
ValueInt
.
get
(
DateTimeUtils
.
getIsoYear
(
v0
));
...
...
@@ -1513,7 +1514,7 @@ public class Function extends Expression implements FunctionCall {
break
;
case
EXTRACT:
{
int
field
=
getDatePart
(
v0
.
getString
());
result
=
Value
Int
.
get
(
DateTimeUtils
.
getDatePart
(
v1
,
field
));
result
=
Value
Long
.
get
(
DateTimeUtils
.
getDatePart
(
v1
,
field
));
break
;
}
case
FORMATDATETIME:
{
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
7fed46d6
...
...
@@ -16,6 +16,7 @@ import java.util.Locale;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.engine.Mode
;
import
org.h2.expression.Function
;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.ValueDate
;
...
...
@@ -594,8 +595,11 @@ public class DateTimeUtils {
* @param field the field type
* @return the value
*/
public
static
int
getDatePart
(
Value
date
,
int
field
)
{
public
static
long
getDatePart
(
Value
date
,
int
field
)
{
Calendar
c
=
valueToCalendar
(
date
);
if
(
field
==
Function
.
EPOCH
)
{
return
c
.
getTime
().
getTime
()
/
1000
;
}
if
(
field
==
Calendar
.
YEAR
)
{
return
getYear
(
c
);
}
...
...
h2/src/test/org/h2/test/scripts/testSimple.in.txt
浏览文件 @
7fed46d6
...
...
@@ -374,6 +374,8 @@ select hour('2001-02-03 14:15:16');
> 14;
select extract(week from timestamp '2001-02-03 14:15:16');
> 5;
select extract(epoch from '2001-02-03 14:15:16');
> 981209716;
CREATE TABLE TEST(A int NOT NULL, B int NOT NULL, C int) ;
ALTER TABLE TEST ADD CONSTRAINT CON UNIQUE(A,B);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论