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