提交 d82eb12f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use isSimpleIdentifier() in Parser.quoteIdentifier() to avoid code duplication

上级 56fd6802
......@@ -6830,34 +6830,22 @@ public class Parser {
* @return the quoted identifier
*/
public static String quoteIdentifier(String s) {
if (s == null || s.length() == 0) {
if (s == null) {
return "\"\"";
}
char c = s.charAt(0);
// lowercase a-z is quoted as well
if ((!Character.isLetter(c) && c != '_') || Character.isLowerCase(c)) {
return StringUtils.quoteIdentifier(s);
}
for (int i = 1, length = s.length(); i < length; i++) {
c = s.charAt(i);
if ((!Character.isLetterOrDigit(c) && c != '_') ||
Character.isLowerCase(c)) {
return StringUtils.quoteIdentifier(s);
}
}
if (isKeyword(s, true)) {
return StringUtils.quoteIdentifier(s);
}
return s;
if (isSimpleIdentifier(s))
return s;
return StringUtils.quoteIdentifier(s);
}
/**
* @param s
* identifier to check
* @return is specified identifier may be used without quotes
* @throws NullPointerException if s is {@code null}
*/
public static boolean isSimpleIdentifier(String s) {
if (s == null || s.length() == 0) {
if (s.length() == 0) {
return false;
}
char c = s.charAt(0);
......
......@@ -1332,9 +1332,6 @@ public class JdbcStatement extends TraceObject implements Statement, JdbcStateme
*/
@Override
public boolean isSimpleIdentifier(String identifier) throws SQLException {
if (identifier == null)
// To conform with JDBC specification
throw new NullPointerException();
return Parser.isSimpleIdentifier(identifier);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论