Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-967] callable statement clearParameters() doesn't take in accou…
…nt OUTPUT parameters
  • Loading branch information
rusher committed May 13, 2022
1 parent 8978826 commit a6972ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/mariadb/jdbc/BaseCallableStatement.java
Expand Up @@ -16,6 +16,7 @@
import org.mariadb.jdbc.client.result.Result;
import org.mariadb.jdbc.codec.Parameter;
import org.mariadb.jdbc.export.ExceptionFactory;
import org.mariadb.jdbc.util.ParameterList;

/** Common methods for function/stored procedure */
public abstract class BaseCallableStatement extends ServerPreparedStatement
Expand Down Expand Up @@ -167,6 +168,13 @@ public void registerOutParameter(int parameterIndex, int sqlType, int scale) thr
registerOutParameter(parameterIndex, sqlType);
}

@Override
public void clearParameters() throws SQLException {
checkNotClosed();
parameters = new ParameterList();
outputParameters.stream().forEach(index -> parameters.set(index - 1, Parameter.NULL_PARAMETER));
}

/**
* Retrieves whether the last OUT parameter read had the value of SQL <code>NULL</code>. Note that
* this method should be called only after calling a getter method; otherwise, there is no value
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/FunctionTest.java
Expand Up @@ -26,7 +26,20 @@ public void basicFunction() throws SQLException {
callableStatement.setInt(2, 2);
callableStatement.setInt(3, 3);
callableStatement.execute();

assertEquals(6, callableStatement.getInt(1));

callableStatement.clearParameters();
callableStatement.setInt(2, 3);
callableStatement.setInt(3, 3);
callableStatement.execute();
assertEquals(9, callableStatement.getInt(1));

callableStatement.clearParameters();
assertThrowsContains(
SQLTransientConnectionException.class,
() -> callableStatement.execute(),
"Parameter at position 1 is not set");
}

try (CallableStatement callableStatement =
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java
Expand Up @@ -134,6 +134,10 @@ public void basicProcedure() throws Throwable {
callableStatement.registerOutParameter(6, JDBCType.TIMESTAMP);
callableStatement.registerOutParameter(7, JDBCType.TIMESTAMP);
checkResults(callableStatement);

callableStatement.clearParameters();
checkResults(callableStatement);

ParameterMetaData meta = callableStatement.getParameterMetaData();

assertEquals("INT", meta.getParameterTypeName(1));
Expand Down

0 comments on commit a6972ba

Please sign in to comment.