Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
c93e30ee
提交
c93e30ee
authored
11月 13, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Compatibility for MS SQL Server DATEDIFF(YYYY, .., ..).
上级
7beb10a8
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
43 行增加
和
7 行删除
+43
-7
Parser.java
h2/src/main/org/h2/command/Parser.java
+14
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+27
-7
testSimple.in.txt
h2/src/test/org/h2/test/testSimple.in.txt
+2
-0
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
c93e30ee
...
...
@@ -1971,6 +1971,20 @@ public class Parser {
read
(
")"
);
break
;
}
case
Function
.
DATE_DIFF
:
{
if
(
Function
.
isDatePart
(
currentToken
))
{
function
.
setParameter
(
0
,
ValueExpression
.
get
(
ValueString
.
get
(
currentToken
)));
read
();
}
else
{
function
.
setParameter
(
0
,
readExpression
());
}
read
(
","
);
function
.
setParameter
(
1
,
readExpression
());
read
(
","
);
function
.
setParameter
(
2
,
readExpression
());
read
(
")"
);
break
;
}
case
Function
.
SUBSTRING
:
{
function
.
setParameter
(
0
,
readExpression
());
if
(!
readIf
(
","
))
{
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
c93e30ee
...
...
@@ -120,22 +120,31 @@ public class Function extends Expression implements FunctionCall {
static
{
// DATE_PART
DATE_PART
.
put
(
"YY"
,
ObjectUtils
.
getInteger
(
Calendar
.
YEAR
));
DATE_PART
.
put
(
"YEAR"
,
ObjectUtils
.
getInteger
(
Calendar
.
YEAR
));
DATE_PART
.
put
(
"MM"
,
ObjectUtils
.
getInteger
(
Calendar
.
MONTH
));
DATE_PART
.
put
(
"YYYY"
,
ObjectUtils
.
getInteger
(
Calendar
.
YEAR
));
DATE_PART
.
put
(
"YY"
,
ObjectUtils
.
getInteger
(
Calendar
.
YEAR
));
DATE_PART
.
put
(
"MONTH"
,
ObjectUtils
.
getInteger
(
Calendar
.
MONTH
));
DATE_PART
.
put
(
"DD"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_MONTH
));
DATE_PART
.
put
(
"MM"
,
ObjectUtils
.
getInteger
(
Calendar
.
MONTH
));
DATE_PART
.
put
(
"M"
,
ObjectUtils
.
getInteger
(
Calendar
.
MONTH
));
DATE_PART
.
put
(
"WW"
,
ObjectUtils
.
getInteger
(
Calendar
.
WEEK_OF_YEAR
));
DATE_PART
.
put
(
"WK"
,
ObjectUtils
.
getInteger
(
Calendar
.
WEEK_OF_YEAR
));
DATE_PART
.
put
(
"DAY"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_MONTH
));
DATE_PART
.
put
(
"DD"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_MONTH
));
DATE_PART
.
put
(
"D"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_MONTH
));
DATE_PART
.
put
(
"DAYOFYEAR"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_YEAR
));
DATE_PART
.
put
(
"DAY_OF_YEAR"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_YEAR
));
DATE_PART
.
put
(
"DY"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_YEAR
));
DATE_PART
.
put
(
"DOY"
,
ObjectUtils
.
getInteger
(
Calendar
.
DAY_OF_YEAR
));
DATE_PART
.
put
(
"HH"
,
ObjectUtils
.
getInteger
(
Calendar
.
HOUR_OF_DAY
));
DATE_PART
.
put
(
"HOUR"
,
ObjectUtils
.
getInteger
(
Calendar
.
HOUR_OF_DAY
));
DATE_PART
.
put
(
"
MI"
,
ObjectUtils
.
getInteger
(
Calendar
.
MINUTE
));
DATE_PART
.
put
(
"
HH"
,
ObjectUtils
.
getInteger
(
Calendar
.
HOUR_OF_DAY
));
DATE_PART
.
put
(
"MINUTE"
,
ObjectUtils
.
getInteger
(
Calendar
.
MINUTE
));
DATE_PART
.
put
(
"SS"
,
ObjectUtils
.
getInteger
(
Calendar
.
SECOND
));
DATE_PART
.
put
(
"MI"
,
ObjectUtils
.
getInteger
(
Calendar
.
MINUTE
));
DATE_PART
.
put
(
"N"
,
ObjectUtils
.
getInteger
(
Calendar
.
MINUTE
));
DATE_PART
.
put
(
"SECOND"
,
ObjectUtils
.
getInteger
(
Calendar
.
SECOND
));
DATE_PART
.
put
(
"MS"
,
ObjectUtils
.
getInteger
(
Calendar
.
MILLISECOND
));
DATE_PART
.
put
(
"SS"
,
ObjectUtils
.
getInteger
(
Calendar
.
SECOND
));
DATE_PART
.
put
(
"S"
,
ObjectUtils
.
getInteger
(
Calendar
.
SECOND
));
DATE_PART
.
put
(
"MILLISECOND"
,
ObjectUtils
.
getInteger
(
Calendar
.
MILLISECOND
));
DATE_PART
.
put
(
"MS"
,
ObjectUtils
.
getInteger
(
Calendar
.
MILLISECOND
));
// SOUNDEX_INDEX
String
index
=
"7AEIOUY8HW1BFPV2CGJKQSXZ3DT4L5MN6R"
;
...
...
@@ -1189,6 +1198,17 @@ public class Function extends Expression implements FunctionCall {
return
bytes
;
}
/**
* Check if a given string is a valid date part string.
*
* @param part the string
* @return true if it is
*/
public
static
boolean
isDatePart
(
String
part
)
{
Integer
p
=
(
Integer
)
DATE_PART
.
get
(
StringUtils
.
toUpperEnglish
(
part
));
return
p
!=
null
;
}
private
static
int
getDatePart
(
String
part
)
throws
SQLException
{
Integer
p
=
(
Integer
)
DATE_PART
.
get
(
StringUtils
.
toUpperEnglish
(
part
));
if
(
p
==
null
)
{
...
...
h2/src/test/org/h2/test/testSimple.in.txt
浏览文件 @
c93e30ee
select datediff(yyyy, now(), now());
> 0;
create table t(d date) as select '2008-11-01' union select '2008-11-02';
select 1 from t group by year(d) order by year(d);
> 1;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论