Skip to content

Commit

Permalink
CONJ-889 - callableStatement using function throw wrong error on getX…
Browse files Browse the repository at this point in the history
…XX methods
  • Loading branch information
rusher committed Jun 14, 2021
1 parent 42e861f commit 126aecb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private int nameToIndex(String parameterName) throws SQLException {
*/
private int nameToOutputIndex(String parameterName) throws SQLException {
for (int i = 0; i < parameterMetadata.getParameterCount(); i++) {
String name = parameterMetadata.getParameterName(i);
String name = parameterMetadata.getParameterName(i + 1);
if (name != null && name.equalsIgnoreCase(parameterName)) {
return i;
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/mariadb/jdbc/CallStatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ public void prepareStmtSimpleFunction() throws SQLException {
}
}

@Test
public void functionParameterByNameError() throws SQLException {
try (CallableStatement call =
sharedConnection.prepareCall("{? = call stmtSimpleFunction(?,?,?)}")){
call.setInt("a", 8);
call.setInt(3, 2);
call.setInt(4, 2);
call.execute();

try {
call.getString("b");
fail("must have thrown exception");
} catch (SQLDataException ee) {
assertTrue(ee.getMessage().contains("No such column"));
}

try {
call.getString("d");
fail("must have thrown exception");
} catch (SQLSyntaxErrorException ee) {
assertTrue(ee.getMessage().contains("there is no parameter with the name d"));
}
assertEquals(8, call.getInt(1));
}
}

@Test
public void prepareStmtWithOutParameter() throws SQLException {
Assume.assumeTrue(sharedUsePrepare());
Expand Down

0 comments on commit 126aecb

Please sign in to comment.