Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
52c9c778
提交
52c9c778
authored
1月 04, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More tests
上级
01fa3e13
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
113 行增加
和
65 行删除
+113
-65
TestCallableStatement.java
h2/src/test/org/h2/test/jdbc/TestCallableStatement.java
+50
-43
TestUpdatableResultSet.java
h2/src/test/org/h2/test/jdbc/TestUpdatableResultSet.java
+63
-22
没有找到文件。
h2/src/test/org/h2/test/jdbc/TestCallableStatement.java
浏览文件 @
52c9c778
...
...
@@ -47,6 +47,7 @@ public class TestCallableStatement extends TestBase {
testUnsupportedOperations
(
conn
);
testGetters
(
conn
);
testCallWithResultSet
(
conn
);
testPreparedStatement
(
conn
);
testCallWithResult
(
conn
);
testPrepare
(
conn
);
testClassLoader
(
conn
);
...
...
@@ -98,50 +99,16 @@ public class TestCallableStatement extends TestBase {
private
void
testCallWithResultSet
(
Connection
conn
)
throws
SQLException
{
CallableStatement
call
;
ResultSet
rs
;
call
=
conn
.
prepareCall
(
"select 10 as a, 20 as b, null as c, timestamp '2001-01-01 01:01:01.0' d"
);
call
=
conn
.
prepareCall
(
"select 10 as a"
);
call
.
execute
();
rs
=
call
.
getResultSet
();
rs
.
next
();
assertEquals
(
10
,
rs
.
getInt
(
1
));
assertEquals
(
10
,
rs
.
getByte
(
1
));
assertEquals
(
"10"
,
rs
.
getBigDecimal
(
1
).
toString
());
assertEquals
(
10
,
((
Integer
)
rs
.
getObject
(
1
)).
intValue
());
assertEquals
(
10
,
rs
.
getShort
(
1
));
assertEquals
(
10
,
rs
.
getLong
(
1
));
assertEquals
(
10
,
rs
.
getFloat
(
1
));
assertEquals
(
10
,
rs
.
getDouble
(
1
));
assertTrue
(
rs
.
getBoolean
(
1
));
assertEquals
(
10
,
rs
.
getInt
(
"a"
));
assertEquals
(
10
,
rs
.
getByte
(
"a"
));
assertEquals
(
"10"
,
rs
.
getBigDecimal
(
"a"
).
toString
());
assertEquals
(
10
,
((
Integer
)
rs
.
getObject
(
"a"
)).
intValue
());
assertEquals
(
10
,
rs
.
getShort
(
"a"
));
assertEquals
(
10
,
rs
.
getLong
(
"a"
));
assertEquals
(
10
,
rs
.
getFloat
(
"a"
));
assertEquals
(
10
,
rs
.
getDouble
(
"a"
));
assertTrue
(
rs
.
getBoolean
(
"a"
));
assertFalse
(
rs
.
wasNull
());
assertEquals
(
20
,
rs
.
getInt
(
2
));
assertEquals
(
20
,
rs
.
getInt
(
"b"
));
assertFalse
(
rs
.
wasNull
());
assertEquals
(
0
,
rs
.
getInt
(
3
));
assertTrue
(
rs
.
wasNull
());
assertEquals
(
0
,
rs
.
getInt
(
"c"
));
assertTrue
(
rs
.
wasNull
());
assertEquals
(
"2001-01-01"
,
rs
.
getDate
(
4
).
toString
());
assertEquals
(
"2001-01-01"
,
rs
.
getDate
(
"d"
).
toString
());
assertEquals
(
"01:01:01"
,
rs
.
getTime
(
4
).
toString
());
assertEquals
(
"01:01:01"
,
rs
.
getTime
(
"d"
).
toString
());
assertEquals
(
"2001-01-01 01:01:01.0"
,
rs
.
getTimestamp
(
4
).
toString
());
assertEquals
(
"2001-01-01 01:01:01.0"
,
rs
.
getTimestamp
(
"d"
).
toString
());
}
private
void
testPreparedStatement
(
Connection
conn
)
throws
SQLException
{
// using a callable statement like a prepared statement
CallableStatement
call
;
call
=
conn
.
prepareCall
(
"create table test(id int)"
);
call
.
executeUpdate
();
call
=
conn
.
prepareCall
(
"insert into test values(1), (2)"
);
...
...
@@ -157,6 +124,9 @@ public class TestCallableStatement extends TestBase {
call
.
registerOutParameter
(
1
,
Types
.
BIGINT
);
call
.
execute
();
assertEquals
(
1
,
call
.
getLong
(
1
));
assertEquals
(
1
,
call
.
getByte
(
1
));
assertEquals
(
1
,
((
Long
)
call
.
getObject
(
1
)).
longValue
());
assertFalse
(
call
.
wasNull
());
call
.
setFloat
(
2
,
1.1f
);
call
.
registerOutParameter
(
1
,
Types
.
REAL
);
...
...
@@ -244,11 +214,12 @@ public class TestCallableStatement extends TestBase {
assertEquals
(
"Hello"
,
rs
.
getString
(
2
));
assertFalse
(
rs
.
next
());
stat
.
execute
(
"CREATE ALIAS testCall FOR \""
+
getClass
().
getName
()
+
".testCall\""
);
call
=
conn
.
prepareCall
(
"{CALL testCall(?,
?,
?)}"
);
call
.
setInt
(
"A"
,
10
0
);
call
=
conn
.
prepareCall
(
"{CALL testCall(?,
?, ?,
?)}"
);
call
.
setInt
(
"A"
,
5
0
);
call
.
setString
(
2
,
"abc"
);
long
t
=
System
.
currentTimeMillis
();
call
.
setTimestamp
(
"C"
,
new
Timestamp
(
t
));
call
.
setTimestamp
(
"D"
,
Timestamp
.
valueOf
(
"2001-02-03 10:20:30.0"
));
call
.
registerOutParameter
(
1
,
Types
.
INTEGER
);
call
.
registerOutParameter
(
"B"
,
Types
.
VARCHAR
);
call
.
executeUpdate
();
...
...
@@ -259,10 +230,45 @@ public class TestCallableStatement extends TestBase {
// expected exception
}
call
.
registerOutParameter
(
3
,
Types
.
TIMESTAMP
);
call
.
registerOutParameter
(
4
,
Types
.
TIMESTAMP
);
call
.
executeUpdate
();
assertEquals
(
t
+
1
,
call
.
getTimestamp
(
3
).
getTime
());
assertEquals
(
200
,
call
.
getInt
(
"A"
));
assertEquals
(
t
+
1
,
call
.
getTimestamp
(
"C"
).
getTime
());
assertEquals
(
"2001-02-03 10:20:30.0"
,
call
.
getTimestamp
(
4
).
toString
());
assertEquals
(
"2001-02-03 10:20:30.0"
,
call
.
getTimestamp
(
"D"
).
toString
());
assertEquals
(
"10:20:30"
,
call
.
getTime
(
4
).
toString
());
assertEquals
(
"10:20:30"
,
call
.
getTime
(
"D"
).
toString
());
assertEquals
(
"2001-02-03"
,
call
.
getDate
(
4
).
toString
());
assertEquals
(
"2001-02-03"
,
call
.
getDate
(
"D"
).
toString
());
assertEquals
(
100
,
call
.
getInt
(
1
));
assertEquals
(
100
,
call
.
getInt
(
"A"
));
assertEquals
(
100
,
call
.
getLong
(
1
));
assertEquals
(
100
,
call
.
getLong
(
"A"
));
assertEquals
(
"100"
,
call
.
getBigDecimal
(
1
).
toString
());
assertEquals
(
"100"
,
call
.
getBigDecimal
(
"A"
).
toString
());
assertEquals
(
100
,
call
.
getFloat
(
1
));
assertEquals
(
100
,
call
.
getFloat
(
"A"
));
assertEquals
(
100
,
call
.
getDouble
(
1
));
assertEquals
(
100
,
call
.
getDouble
(
"A"
));
assertEquals
(
100
,
call
.
getByte
(
1
));
assertEquals
(
100
,
call
.
getByte
(
"A"
));
assertEquals
(
100
,
call
.
getShort
(
1
));
assertEquals
(
100
,
call
.
getShort
(
"A"
));
assertTrue
(
call
.
getBoolean
(
1
));
assertTrue
(
call
.
getBoolean
(
"A"
));
assertEquals
(
"ABC"
,
call
.
getString
(
2
));
assertEquals
(
"ABC"
,
call
.
getString
(
"B"
));
assertEquals
(
"ABC"
,
call
.
getNString
(
2
));
assertEquals
(
"ABC"
,
call
.
getNString
(
"B"
));
assertEquals
(
"ABC"
,
call
.
getClob
(
2
).
getSubString
(
1
,
3
));
assertEquals
(
"ABC"
,
call
.
getClob
(
"B"
).
getSubString
(
1
,
3
));
assertEquals
(
"ABC"
,
call
.
getNClob
(
2
).
getSubString
(
1
,
3
));
assertEquals
(
"ABC"
,
call
.
getNClob
(
"B"
).
getSubString
(
1
,
3
));
try
{
call
.
getString
(
100
);
fail
(
"incorrect parameter index value"
);
...
...
@@ -323,15 +329,16 @@ public class TestCallableStatement extends TestBase {
* @param c the value c
* @return a result set
*/
public
static
ResultSet
testCall
(
Connection
conn
,
int
a
,
String
b
,
Timestamp
c
)
throws
SQLException
{
public
static
ResultSet
testCall
(
Connection
conn
,
int
a
,
String
b
,
Timestamp
c
,
Timestamp
d
)
throws
SQLException
{
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"A"
,
Types
.
INTEGER
,
0
,
0
);
rs
.
addColumn
(
"B"
,
Types
.
VARCHAR
,
0
,
0
);
rs
.
addColumn
(
"C"
,
Types
.
TIMESTAMP
,
0
,
0
);
rs
.
addColumn
(
"D"
,
Types
.
TIMESTAMP
,
0
,
0
);
if
(
"jdbc:columnlist:connection"
.
equals
(
conn
.
getMetaData
().
getURL
()))
{
return
rs
;
}
rs
.
addRow
(
a
*
2
,
b
.
toUpperCase
(),
new
Timestamp
(
c
.
getTime
()
+
1
));
rs
.
addRow
(
a
*
2
,
b
.
toUpperCase
(),
new
Timestamp
(
c
.
getTime
()
+
1
)
,
d
);
return
rs
;
}
...
...
h2/src/test/org/h2/test/jdbc/TestUpdatableResultSet.java
浏览文件 @
52c9c778
...
...
@@ -7,8 +7,10 @@
package
org
.
h2
.
test
.
jdbc
;
import
java.io.ByteArrayInputStream
;
import
java.io.OutputStream
;
import
java.io.StringReader
;
import
java.math.BigDecimal
;
import
java.sql.Blob
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.PreparedStatement
;
...
...
@@ -37,7 +39,7 @@ public class TestUpdatableResultSet extends TestBase {
}
@Override
public
void
test
()
throws
SQL
Exception
{
public
void
test
()
throws
Exception
{
testDetectUpdatable
();
testUpdateLob
();
testScroll
();
...
...
@@ -272,7 +274,7 @@ public class TestUpdatableResultSet extends TestBase {
conn
.
close
();
}
private
void
testUpdateDataType
()
throws
SQL
Exception
{
private
void
testUpdateDataType
()
throws
Exception
{
deleteDb
(
"updatableResultSet"
);
Connection
conn
=
getConnection
(
"updatableResultSet"
);
Statement
stat
=
conn
.
createStatement
(
ResultSet
.
TYPE_FORWARD_ONLY
,
ResultSet
.
CONCUR_UPDATABLE
);
...
...
@@ -369,6 +371,58 @@ public class TestUpdatableResultSet extends TestBase {
rs
.
updateBlob
(
16
,
new
ByteArrayInputStream
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
}));
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
7
);
rs
.
updateNClob
(
"CL"
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
));
Blob
b
=
conn
.
createBlob
();
OutputStream
out
=
b
.
setBinaryStream
(
1
);
out
.
write
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
});
out
.
close
();
rs
.
updateBlob
(
"BL"
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
8
);
rs
.
updateNClob
(
15
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
));
rs
.
updateBlob
(
16
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
9
);
rs
.
updateNClob
(
"CL"
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
),
-
1
);
rs
.
updateBlob
(
"BL"
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
10
);
rs
.
updateNClob
(
15
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
),
-
1
);
rs
.
updateBlob
(
16
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
11
);
rs
.
updateNCharacterStream
(
"CL"
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
),
-
1
);
rs
.
updateBlob
(
"BL"
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
12
);
rs
.
updateNCharacterStream
(
15
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
),
-
1
);
rs
.
updateBlob
(
16
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
13
);
rs
.
updateNCharacterStream
(
"CL"
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
));
rs
.
updateBlob
(
"BL"
,
b
);
rs
.
insertRow
();
rs
.
moveToInsertRow
();
rs
.
updateInt
(
"ID"
,
14
);
rs
.
updateNCharacterStream
(
15
,
new
StringReader
(
"\u00ef\u00f6\u00fc"
));
rs
.
updateBlob
(
16
,
b
);
rs
.
insertRow
();
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST ORDER BY ID NULLS FIRST"
);
rs
.
next
();
assertTrue
(
rs
.
getInt
(
1
)
==
0
);
...
...
@@ -425,27 +479,14 @@ public class TestUpdatableResultSet extends TestBase {
assertEquals
(
"\u00ef\u00f6\u00fc"
,
rs
.
getString
(
15
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
},
rs
.
getBytes
(
16
));
for
(
int
i
=
3
;
i
<=
14
;
i
++)
{
rs
.
next
();
assertTrue
(
rs
.
getInt
(
1
)
==
3
);
assertEquals
(
"\u00ef\u00f6\u00fc"
,
rs
.
getString
(
15
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
},
rs
.
getBytes
(
16
));
rs
.
next
();
assertTrue
(
rs
.
getInt
(
1
)
==
4
);
assertEquals
(
i
,
rs
.
getInt
(
1
));
assertEquals
(
"\u00ef\u00f6\u00fc"
,
rs
.
getString
(
15
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
},
rs
.
getBytes
(
16
));
rs
.
next
();
assertTrue
(
rs
.
getInt
(
1
)
==
5
);
assertEquals
(
"\u00ef\u00f6\u00fc"
,
rs
.
getString
(
15
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
},
rs
.
getBytes
(
16
));
rs
.
next
();
assertTrue
(
rs
.
getInt
(
1
)
==
6
);
assertEquals
(
"\u00ef\u00f6\u00fc"
,
rs
.
getString
(
15
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xab
,
0x12
},
rs
.
getBytes
(
16
));
}
assertFalse
(
rs
.
next
());
stat
.
execute
(
"DROP TABLE TEST"
);
conn
.
close
();
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论