提交 9f90c8ed authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Extract Parser.readTermWithIdentifier()

上级 7622dda9
......@@ -3699,7 +3699,119 @@ public class Parser {
r = readCase();
} else if (readIf(OPEN_PAREN)) {
r = readFunction(null, name);
} else if (equalsToken("CURRENT_USER", name)) {
} else {
r = readTermWithIdentifier(name);
}
}
break;
case MINUS_SIGN:
read();
if (currentTokenType == VALUE) {
r = ValueExpression.get(currentValue.negate());
if (r.getType() == Value.LONG &&
r.getValue(session).getLong() == Integer.MIN_VALUE) {
// convert Integer.MIN_VALUE to type 'int'
// (Integer.MAX_VALUE+1 is of type 'long')
r = ValueExpression.get(ValueInt.get(Integer.MIN_VALUE));
} else if (r.getType() == Value.DECIMAL &&
r.getValue(session).getBigDecimal()
.compareTo(Value.MIN_LONG_DECIMAL) == 0) {
// convert Long.MIN_VALUE to type 'long'
// (Long.MAX_VALUE+1 is of type 'decimal')
r = ValueExpression.get(ValueLong.MIN);
}
read();
} else {
r = new UnaryOperation(readTerm());
}
break;
case PLUS_SIGN:
read();
r = readTerm();
break;
case OPEN_PAREN:
read();
if (readIf(CLOSE_PAREN)) {
r = new ExpressionList(new Expression[0]);
} else {
r = readExpression();
if (readIfMore(true)) {
ArrayList<Expression> list = Utils.newSmallArrayList();
list.add(r);
if (!readIf(CLOSE_PAREN)) {
do {
list.add(readExpression());
} while (readIfMore(false));
}
r = new ExpressionList(list.toArray(new Expression[0]));
}
}
break;
case TRUE:
read();
r = ValueExpression.get(ValueBoolean.TRUE);
break;
case FALSE:
read();
r = ValueExpression.get(ValueBoolean.FALSE);
break;
case ROWNUM:
read();
if (readIf(OPEN_PAREN)) {
read(CLOSE_PAREN);
}
if (currentSelect == null && currentPrepared == null) {
throw getSyntaxError();
}
r = new Rownum(currentSelect == null ? currentPrepared
: currentSelect);
break;
case NULL:
read();
r = ValueExpression.getNull();
break;
case VALUE:
r = ValueExpression.get(currentValue);
read();
break;
default:
throw getSyntaxError();
}
if (readIf(OPEN_BRACKET)) {
Function function = Function.getFunction(database, "ARRAY_GET");
function.setParameter(0, r);
function.setParameter(1, readExpression());
r = function;
read(CLOSE_BRACKET);
}
if (readIf(COLON_COLON)) {
// PostgreSQL compatibility
if (isToken("PG_CATALOG")) {
read("PG_CATALOG");
read(DOT);
}
if (readIf("REGCLASS")) {
FunctionAlias f = findFunctionAlias(Constants.SCHEMA_MAIN,
"PG_GET_OID");
if (f == null) {
throw getSyntaxError();
}
Expression[] args = { r };
r = new JavaFunction(f, args);
} else {
Column col = parseColumnWithType(null, false);
Function function = Function.getFunction(database, "CAST");
function.setDataType(col);
function.setParameter(0, r);
r = function;
}
}
return r;
}
private Expression readTermWithIdentifier(String name) {
Expression r;
if (equalsToken("CURRENT_USER", name)) {
r = readFunctionWithoutParameters("USER");
} else if (equalsToken("CURRENT_TIMESTAMP", name)) {
r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
......@@ -3814,110 +3926,6 @@ public class Parser {
} else {
r = new ExpressionColumn(database, null, null, name);
}
}
break;
case MINUS_SIGN:
read();
if (currentTokenType == VALUE) {
r = ValueExpression.get(currentValue.negate());
if (r.getType() == Value.LONG &&
r.getValue(session).getLong() == Integer.MIN_VALUE) {
// convert Integer.MIN_VALUE to type 'int'
// (Integer.MAX_VALUE+1 is of type 'long')
r = ValueExpression.get(ValueInt.get(Integer.MIN_VALUE));
} else if (r.getType() == Value.DECIMAL &&
r.getValue(session).getBigDecimal()
.compareTo(Value.MIN_LONG_DECIMAL) == 0) {
// convert Long.MIN_VALUE to type 'long'
// (Long.MAX_VALUE+1 is of type 'decimal')
r = ValueExpression.get(ValueLong.MIN);
}
read();
} else {
r = new UnaryOperation(readTerm());
}
break;
case PLUS_SIGN:
read();
r = readTerm();
break;
case OPEN_PAREN:
read();
if (readIf(CLOSE_PAREN)) {
r = new ExpressionList(new Expression[0]);
} else {
r = readExpression();
if (readIfMore(true)) {
ArrayList<Expression> list = Utils.newSmallArrayList();
list.add(r);
if (!readIf(CLOSE_PAREN)) {
do {
list.add(readExpression());
} while (readIfMore(false));
}
r = new ExpressionList(list.toArray(new Expression[0]));
}
}
break;
case TRUE:
read();
r = ValueExpression.get(ValueBoolean.TRUE);
break;
case FALSE:
read();
r = ValueExpression.get(ValueBoolean.FALSE);
break;
case ROWNUM:
read();
if (readIf(OPEN_PAREN)) {
read(CLOSE_PAREN);
}
if (currentSelect == null && currentPrepared == null) {
throw getSyntaxError();
}
r = new Rownum(currentSelect == null ? currentPrepared
: currentSelect);
break;
case NULL:
read();
r = ValueExpression.getNull();
break;
case VALUE:
r = ValueExpression.get(currentValue);
read();
break;
default:
throw getSyntaxError();
}
if (readIf(OPEN_BRACKET)) {
Function function = Function.getFunction(database, "ARRAY_GET");
function.setParameter(0, r);
function.setParameter(1, readExpression());
r = function;
read(CLOSE_BRACKET);
}
if (readIf(COLON_COLON)) {
// PostgreSQL compatibility
if (isToken("PG_CATALOG")) {
read("PG_CATALOG");
read(DOT);
}
if (readIf("REGCLASS")) {
FunctionAlias f = findFunctionAlias(Constants.SCHEMA_MAIN,
"PG_GET_OID");
if (f == null) {
throw getSyntaxError();
}
Expression[] args = { r };
r = new JavaFunction(f, args);
} else {
Column col = parseColumnWithType(null, false);
Function function = Function.getFunction(database, "CAST");
function.setDataType(col);
function.setParameter(0, r);
r = function;
}
}
return r;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论