提交 5874ac22 authored 作者: Thomas Mueller's avatar Thomas Mueller

CallableStatement with "out" parameters: running the same statement twice could…

CallableStatement with "out" parameters: running the same statement twice could result in an exception ("parameter not set").
上级 ad484351
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Union queries: duplicate rows could be returned if the sub-queries contained "order by". <ul><li>CallableStatement with "out" parameters: running the same statement twice
could result in an exception ("parameter not set").
</li><li>Union queries: duplicate rows could be returned if the sub-queries contained "order by".
</li><li>The GEOMETRY data type now works for user defined functions that return a result set. </li><li>The GEOMETRY data type now works for user defined functions that return a result set.
</li><li>PostgreSQL compatibility: the PgServer was not working properly when the setting </li><li>PostgreSQL compatibility: the PgServer was not working properly when the setting
database_to_upper was set to false. database_to_upper was set to false.
......
...@@ -1578,7 +1578,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call ...@@ -1578,7 +1578,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
} }
checkIndexBounds(parameterIndex); checkIndexBounds(parameterIndex);
ParameterInterface param = command.getParameters().get(--parameterIndex); ParameterInterface param = command.getParameters().get(--parameterIndex);
if (param.getParamValue() == null) { if (!param.isValueSet()) {
param.setValue(ValueNull.INSTANCE, false); param.setValue(ValueNull.INSTANCE, false);
} }
outParameters.set(parameterIndex); outParameters.set(parameterIndex);
......
...@@ -43,6 +43,7 @@ public class TestCallableStatement extends TestBase { ...@@ -43,6 +43,7 @@ public class TestCallableStatement extends TestBase {
public void test() throws SQLException { public void test() throws SQLException {
deleteDb("callableStatement"); deleteDb("callableStatement");
Connection conn = getConnection("callableStatement"); Connection conn = getConnection("callableStatement");
testOutParameter(conn);
testUnsupportedOperations(conn); testUnsupportedOperations(conn);
testGetters(conn); testGetters(conn);
testCallWithResultSet(conn); testCallWithResultSet(conn);
...@@ -53,6 +54,19 @@ public class TestCallableStatement extends TestBase { ...@@ -53,6 +54,19 @@ public class TestCallableStatement extends TestBase {
deleteDb("callableStatement"); deleteDb("callableStatement");
} }
private void testOutParameter(Connection conn) throws SQLException {
conn.createStatement().execute(
"create table test(id identity) as select null");
for (int i = 1; i < 20; i++) {
CallableStatement cs = conn.prepareCall("{ ? = call IDENTITY()}");
cs.registerOutParameter(1, Types.BIGINT);
cs.execute();
long id = cs.getLong(1);
assertEquals(1, id);
cs.close();
}
}
private void testUnsupportedOperations(Connection conn) throws SQLException { private void testUnsupportedOperations(Connection conn) throws SQLException {
CallableStatement call; CallableStatement call;
call = conn.prepareCall("select 10 as a"); call = conn.prepareCall("select 10 as a");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论