Skip to content

Commit

Permalink
Polish 5b2df32
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniycheban committed Dec 11, 2024
1 parent 44e1f17 commit f85765b
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ private String prepareQuery(Object[] parameters) {
index += digit;
digits++;
}
String value = getParameterValuePart(parameters, index - 1);
if (index < 1 || index > parameters.length) {
throw new IllegalStateException("Invalid parameter reference at index: " + i);
}
String value = getParameterValuePart(parameters[index - 1]);
result.replace(offset + i - 1, offset + i + digits, value);
offset += value.length() - digits - 1;
break;
Expand All @@ -131,7 +134,7 @@ private String prepareQuery(Object[] parameters) {
String parameterName = sb.toString();
Integer index = this.namedParameters.get(parameterName);
Assert.notNull(index, () -> "No parameter found for name: " + parameterName);
String value = getParameterValuePart(parameters, index);
String value = getParameterValuePart(parameters[index]);
result.replace(offset + i - 1, offset + i + parameterName.length(), value);
offset += value.length() - parameterName.length() - 1;
break;
Expand All @@ -141,9 +144,7 @@ private String prepareQuery(Object[] parameters) {
return result.toString();
}

private String getParameterValuePart(Object[] parameters, int index) {
Assert.state(index >= 0 && index < parameters.length, () -> "No parameter found at index: " + index);
Object value = parameters[index];
private String getParameterValuePart(Object value) {
if (value instanceof String) {
return "'" + value + "'";
}
Expand Down

0 comments on commit f85765b

Please sign in to comment.