提交 05db33de authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

ARRAY, INTERSECTS, and INTERVAL should be keywords too

上级 5ae94953
......@@ -475,11 +475,13 @@ There is a list of keywords that can't be used as identifiers (table names, colu
unless they are quoted (surrounded with double quotes). The list is currently:
</p><p>
<code>
ALL, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, DISTINCT, EXCEPT,
EXISTS, FALSE, FETCH, FOR, FOREIGN, FROM, FULL, GROUP, HAVING, INNER, INTERSECT, INTERSECTS,
IS, JOIN, LIKE, LIMIT, LOCALTIME, LOCALTIMESTAMP, MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER,
PRIMARY, ROW, ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE,
WINDOW, WITH
ALL, ARRAY, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME,
CURRENT_TIMESTAMP, DISTINCT, EXCEPT, EXISTS, FALSE, FETCH, FOR,
FOREIGN, FROM, FULL, GROUP, HAVING, INNER, INTERSECT, INTERSECTS,
INTERVAL, IS, JOIN, LIKE, LIMIT, LOCALTIME, LOCALTIMESTAMP,
MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROW,
ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE,
UNION, UNIQUE, WHERE, WINDOW, WITH
</code>
</p><p>
Certain words of this list are keywords because they are functions that can be used without '()',
......
......@@ -9,6 +9,7 @@
package org.h2.command;
import static org.h2.util.ParserUtil.ALL;
import static org.h2.util.ParserUtil.ARRAY;
import static org.h2.util.ParserUtil.CHECK;
import static org.h2.util.ParserUtil.CONSTRAINT;
import static org.h2.util.ParserUtil.CROSS;
......@@ -29,6 +30,8 @@ import static org.h2.util.ParserUtil.HAVING;
import static org.h2.util.ParserUtil.IDENTIFIER;
import static org.h2.util.ParserUtil.INNER;
import static org.h2.util.ParserUtil.INTERSECT;
import static org.h2.util.ParserUtil.INTERSECTS;
import static org.h2.util.ParserUtil.INTERVAL;
import static org.h2.util.ParserUtil.IS;
import static org.h2.util.ParserUtil.JOIN;
import static org.h2.util.ParserUtil.LIKE;
......@@ -417,6 +420,8 @@ public class Parser {
null,
// ALL
"ALL",
// ARRAY
"ARRAY",
// CHECK
"CHECK",
// CONSTRAINT
......@@ -455,6 +460,10 @@ public class Parser {
"INNER",
// INTERSECT
"INTERSECT",
// INTERSECTS
"INTERSECTS",
// INTERVAL
"INTERVAL",
// IS
"IS",
// JOIN
......@@ -2747,7 +2756,7 @@ public class Parser {
read(CLOSE_PAREN);
return new ConditionExists(query);
}
if (readIf("INTERSECTS")) {
if (readIf(INTERSECTS)) {
read(OPEN_PAREN);
Expression r1 = readConcat();
read(COMMA);
......@@ -3808,6 +3817,22 @@ public class Parser {
}
}
break;
case ARRAY: {
read();
read(OPEN_BRACKET);
ArrayList<Expression> list = Utils.newSmallArrayList();
if (!readIf(CLOSE_BRACKET)) {
list.add(readExpression());
while (readIf(COMMA)) {
list.add(readExpression());
}
read(CLOSE_BRACKET);
}
return new ExpressionList(list.toArray(new Expression[0]), true);
}
case INTERVAL:
read();
return readInterval();
case ROW: {
read();
read(OPEN_PAREN);
......@@ -3915,20 +3940,6 @@ public class Parser {
ch &= 0xffdf;
}
switch (ch) {
case 'A':
if (equalsToken("ARRAY", name)) {
read(OPEN_BRACKET);
ArrayList<Expression> list = Utils.newSmallArrayList();
if (!readIf(CLOSE_BRACKET)) {
list.add(readExpression());
while (readIf(COMMA)) {
list.add(readExpression());
}
read(CLOSE_BRACKET);
}
return new ExpressionList(list.toArray(new Expression[0]), true);
}
break;
case 'C':
if (equalsToken("CURRENT_USER", name)) {
return readFunctionWithoutParameters("USER");
......@@ -3956,11 +3967,6 @@ public class Parser {
return ValueExpression.get(ValueString.get(text));
}
break;
case 'I':
if (equalsToken("INTERVAL", name)) {
return readInterval();
}
break;
case 'N':
if (equalsToken("NEXT", name) && readIf("VALUE")) {
read(FOR);
......@@ -5171,7 +5177,7 @@ public class Parser {
read("ZONE");
original = "TIMESTAMP WITHOUT TIME ZONE";
}
} else if (readIf("INTERVAL")) {
} else if (readIf(INTERVAL)) {
if (readIf("YEAR")) {
if (readIf(OPEN_PAREN)) {
originalPrecision = readNonNegativeInt();
......
......@@ -1547,12 +1547,13 @@ public class JdbcDatabaseMetaData extends TraceObject implements
* </pre>
* The complete list of keywords (including SQL-2003 keywords) is:
* <pre>
* ALL, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP,
* DISTINCT, EXCEPT, EXISTS, FALSE, FETCH, FOR, FOREIGN, FROM, FULL, GROUP,
* HAVING, INNER, INTERSECT, INTERSECTS, IS, JOIN, LIKE, LIMIT, LOCALTIME,
* LOCALTIMESTAMP, MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROW, ROWNUM,
* SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE,
* WINDOW, WITH
* ALL, ARRAY, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME,
* CURRENT_TIMESTAMP, DISTINCT, EXCEPT, EXISTS, FALSE, FETCH, FOR,
* FOREIGN, FROM, FULL, GROUP, HAVING, INNER, INTERSECT, INTERSECTS,
* INTERVAL, IS, JOIN, LIKE, LIMIT, LOCALTIME, LOCALTIMESTAMP,
* MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROW,
* ROWNUM, SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE,
* UNION, UNIQUE, WHERE, WINDOW, WITH
* </pre>
*
* @return a list of additional the keywords
......
......@@ -22,10 +22,15 @@ public class ParserUtil {
*/
public static final int ALL = IDENTIFIER + 1;
/**
* The token "ARRAY".
*/
public static final int ARRAY = ALL + 1;
/**
* The token "CHECK".
*/
public static final int CHECK = ALL + 1;
public static final int CHECK = ARRAY + 1;
/**
* The token "CONSTRAINT".
......@@ -117,10 +122,20 @@ public class ParserUtil {
*/
public static final int INTERSECT = INNER + 1;
/**
* The token "INTERSECTS".
*/
public static final int INTERSECTS = INTERSECT + 1;
/**
* The token "INTERVAL".
*/
public static final int INTERVAL = INTERSECTS + 1;
/**
* The token "IS".
*/
public static final int IS = INTERSECT + 1;
public static final int IS = INTERVAL + 1;
/**
* The token "JOIN".
......@@ -317,6 +332,8 @@ public class ParserUtil {
case 'A':
if (eq("ALL", s, ignoreCase, start, end)) {
return ALL;
} else if (eq("ARRAY", s, ignoreCase, start, end)) {
return ARRAY;
}
return IDENTIFIER;
case 'C':
......@@ -376,14 +393,13 @@ public class ParserUtil {
return INNER;
} else if (eq("INTERSECT", s, ignoreCase, start, end)) {
return INTERSECT;
} else if (eq("INTERSECTS", s, ignoreCase, start, end)) {
return INTERSECTS;
} else if (eq("INTERVAL", s, ignoreCase, start, end)) {
return INTERVAL;
} else if (eq("IS", s, ignoreCase, start, end)) {
return IS;
}
if (additionalKeywords) {
if (eq("INTERSECTS", s, ignoreCase, start, end)) {
return KEYWORD;
}
}
return IDENTIFIER;
case 'J':
if (eq("JOIN", s, ignoreCase, start, end)) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论