Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3f900196
提交
3f900196
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support Interval class in more places
上级
41c30c1c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
0 行删除
+59
-0
JdbcResultSet.java
h2/src/main/org/h2/jdbc/JdbcResultSet.java
+8
-0
DataType.java
h2/src/main/org/h2/value/DataType.java
+18
-0
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+14
-0
TestResultSet.java
h2/src/test/org/h2/test/jdbc/TestResultSet.java
+19
-0
没有找到文件。
h2/src/main/org/h2/jdbc/JdbcResultSet.java
浏览文件 @
3f900196
...
...
@@ -30,6 +30,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.UUID
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Interval
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.command.CommandInterface
;
import
org.h2.engine.Mode
;
...
...
@@ -53,6 +54,7 @@ import org.h2.value.ValueDecimal;
import
org.h2.value.ValueDouble
;
import
org.h2.value.ValueFloat
;
import
org.h2.value.ValueInt
;
import
org.h2.value.ValueInterval
;
import
org.h2.value.ValueLong
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueShort
;
...
...
@@ -3929,6 +3931,12 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
}
else
if
(
type
==
TimestampWithTimeZone
.
class
)
{
ValueTimestampTimeZone
v
=
(
ValueTimestampTimeZone
)
value
.
convertTo
(
Value
.
TIMESTAMP_TZ
);
return
type
.
cast
(
new
TimestampWithTimeZone
(
v
.
getDateValue
(),
v
.
getTimeNanos
(),
v
.
getTimeZoneOffsetMins
()));
}
else
if
(
type
==
Interval
.
class
)
{
if
(!(
value
instanceof
ValueInterval
))
{
value
=
value
.
convertTo
(
Value
.
INTERVAL_DAY_TO_SECOND
);
}
ValueInterval
v
=
(
ValueInterval
)
value
;
return
type
.
cast
(
new
Interval
(
v
.
getQualifier
(),
v
.
getLeading
(),
v
.
getRemaining
()));
}
else
if
(
DataType
.
isGeometryClass
(
type
))
{
return
type
.
cast
(
value
.
convertTo
(
Value
.
GEOMETRY
).
getObject
());
}
else
if
(
type
==
LocalDateTimeUtils
.
LOCAL_DATE
)
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/DataType.java
浏览文件 @
3f900196
...
...
@@ -896,6 +896,21 @@ public class DataType {
return
ResultSet
.
class
.
getName
();
case
Value
.
GEOMETRY
:
return
GEOMETRY_CLASS_NAME
;
case
Value
.
INTERVAL_YEAR
:
case
Value
.
INTERVAL_MONTH
:
case
Value
.
INTERVAL_DAY
:
case
Value
.
INTERVAL_HOUR
:
case
Value
.
INTERVAL_MINUTE
:
case
Value
.
INTERVAL_SECOND
:
case
Value
.
INTERVAL_YEAR_TO_MONTH
:
case
Value
.
INTERVAL_DAY_TO_HOUR
:
case
Value
.
INTERVAL_DAY_TO_MINUTE
:
case
Value
.
INTERVAL_DAY_TO_SECOND
:
case
Value
.
INTERVAL_HOUR_TO_MINUTE
:
case
Value
.
INTERVAL_HOUR_TO_SECOND
:
case
Value
.
INTERVAL_MINUTE_TO_SECOND
:
// "org.h2.api.Interval"
return
Interval
.
class
.
getName
();
default
:
if
(
JdbcUtils
.
customDataTypesHandler
!=
null
)
{
return
JdbcUtils
.
customDataTypesHandler
.
getDataTypeClassName
(
type
);
...
...
@@ -1257,6 +1272,9 @@ public class DataType {
return
LocalDateTimeUtils
.
offsetDateTimeToValue
(
x
);
}
else
if
(
x
instanceof
TimestampWithTimeZone
)
{
return
ValueTimestampTimeZone
.
get
((
TimestampWithTimeZone
)
x
);
}
else
if
(
x
instanceof
Interval
)
{
Interval
i
=
(
Interval
)
x
;
return
ValueInterval
.
from
(
i
.
getQualifier
(),
i
.
getLeading
(),
i
.
getRemaining
());
}
else
{
if
(
JdbcUtils
.
customDataTypesHandler
!=
null
)
{
return
JdbcUtils
.
customDataTypesHandler
.
getValue
(
type
,
x
,
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
3f900196
...
...
@@ -30,6 +30,8 @@ import java.util.GregorianCalendar;
import
java.util.UUID
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Interval
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.api.Trigger
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
...
...
@@ -180,6 +182,7 @@ public class TestPreparedStatement extends TestDb {
testDateTime8
(
conn
);
testOffsetDateTime8
(
conn
);
testInstant8
(
conn
);
testInterval
(
conn
);
testArray
(
conn
);
testSetObject
(
conn
);
testPreparedSubquery
(
conn
);
...
...
@@ -902,6 +905,17 @@ public class TestPreparedStatement extends TestDb {
rs
.
close
();
}
private
void
testInterval
(
Connection
conn
)
throws
SQLException
{
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT ?"
);
Interval
interval
=
new
Interval
(
IntervalQualifier
.
MINUTE
,
100
,
0
);
prep
.
setObject
(
1
,
interval
);
ResultSet
rs
=
prep
.
executeQuery
();
rs
.
next
();
assertEquals
(
"INTERVAL '100' MINUTE"
,
rs
.
getString
(
1
));
assertEquals
(
interval
,
rs
.
getObject
(
1
));
assertEquals
(
interval
,
rs
.
getObject
(
1
,
Interval
.
class
));
}
private
void
testPreparedSubquery
(
Connection
conn
)
throws
SQLException
{
Statement
s
=
conn
.
createStatement
();
s
.
executeUpdate
(
"CREATE TABLE TEST(ID IDENTITY, FLAG BIT)"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestResultSet.java
浏览文件 @
3f900196
...
...
@@ -37,6 +37,8 @@ import java.util.Collections;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.Interval
;
import
org.h2.api.IntervalQualifier
;
import
org.h2.engine.SysProperties
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestDb
;
...
...
@@ -103,6 +105,7 @@ public class TestResultSet extends TestDb {
testDoubleFloat
();
testDatetime
();
testDatetimeWithCalendar
();
testInterval
();
testBlob
();
testClob
();
testAutoIncrement
();
...
...
@@ -1562,6 +1565,22 @@ public class TestResultSet extends TestDb {
stat
.
execute
(
"DROP TABLE TEST"
);
}
private
void
testInterval
()
throws
SQLException
{
trace
(
"Test INTERVAL"
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"CALL INTERVAL '10' YEAR"
);
rs
.
next
();
assertEquals
(
"INTERVAL '10' YEAR"
,
rs
.
getString
(
1
));
Interval
expected
=
new
Interval
(
IntervalQualifier
.
YEAR
,
10
,
0
);
assertEquals
(
expected
,
rs
.
getObject
(
1
));
assertEquals
(
expected
,
rs
.
getObject
(
1
,
Interval
.
class
));
ResultSetMetaData
metaData
=
rs
.
getMetaData
();
assertEquals
(
Types
.
OTHER
,
metaData
.
getColumnType
(
1
));
assertEquals
(
"INTERVAL YEAR"
,
metaData
.
getColumnTypeName
(
1
));
assertEquals
(
Interval
.
class
.
getName
(),
metaData
.
getColumnClassName
(
1
));
}
private
void
testBlob
()
throws
SQLException
{
trace
(
"Test BLOB"
);
ResultSet
rs
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论