in core/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java [297:365]
public static String getParamString(Properties props) {
if (props == null) {
return "";
}
StringBuilder buf = new StringBuilder();
for (Map.Entry<String, String> entry : toMap(props).entrySet()) {
final String name = entry.getKey();
final String value = entry.getValue();
String quote = "";
if (buf.length() > 0) {
buf.append(';');
}
// write parameter name
if (name.startsWith(" ") || name.endsWith(" ")) {
quote = "'";
buf.append(quote);
}
int len = name.length();
for (int i = 0; i < len; ++i) {
char c = name.charAt(i);
if (c == '=') {
buf.append('=');
}
buf.append(c);
}
buf.append(quote); // might be empty
quote = "";
buf.append('=');
// write parameter value
len = value.length();
boolean hasSemi = value.indexOf(';') >= 0;
boolean hasSQ = value.indexOf('\'') >= 0;
boolean hasDQ = value.indexOf('"') >= 0;
if (value.startsWith(" ") || value.endsWith(" ")) {
quote = "'";
} else if (hasSemi || hasSQ || hasDQ) {
// try to choose the least painful quote
if (value.startsWith("\"")) {
quote = "'";
} else if (value.startsWith("'")) {
quote = "\"";
} else {
quote = hasSQ ? "\"" : "'";
}
}
char q;
if (quote.length() > 0) {
buf.append(quote);
q = quote.charAt(0);
} else {
q = '\0';
}
for (int i = 0; i < len; ++i) {
char c = value.charAt(i);
if (c == q) {
buf.append(q);
}
buf.append(c);
}
buf.append(quote); // might be empty
}
return buf.toString();
}