Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-791] correcting CallableStatement.getter for output parameter.
following methods :
getDate(int parameterIndex, Calendar cal)
getTimestamp(int parameterIndex)
getBlob(int parameterIndex)

where returning wrong index value when query did have value only IN before that index.
  • Loading branch information
rusher committed Jun 8, 2020
1 parent 7b569cb commit c1db252
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -336,7 +336,7 @@ public Date getDate(String parameterName, Calendar cal) throws SQLException {

@Override
public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
return getOutputResult().getDate(parameterIndex, cal);
return getOutputResult().getDate(indexToOutputIndex(parameterIndex), cal);
}

@Override
Expand All @@ -361,7 +361,7 @@ public Time getTime(int parameterIndex) throws SQLException {

@Override
public Timestamp getTimestamp(int parameterIndex) throws SQLException {
return getOutputResult().getTimestamp(parameterIndex);
return getOutputResult().getTimestamp(indexToOutputIndex(parameterIndex));
}

@Override
Expand Down Expand Up @@ -431,7 +431,7 @@ public Ref getRef(String parameterName) throws SQLException {

@Override
public Blob getBlob(int parameterIndex) throws SQLException {
return getOutputResult().getBlob(parameterIndex);
return getOutputResult().getBlob(indexToOutputIndex(parameterIndex));
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/org/mariadb/jdbc/StoredProcedureTest.java
Expand Up @@ -1662,4 +1662,18 @@ public void functionCaching() throws SQLException {
assertFalse(st3.execute());
}
}

@Test
public void testTimestampParameterOutput() throws Exception {
createProcedure(
"CONJ791", "(IN a TEXT, OUT b DATETIME) \nBEGIN\nSET b := '2006-01-01 01:01:16';\nEND");

// registering with VARCHAR Type
CallableStatement cstmt = sharedConnection.prepareCall("{call CONJ791(?, ?)}");
cstmt.setString(1, "o");
cstmt.registerOutParameter(2, Types.TIMESTAMP);
cstmt.execute();

assertEquals(Timestamp.valueOf("2006-01-01 01:01:16"), cstmt.getTimestamp(2));
}
}

0 comments on commit c1db252

Please sign in to comment.