private boolean isKeyword(String s) { if (!identifiersToUpper) { // if not yet converted to uppercase, do it now s = StringUtils.toUpperEnglish(s); } return isKeyword(s, false); }
/** * Add double quotes around an identifier if required. * * @param s the identifier * @return the quoted identifier */ public static String quoteIdentifier(String s) { if (s == null || s.length() == 0) { 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; }
private CreateConstant parseCreateConstant() { boolean ifNotExists = readIfNotExists(); String constantName = readIdentifierWithSchema(); Schema schema = getSchema(); if (isKeyword(constantName)) { throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName); } read("VALUE"); Expression expr = readExpression(); CreateConstant command = new CreateConstant(session, schema); command.setConstantName(constantName); command.setExpression(expr); command.setIfNotExists(ifNotExists); return command; }
private CreateAggregate parseCreateAggregate(boolean force) { boolean ifNotExists = readIfNotExists(); CreateAggregate command = new CreateAggregate(session); command.setForce(force); String name = readIdentifierWithSchema(); if (isKeyword(name) || Function.getFunction(database, name) != null || getAggregateType(name) >= 0) { throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name); } command.setName(name); command.setSchema(getSchema()); command.setIfNotExists(ifNotExists); read("FOR"); command.setJavaClassMethod(readUniqueIdentifier()); return command; }