提交 9dcb6c46 authored 作者: Thomas Mueller's avatar Thomas Mueller

CallableStatement: the first row of the result set was skipped when using…

CallableStatement: the first row of the result set was skipped when using CallableStatement.execute().
上级 65f044a0
......@@ -54,28 +54,6 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
}
/**
* Executes an arbitrary statement. If another result set exists for this
* statement, this will be closed (even if this statement fails). If auto
* commit is on, and the statement is not a select, this statement will be
* committed.
*
* @return true if a result set is available, false if not
* @throws SQLException if this object is closed or invalid
*/
public boolean execute() throws SQLException {
try {
checkClosed();
if (command.isQuery()) {
super.executeQuery().next();
return true;
}
super.executeUpdate();
return false;
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Executes a statement (insert, update, delete, create, drop)
* and returns the update count.
......@@ -96,7 +74,7 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
try {
checkClosed();
if (command.isQuery()) {
super.executeQuery().next();
super.executeQuery();
return 0;
}
return super.executeUpdate();
......@@ -1575,6 +1553,9 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements Call
if (resultSet == null) {
throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
}
if (resultSet.isBeforeFirst()) {
resultSet.next();
}
return resultSet;
} catch (Exception e) {
throw logAndConvert(e);
......
......@@ -35,12 +35,30 @@ public class TestCallableStatement extends TestBase {
public void test() throws SQLException {
deleteDb("callableStatement");
Connection conn = getConnection("callableStatement");
testCallWithResultSet(conn);
testCallWithResult(conn);
testPrepare(conn);
conn.close();
deleteDb("callableStatement");
}
private void testCallWithResultSet(Connection conn) throws SQLException {
CallableStatement call;
ResultSet rs;
call = conn.prepareCall("select 10");
call.execute();
rs = call.getResultSet();
rs.next();
assertEquals(10, rs.getInt(1));
call.executeUpdate();
rs = call.getResultSet();
rs.next();
assertEquals(10, rs.getInt(1));
}
private void testCallWithResult(Connection conn) throws SQLException {
CallableStatement call;
for (String s : new String[]{"{?= call abs(?)}", " { ? = call abs(?)}", " {? = call abs(?)}"}) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论