Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
dfc350ac
提交
dfc350ac
authored
7 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix possible overflow in scale of timestamps
上级
d4ac543e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
53 行增加
和
14 行删除
+53
-14
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+17
-0
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+7
-7
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+7
-7
timestamp-with-timezone.sql
...org/h2/test/scripts/datatypes/timestamp-with-timezone.sql
+11
-0
timestamp.sql
h2/src/test/org/h2/test/scripts/datatypes/timestamp.sql
+11
-0
没有找到文件。
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
dfc350ac
...
...
@@ -6,6 +6,7 @@
*/
package
org
.
h2
.
util
;
import
java.math.BigDecimal
;
import
java.sql.Date
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
...
...
@@ -19,6 +20,7 @@ import org.h2.engine.Mode;
import
org.h2.message.DbException
;
import
org.h2.value.Value
;
import
org.h2.value.ValueDate
;
import
org.h2.value.ValueDecimal
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
...
...
@@ -1448,4 +1450,19 @@ public class DateTimeUtils {
return
b
.
toString
();
}
/**
* Converts scale of nanoseconds.
*
* @param nanosOfDay nanoseconds of day
* @param scale fractional seconds precision
* @return scaled value
*/
public
static
long
convertScale
(
long
nanosOfDay
,
int
scale
)
{
BigDecimal
bd
=
BigDecimal
.
valueOf
(
nanosOfDay
);
bd
=
bd
.
movePointLeft
(
9
);
bd
=
ValueDecimal
.
setScale
(
bd
,
scale
);
bd
=
bd
.
movePointRight
(
9
);
return
bd
.
longValue
();
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
dfc350ac
...
...
@@ -5,7 +5,6 @@
*/
package
org
.
h2
.
value
;
import
java.math.BigDecimal
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
...
...
@@ -216,15 +215,16 @@ public class ValueTimestamp extends Value {
throw
DbException
.
getInvalidValueException
(
"scale"
,
targetScale
);
}
long
n
=
timeNanos
;
BigDecimal
bd
=
BigDecimal
.
valueOf
(
n
);
bd
=
bd
.
movePointLeft
(
9
);
bd
=
ValueDecimal
.
setScale
(
bd
,
targetScale
);
bd
=
bd
.
movePointRight
(
9
);
long
n2
=
bd
.
longValue
();
long
n2
=
DateTimeUtils
.
convertScale
(
n
,
targetScale
);
if
(
n2
==
n
)
{
return
this
;
}
return
fromDateValueAndNanos
(
dateValue
,
n2
);
long
dv
=
dateValue
;
if
(
n2
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
n2
-=
DateTimeUtils
.
NANOS_PER_DAY
;
dv
=
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
1
);
}
return
fromDateValueAndNanos
(
dv
,
n2
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
dfc350ac
...
...
@@ -5,7 +5,6 @@
*/
package
org
.
h2
.
value
;
import
java.math.BigDecimal
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
...
...
@@ -205,15 +204,16 @@ public class ValueTimestampTimeZone extends Value {
throw
DbException
.
getInvalidValueException
(
"scale"
,
targetScale
);
}
long
n
=
timeNanos
;
BigDecimal
bd
=
BigDecimal
.
valueOf
(
n
);
bd
=
bd
.
movePointLeft
(
9
);
bd
=
ValueDecimal
.
setScale
(
bd
,
targetScale
);
bd
=
bd
.
movePointRight
(
9
);
long
n2
=
bd
.
longValue
();
long
n2
=
DateTimeUtils
.
convertScale
(
n
,
targetScale
);
if
(
n2
==
n
)
{
return
this
;
}
return
fromDateValueAndNanos
(
dateValue
,
n2
,
timeZoneOffsetMins
);
long
dv
=
dateValue
;
if
(
n2
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
n2
-=
DateTimeUtils
.
NANOS_PER_DAY
;
dv
=
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
1
);
}
return
fromDateValueAndNanos
(
dv
,
n2
,
timeZoneOffsetMins
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/datatypes/timestamp-with-timezone.sql
浏览文件 @
dfc350ac
...
...
@@ -84,5 +84,16 @@ SELECT T7, T8, T9 FROM TEST;
>
2000
-
01
-
01
08
:
00
:
00
.
1234568
+
00
2000
-
01
-
01
08
:
00
:
00
.
12345679
+
00
2000
-
01
-
01
08
:
00
:
00
.
123456789
+
00
>
rows
:
1
DELETE
FROM
TEST
;
>
update
count
:
1
INSERT
INTO
TEST
(
T0
)
VALUES
(
'2000-01-01 23:59:59.999999999Z'
);
>
update
count
:
1
SELECT
T0
FROM
TEST
;
>
T0
>
------------------------
>
2000
-
01
-
02
00
:
00
:
00
.
0
+
00
DROP
TABLE
TEST
;
>
ok
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/scripts/datatypes/timestamp.sql
浏览文件 @
dfc350ac
...
...
@@ -77,5 +77,16 @@ SELECT T7, T8, T9 FROM TEST;
>
2000
-
01
-
01
08
:
00
:
00
.
1234568
2000
-
01
-
01
08
:
00
:
00
.
12345679
2000
-
01
-
01
08
:
00
:
00
.
123456789
>
rows
:
1
DELETE
FROM
TEST
;
>
update
count
:
1
INSERT
INTO
TEST
(
T0
)
VALUES
(
'2000-01-01 23:59:59.999999999'
);
>
update
count
:
1
SELECT
T0
FROM
TEST
;
>
T0
>
---------------------
>
2000
-
01
-
02
00
:
00
:
00
.
0
DROP
TABLE
TEST
;
>
ok
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论