Skip to content

Commit

Permalink
Fix Sybase SimpleJdbcCall named parameter binding
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppemilicia authored and jhoeller committed Dec 8, 2023
1 parent b3a3b79 commit 748dd94
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,9 @@ public String createCallString() {
* @since 4.2
*/
protected String createParameterBinding(SqlParameter parameter) {
return (isNamedBinding() ? parameter.getName() + " => ?" : "?");
Assert.state(this.metaDataProvider != null, "No CallMetaDataProvider available");

return (isNamedBinding() ? this.metaDataProvider.namedParamBindingToUse(parameter.getName()) : "?");
}

private static String lowerCase(@Nullable String paramName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,11 @@ void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @N
*/
boolean isSupportsSchemasInProcedureCalls();

/**
* Returns the name of the named parameter to use for binding the given parameter name.
* @param paramName the name of the parameter to bind
* @return the name of the named parameter to use for binding the given parameter name,
*/
String namedParamBindingToUse(@Nullable String paramName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ public boolean isSupportsSchemasInProcedureCalls() {
return this.supportsSchemasInProcedureCalls;
}

/**
* Returns the name of the named parameter to use for binding the given parameter name.
* @param paramName the name of the parameter to bind
* @return the name of the named parameter to use for binding the given parameter name,
*/
@Override
public String namedParamBindingToUse(@Nullable String paramName) {
return paramName + " => ?";
}

/**
* Specify whether the database uses upper case for identifiers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public boolean byPassReturnParameter(String parameterName) {
RETURN_VALUE_NAME.equals(parameterNameToUse(parameterName)));
}

@Override
public String namedParamBindingToUse(@Nullable String paramName) {
return paramName + " = ?";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,17 @@ private void verifyAddInvoiceWithMetaData(boolean isFunction) throws SQLExceptio
verify(procedureColumnsResultSet).close();
}

@Test
void correctSybaseFunctionStatementNamed() throws Exception {
given(databaseMetaData.getDatabaseProductName()).willReturn("Sybase");
SimpleJdbcCall adder = new SimpleJdbcCall(dataSource)
.withoutProcedureColumnMetaDataAccess()
.withNamedBinding()
.withProcedureName("ADD_INVOICE")
.declareParameters(new SqlParameter("@AMOUNT", Types.NUMERIC))
.declareParameters(new SqlParameter("@CUSTID", Types.NUMERIC));
adder.compile();
verifyStatement(adder, "{call ADD_INVOICE(@AMOUNT = ?, @CUSTID = ?)}");
}

}

0 comments on commit 748dd94

Please sign in to comment.