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

Use switch over first letter in Parser.readTermWithIdentifier()

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