in src/main/java/org/mariadb/jdbc/internal/util/Utils.java [280:403]
private static String replaceFunctionParameter(String functionString, Protocol protocol) {
char[] input = functionString.toCharArray();
StringBuilder sb = new StringBuilder();
int index;
for (index = 0; index < input.length; index++) {
if (input[index] != ' ') {
break;
}
}
for (;
((input[index] >= 'a' && input[index] <= 'z')
|| (input[index] >= 'A' && input[index] <= 'Z'))
&& index < input.length;
index++) {
sb.append(input[index]);
}
String func = sb.toString().toLowerCase(Locale.ROOT);
switch (func) {
case "convert":
// Handle "convert(value, type)" case
// extract last parameter, after the last ','
int lastCommaIndex = functionString.lastIndexOf(',');
int firstParentheses = functionString.indexOf('(');
String value = functionString.substring(firstParentheses + 1, lastCommaIndex);
for (index = lastCommaIndex + 1; index < input.length; index++) {
if (!Character.isWhitespace(input[index])) {
break;
}
}
int endParam = index + 1;
for (; endParam < input.length; endParam++) {
if ((input[endParam] < 'a' || input[endParam] > 'z')
&& (input[endParam] < 'A' || input[endParam] > 'Z')
&& input[endParam] != '_') {
break;
}
}
String typeParam = new String(input, index, endParam - index).toUpperCase(Locale.ROOT);
if (typeParam.startsWith("SQL_")) {
typeParam = typeParam.substring(4);
}
switch (typeParam) {
case "BOOLEAN":
return "1=" + value;
case "BIGINT":
case "SMALLINT":
case "TINYINT":
typeParam = "SIGNED INTEGER";
break;
case "BIT":
typeParam = "UNSIGNED INTEGER";
break;
case "BLOB":
case "VARBINARY":
case "LONGVARBINARY":
case "ROWID":
typeParam = "BINARY";
break;
case "NCHAR":
case "CLOB":
case "NCLOB":
case "DATALINK":
case "VARCHAR":
case "NVARCHAR":
case "LONGVARCHAR":
case "LONGNVARCHAR":
case "SQLXML":
case "LONGNCHAR":
typeParam = "CHAR";
break;
case "DOUBLE":
case "FLOAT":
if (protocol.isServerMariaDb() || protocol.versionGreaterOrEqual(8, 0, 17)) {
typeParam = "DOUBLE";
break;
}
return "0.0+" + value;
case "REAL":
case "NUMERIC":
typeParam = "DECIMAL";
break;
case "TIMESTAMP":
typeParam = "DATETIME";
break;
default:
break;
}
return new String(input, 0, index)
+ typeParam
+ new String(input, endParam, input.length - endParam);
case "timestampdiff":
case "timestampadd":
// Skip to first parameter
for (; index < input.length; index++) {
if (!Character.isWhitespace(input[index]) && input[index] != '(') {
break;
}
}
if (index < input.length - 8) {
String paramPrefix = new String(input, index, 8);
if ("SQL_TSI_".equals(paramPrefix)) {
return new String(input, 0, index)
+ new String(input, index + 8, input.length - (index + 8));
}
}
return functionString;
default:
return functionString;
}
}