Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
25e6a14d
提交
25e6a14d
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use CURRENT_TIMESTAMP in ToDateParser
上级
c85578fc
master
version-1.4.198
无相关合并请求
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
106 行增加
和
94 行删除
+106
-94
Function.java
h2/src/main/org/h2/expression/function/Function.java
+3
-6
ToDateParser.java
h2/src/main/org/h2/expression/function/ToDateParser.java
+23
-17
TestFunctions.java
h2/src/test/org/h2/test/db/TestFunctions.java
+80
-71
没有找到文件。
h2/src/main/org/h2/expression/function/Function.java
浏览文件 @
25e6a14d
...
...
@@ -1433,19 +1433,16 @@ public class Function extends Expression implements FunctionCall {
}
break
;
case
TO_DATE:
result
=
ToDateParser
.
toDate
(
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getString
());
result
=
ToDateParser
.
toDate
(
session
,
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getString
());
break
;
case
TO_TIMESTAMP:
result
=
ToDateParser
.
toTimestamp
(
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getString
());
result
=
ToDateParser
.
toTimestamp
(
session
,
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getString
());
break
;
case
ADD_MONTHS:
result
=
DateTimeFunctions
.
dateadd
(
"MONTH"
,
v1
.
getInt
(),
v0
);
break
;
case
TO_TIMESTAMP_TZ:
result
=
ToDateParser
.
toTimestampTz
(
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getString
());
result
=
ToDateParser
.
toTimestampTz
(
session
,
v0
.
getString
(),
v1
==
null
?
null
:
v1
.
getString
());
break
;
case
TRANSLATE:
{
String
matching
=
v1
.
getString
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/function/ToDateParser.java
浏览文件 @
25e6a14d
...
...
@@ -7,11 +7,10 @@ package org.h2.expression.function;
import
static
java
.
lang
.
String
.
format
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
import
java.util.TimeZone
;
import
org.h2.engine.Session
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
...
...
@@ -21,6 +20,8 @@ import org.h2.value.ValueTimestampTimeZone;
* This class holds and handles the input data form the TO_DATE-method
*/
public
class
ToDateParser
{
private
final
Session
session
;
private
final
String
unmodifiedInputStr
;
private
final
String
unmodifiedFormatStr
;
private
final
ConfigParam
functionName
;
...
...
@@ -52,12 +53,14 @@ public class ToDateParser {
private
int
currentYear
,
currentMonth
;
/**
* @param input the input date with the date-time info
* @param format the format of date-time info
* @param session the database session
* @param functionName one of [TO_DATE, TO_TIMESTAMP] (both share the same
* code)
* @param input the input date with the date-time info
* @param format the format of date-time info
*/
private
ToDateParser
(
ConfigParam
functionName
,
String
input
,
String
format
)
{
private
ToDateParser
(
Session
session
,
ConfigParam
functionName
,
String
input
,
String
format
)
{
this
.
session
=
session
;
this
.
functionName
=
functionName
;
inputStr
=
input
.
trim
();
// Keep a copy
...
...
@@ -72,8 +75,8 @@ public class ToDateParser {
unmodifiedFormatStr
=
formatStr
;
}
private
static
ToDateParser
getTimestampParser
(
ConfigParam
param
,
String
input
,
String
format
)
{
ToDateParser
result
=
new
ToDateParser
(
param
,
input
,
format
);
private
static
ToDateParser
getTimestampParser
(
Session
session
,
ConfigParam
param
,
String
input
,
String
format
)
{
ToDateParser
result
=
new
ToDateParser
(
session
,
param
,
input
,
format
);
parse
(
result
);
return
result
;
}
...
...
@@ -145,10 +148,10 @@ public class ToDateParser {
}
private
void
queryCurrentYearAndMonth
()
{
GregorianCalendar
gc
=
DateTimeUtils
.
getCalendar
();
gc
.
setTimeInMillis
(
System
.
currentTimeMillis
()
);
currentYear
=
gc
.
get
(
Calendar
.
YEAR
);
currentMonth
=
gc
.
get
(
Calendar
.
MONTH
)
+
1
;
long
dateValue
=
(
session
.
getDatabase
().
getMode
().
dateTimeValueWithinTransaction
?
session
.
getTransactionStart
()
:
session
.
getCurrentCommandStart
()).
getDateValue
(
);
currentYear
=
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
currentMonth
=
DateTimeUtils
.
monthFromDateValue
(
dateValue
)
;
}
int
getCurrentYear
()
{
...
...
@@ -319,36 +322,39 @@ public class ToDateParser {
/**
* Parse a string as a timestamp with the given format.
*
* @param session the database session
* @param input the input
* @param format the format
* @return the timestamp
*/
public
static
ValueTimestamp
toTimestamp
(
String
input
,
String
format
)
{
ToDateParser
parser
=
getTimestampParser
(
ConfigParam
.
TO_TIMESTAMP
,
input
,
format
);
public
static
ValueTimestamp
toTimestamp
(
S
ession
session
,
S
tring
input
,
String
format
)
{
ToDateParser
parser
=
getTimestampParser
(
session
,
ConfigParam
.
TO_TIMESTAMP
,
input
,
format
);
return
parser
.
getResultingValue
();
}
/**
* Parse a string as a timestamp with the given format.
*
* @param session the database session
* @param input the input
* @param format the format
* @return the timestamp
*/
public
static
ValueTimestampTimeZone
toTimestampTz
(
String
input
,
String
format
)
{
ToDateParser
parser
=
getTimestampParser
(
ConfigParam
.
TO_TIMESTAMP_TZ
,
input
,
format
);
public
static
ValueTimestampTimeZone
toTimestampTz
(
S
ession
session
,
S
tring
input
,
String
format
)
{
ToDateParser
parser
=
getTimestampParser
(
session
,
ConfigParam
.
TO_TIMESTAMP_TZ
,
input
,
format
);
return
parser
.
getResultingValueWithTimeZone
();
}
/**
* Parse a string as a date with the given format.
*
* @param session the database session
* @param input the input
* @param format the format
* @return the date as a timestamp
*/
public
static
ValueTimestamp
toDate
(
String
input
,
String
format
)
{
ToDateParser
parser
=
getTimestampParser
(
ConfigParam
.
TO_DATE
,
input
,
format
);
public
static
ValueTimestamp
toDate
(
S
ession
session
,
S
tring
input
,
String
format
)
{
ToDateParser
parser
=
getTimestampParser
(
session
,
ConfigParam
.
TO_DATE
,
input
,
format
);
return
parser
.
getResultingValue
();
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestFunctions.java
浏览文件 @
25e6a14d
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论