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

Parse datetime value functions as keywords unconditionally

上级 b1da72bd
......@@ -12,6 +12,9 @@ import static org.h2.util.ParserUtil.ALL;
import static org.h2.util.ParserUtil.CHECK;
import static org.h2.util.ParserUtil.CONSTRAINT;
import static org.h2.util.ParserUtil.CROSS;
import static org.h2.util.ParserUtil.CURRENT_DATE;
import static org.h2.util.ParserUtil.CURRENT_TIME;
import static org.h2.util.ParserUtil.CURRENT_TIMESTAMP;
import static org.h2.util.ParserUtil.DISTINCT;
import static org.h2.util.ParserUtil.EXCEPT;
import static org.h2.util.ParserUtil.EXISTS;
......@@ -30,6 +33,8 @@ import static org.h2.util.ParserUtil.IS;
import static org.h2.util.ParserUtil.JOIN;
import static org.h2.util.ParserUtil.LIKE;
import static org.h2.util.ParserUtil.LIMIT;
import static org.h2.util.ParserUtil.LOCALTIME;
import static org.h2.util.ParserUtil.LOCALTIMESTAMP;
import static org.h2.util.ParserUtil.MINUS;
import static org.h2.util.ParserUtil.NATURAL;
import static org.h2.util.ParserUtil.NOT;
......@@ -457,6 +462,10 @@ public class Parser {
"LIKE",
// LIMIT
"LIMIT",
// LOCALTIME
"LOCALTIME",
// LOCALTIMESTAMP
"LOCALTIMESTAMP",
// MINUS
"MINUS",
// NATURAL
......@@ -3523,6 +3532,14 @@ public class Parser {
}
}
private Expression readKeywordFunction(String name) {
if (readIf(OPEN_PAREN)) {
return readFunction(null, name);
} else {
return readFunctionWithoutParameters(name);
}
}
private Expression readFunctionWithoutParameters(String name) {
if (database.isAllowBuiltinAliasOverride()) {
FunctionAlias functionAlias = database.getSchema(session.getCurrentSchemaName()).findFunction(name);
......@@ -3806,6 +3823,26 @@ public class Parser {
r = ValueExpression.get(currentValue);
read();
break;
case CURRENT_DATE:
read();
r = readKeywordFunction("CURRENT_DATE");
break;
case CURRENT_TIME:
read();
r = readKeywordFunction("CURRENT_TIME");
break;
case CURRENT_TIMESTAMP:
read();
r = readKeywordFunction("CURRENT_TIMESTAMP");
break;
case LOCALTIME:
read();
r = readKeywordFunction("LOCALTIME");
break;
case LOCALTIMESTAMP:
read();
r = readKeywordFunction("LOCALTIMESTAMP");
break;
default:
throw getSyntaxError();
}
......@@ -3862,13 +3899,7 @@ public class Parser {
break;
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)) {
if (equalsToken("CURRENT_USER", name)) {
return readFunctionWithoutParameters("USER");
} else if (database.getMode().getEnum() == ModeEnum.DB2 && equalsToken("CURRENT", name)) {
return parseDB2SpecialRegisters(name);
......@@ -3902,14 +3933,6 @@ public class Parser {
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")) {
......@@ -4061,10 +4084,11 @@ public class Parser {
if (readIf(WITH)) {
read("TIME");
read("ZONE");
return readFunctionWithoutParameters("CURRENT_TIMESTAMP");
return readKeywordFunction("CURRENT_TIMESTAMP");
}
return readFunctionWithoutParameters("LOCALTIMESTAMP");
return readKeywordFunction("LOCALTIMESTAMP");
} else if (readIf("TIME")) {
// Time with fractional seconds is not supported by DB2
return readFunctionWithoutParameters("CURRENT_TIME");
} else if (readIf("DATE")) {
return readFunctionWithoutParameters("CURRENT_DATE");
......
......@@ -137,10 +137,20 @@ public class ParserUtil {
*/
public static final int LIMIT = LIKE + 1;
/**
* The token "LOCALTIME".
*/
public static final int LOCALTIME = LIMIT + 1;
/**
* The token "LOCALTIMESTAMP".
*/
public static final int LOCALTIMESTAMP = LOCALTIME + 1;
/**
* The token "MINUS".
*/
public static final int MINUS = LIMIT + 1;
public static final int MINUS = LOCALTIMESTAMP + 1;
/**
* The token "NATURAL".
......@@ -311,12 +321,12 @@ public class ParserUtil {
return CONSTRAINT;
} else if (eq("CROSS", s, ignoreCase, start, end)) {
return CROSS;
}
if (additionalKeywords) {
if (eq("CURRENT_DATE", s, ignoreCase, start, end) || eq("CURRENT_TIME", s, ignoreCase, start, end)
|| eq("CURRENT_TIMESTAMP", s, ignoreCase, start, end)) {
return KEYWORD;
}
} else if (eq("CURRENT_DATE", s, ignoreCase, start, end)) {
return CURRENT_DATE;
} else if (eq("CURRENT_TIME", s, ignoreCase, start, end)) {
return CURRENT_TIME;
} else if (eq("CURRENT_TIMESTAMP", s, ignoreCase, start, end)) {
return CURRENT_TIMESTAMP;
}
return IDENTIFIER;
case 'D':
......@@ -380,11 +390,10 @@ public class ParserUtil {
return LIMIT;
} else if (eq("LIKE", s, ignoreCase, start, end)) {
return LIKE;
}
if (additionalKeywords) {
if (eq("LOCALTIME", s, ignoreCase, start, end) || eq("LOCALTIMESTAMP", s, ignoreCase, start, end)) {
return KEYWORD;
}
} else if (eq("LOCALTIME", s, ignoreCase, start, end)) {
return LOCALTIME;
} else if (eq("LOCALTIMESTAMP", s, ignoreCase, start, end)) {
return LOCALTIMESTAMP;
}
return IDENTIFIER;
case 'M':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论