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

Use switch over first letter in Parser.readTermWithIdentifier()

上级 9f90c8ed
......@@ -3810,123 +3810,144 @@ public class Parser {
}
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");
} else if (equalsToken("LOCALTIMESTAMP", name)) {
r = readFunctionWithoutParameters("LOCALTIMESTAMP");
} else if (equalsToken("SYSDATE", name)) {
r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
} else if (equalsToken("SYSTIMESTAMP", name)) {
r = readFunctionWithoutParameters("CURRENT_TIMESTAMP");
} else if (equalsToken("CURRENT_DATE", name)) {
r = readFunctionWithoutParameters("CURRENT_DATE");
} else if (equalsToken("TODAY", name)) {
r = readFunctionWithoutParameters("CURRENT_DATE");
} else if (equalsToken("CURRENT_TIME", name)) {
r = readFunctionWithoutParameters("CURRENT_TIME");
} else if (equalsToken("LOCALTIME", name)) {
r = readFunctionWithoutParameters("LOCALTIME");
} else if (equalsToken("SYSTIME", name)) {
r = readFunctionWithoutParameters("CURRENT_TIME");
} else if (database.getMode().getEnum() == ModeEnum.DB2 && equalsToken("CURRENT", name)) {
r = parseDB2SpecialRegisters(name);
} else if (equalsToken("NEXT", name) && readIf("VALUE")) {
read(FOR);
Sequence sequence = readSequence();
r = new SequenceValue(sequence);
} else if (equalsToken("TIME", name)) {
boolean without = readIf("WITHOUT");
if (without) {
read("TIME");
read("ZONE");
// Unquoted identifier is never empty
char ch = name.charAt(0);
switch (ch) {
case 'C':
case 'c':
if (equalsToken("CURRENT_DATE", name)) {
return readFunctionWithoutParameters("CURRENT_DATE");
} else if (equalsToken("CURRENT_TIME", name)) {
return readFunctionWithoutParameters("CURRENT_TIME");
} else if (equalsToken("CURRENT_TIMESTAMP", name)) {
return readFunctionWithoutParameters("CURRENT_TIMESTAMP");
} else if (equalsToken("CURRENT_USER", name)) {
return readFunctionWithoutParameters("USER");
} else if (database.getMode().getEnum() == ModeEnum.DB2 && equalsToken("CURRENT", name)) {
return parseDB2SpecialRegisters(name);
}
if (currentTokenType != VALUE
|| currentValue.getType() != Value.STRING) {
if (without) {
throw getSyntaxError();
}
r = new ExpressionColumn(database, null, null, name);
} else {
String time = currentValue.getString();
break;
case 'D':
case 'd':
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING &&
(equalsToken("DATE", name) || equalsToken("D", name))) {
String date = currentValue.getString();
read();
r = ValueExpression.get(ValueTime.parse(time));
return ValueExpression.get(ValueDate.parse(date));
}
} else if (equalsToken("TIMESTAMP", name)) {
if (readIf(WITH)) {
read("TIME");
read("ZONE");
if (currentTokenType != VALUE
|| currentValue.getType() != Value.STRING) {
throw getSyntaxError();
}
String timestamp = currentValue.getString();
break;
case 'E':
case 'e':
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING && equalsToken("E", name)) {
String text = currentValue.getString();
// the PostgreSQL ODBC driver uses
// LIKE E'PROJECT\\_DATA' instead of LIKE
// 'PROJECT\_DATA'
// N: SQL-92 "National Language" strings
text = StringUtils.replaceAll(text, "\\\\", "\\");
read();
r = ValueExpression.get(ValueTimestampTimeZone.parse(timestamp));
} else {
return ValueExpression.get(ValueString.get(text));
}
break;
case 'I':
case 'i':
if (equalsToken("INTERVAL", name)) {
return readInterval();
}
break;
case 'L':
case 'l':
if (equalsToken("LOCALTIME", name)) {
return readFunctionWithoutParameters("LOCALTIME");
} else if (equalsToken("LOCALTIMESTAMP", name)) {
return readFunctionWithoutParameters("LOCALTIMESTAMP");
}
break;
case 'N':
case 'n':
if (equalsToken("NEXT", name) && readIf("VALUE")) {
read(FOR);
return new SequenceValue(readSequence());
} else if (currentTokenType == VALUE && currentValue.getType() == Value.STRING && equalsToken("N", name)) {
// SQL-92 "National Language" strings
String text = currentValue.getString();
read();
return ValueExpression.get(ValueString.get(text));
}
break;
case 'S':
case 's':
if (equalsToken("SYSDATE", name)) {
return readFunctionWithoutParameters("CURRENT_TIMESTAMP");
} else if (equalsToken("SYSTIME", name)) {
return readFunctionWithoutParameters("CURRENT_TIME");
} else if (equalsToken("SYSTIMESTAMP", name)) {
return readFunctionWithoutParameters("CURRENT_TIMESTAMP");
}
break;
case 'T':
case 't':
if (equalsToken("TIME", name)) {
boolean without = readIf("WITHOUT");
if (without) {
read("TIME");
read("ZONE");
}
if (currentTokenType != VALUE
|| currentValue.getType() != Value.STRING) {
if (without) {
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
String time = currentValue.getString();
read();
return ValueExpression.get(ValueTime.parse(time));
} else if (without) {
throw getSyntaxError();
}
} else if (equalsToken("TIMESTAMP", name)) {
if (readIf(WITH)) {
read("TIME");
read("ZONE");
if (currentTokenType != VALUE || currentValue.getType() != Value.STRING) {
throw getSyntaxError();
}
r = new ExpressionColumn(database, null, null, name);
String timestamp = currentValue.getString();
read();
return ValueExpression.get(ValueTimestampTimeZone.parse(timestamp));
} else {
boolean without = readIf("WITHOUT");
if (without) {
read("TIME");
read("ZONE");
}
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
String timestamp = currentValue.getString();
read();
return ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
} else if (without) {
throw getSyntaxError();
}
}
} else if (equalsToken("TODAY", name)) {
return readFunctionWithoutParameters("CURRENT_DATE");
} else if (currentTokenType == VALUE && currentValue.getType() == Value.STRING) {
if (equalsToken("T", name)) {
String time = currentValue.getString();
read();
return ValueExpression.get(ValueTime.parse(time));
} else if (equalsToken("TS", name)) {
String timestamp = currentValue.getString();
read();
r = ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
return ValueExpression.get(ValueTimestamp.parse(timestamp, database.getMode()));
}
}
} else if (equalsToken("INTERVAL", name)) {
r = readInterval();
} else if (currentTokenType == VALUE &&
currentValue.getType() == Value.STRING) {
if (equalsToken("DATE", name) ||
equalsToken("D", name)) {
String date = currentValue.getString();
read();
r = ValueExpression.get(ValueDate.parse(date));
} else if (equalsToken("T", name)) {
String time = currentValue.getString();
read();
r = ValueExpression.get(ValueTime.parse(time));
} else if (equalsToken("TS", name)) {
String timestamp = currentValue.getString();
read();
r = ValueExpression
.get(ValueTimestamp.parse(timestamp, database.getMode()));
} else if (equalsToken("X", name)) {
read();
byte[] buffer = StringUtils
.convertHexToBytes(currentValue.getString());
r = ValueExpression.get(ValueBytes.getNoCopy(buffer));
} else if (equalsToken("E", name)) {
String text = currentValue.getString();
// the PostgreSQL ODBC driver uses
// LIKE E'PROJECT\\_DATA' instead of LIKE
// 'PROJECT\_DATA'
// N: SQL-92 "National Language" strings
text = StringUtils.replaceAll(text, "\\\\", "\\");
read();
r = ValueExpression.get(ValueString.get(text));
} else if (equalsToken("N", name)) {
// SQL-92 "National Language" strings
String text = currentValue.getString();
break;
case 'X':
case 'x':
if (currentTokenType == VALUE && currentValue.getType() == Value.STRING && equalsToken("X", name)) {
byte[] buffer = StringUtils.convertHexToBytes(currentValue.getString());
read();
r = ValueExpression.get(ValueString.get(text));
} else {
r = new ExpressionColumn(database, null, null, name);
return ValueExpression.get(ValueBytes.getNoCopy(buffer));
}
} else {
r = new ExpressionColumn(database, null, null, name);
break;
}
return r;
return new ExpressionColumn(database, null, null, name);
}
private Expression readInterval() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论