提交 c8217a52 编写于 作者: S Serge Rider

SQL keywords reorganized


Former-commit-id: f1f854c2
上级 8a8039c3
......@@ -18,9 +18,11 @@
package org.jkiss.dbeaver.ext.oracle.model;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPKeywordType;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCDatabaseMetaData;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCSQLDialect;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
......@@ -40,6 +42,8 @@ class OracleSQLDialect extends JDBCSQLDialect {
addSQLKeyword("STRUCTURE");
addSQLKeyword("COMPUTE");
addSQLKeyword("STATISTICS");
addFunctions(
Arrays.asList("SUBSTR", "APPROX_COUNT_DISTINCT"));
}
@NotNull
......
......@@ -354,14 +354,11 @@ public class JDBCSQLDialect extends BasicSQLDialect {
for (String func : makeStringList(metaData.getTimeDateFunctions())) {
allFunctions.add(func.toUpperCase());
}
functions.addAll(allFunctions);
addFunctions(allFunctions);
}
catch (Throwable e) {
log.error(e);
}
// Remove types and functions from reserved words list
addKeywords(functions, DBPKeywordType.FUNCTION);
}
private static List<String> makeStringList(String source)
......
......@@ -45,7 +45,7 @@ public class BasicSQLDialect implements SQLDialect {
private TreeMap<String, DBPKeywordType> allKeywords = new TreeMap<>();
protected final TreeSet<String> reservedWords = new TreeSet<>();
protected final TreeSet<String> functions = new TreeSet<>();
private final TreeSet<String> functions = new TreeSet<>();
protected final TreeSet<String> types = new TreeSet<>();
protected final TreeSet<String> tableQueryWords = new TreeSet<>();
protected final TreeSet<String> columnQueryWords = new TreeSet<>();
......@@ -88,13 +88,18 @@ public class BasicSQLDialect implements SQLDialect {
allKeywords.remove(keyword);
}
protected void addFunctions(Collection<String> allFunctions) {
functions.addAll(allFunctions);
addKeywords(allFunctions, DBPKeywordType.FUNCTION);
}
public void addKeywords(Collection<String> set, DBPKeywordType type)
{
if (set != null) {
for (String keyword : set) {
reservedWords.add(keyword);
DBPKeywordType oldType = allKeywords.get(keyword);
if (oldType == null || oldType.ordinal() > type.ordinal()) {
if (oldType == null || oldType.ordinal() < type.ordinal()) {
allKeywords.put(keyword, type);
}
}
......@@ -300,9 +305,11 @@ public class BasicSQLDialect implements SQLDialect {
protected void loadStandardKeywords()
{
// Add default set of keywords
Collections.addAll(reservedWords, SQLConstants.SQL2003_RESERVED_KEYWORDS);
Collections.addAll(reservedWords, SQLConstants.SQL2003_NON_RESERVED_KEYWORDS);
Collections.addAll(reservedWords, SQLConstants.SQL_EX_KEYWORDS);
Set<String> all = new HashSet<>();
Collections.addAll(all, SQLConstants.SQL2003_RESERVED_KEYWORDS);
//Collections.addAll(reservedWords, SQLConstants.SQL2003_NON_RESERVED_KEYWORDS);
Collections.addAll(all, SQLConstants.SQL_EX_KEYWORDS);
Collections.addAll(functions, SQLConstants.SQL2003_FUNCTIONS);
Collections.addAll(tableQueryWords, SQLConstants.TABLE_KEYWORDS);
Collections.addAll(columnQueryWords, SQLConstants.COLUMN_KEYWORDS);
......@@ -312,8 +319,9 @@ public class BasicSQLDialect implements SQLDialect {
// Add default types
Collections.addAll(types, SQLConstants.DEFAULT_TYPES);
addKeywords(all, DBPKeywordType.KEYWORD);
addKeywords(types, DBPKeywordType.TYPE);
addKeywords(reservedWords, DBPKeywordType.KEYWORD);
addKeywords(functions, DBPKeywordType.FUNCTION);
}
}
......@@ -66,7 +66,6 @@ public class SQLConstants {
};
public static final String[] SQL2003_RESERVED_KEYWORDS = {
"ABS",
"ALL",
"ALLOCATE",
"ALTER",
......@@ -80,29 +79,23 @@ public class SQLConstants {
"AT",
"ATOMIC",
"AUTHORIZATION",
"AVG",
"BEGIN",
"BETWEEN",
"BIGINT",
"BINARY",
"BLOB",
"BOOLEAN",
"BOTH",
"BY",
"CALL",
"CALLED",
"CARDINALITY",
"CASCADE",
"CASCADED",
"CASE",
"CAST",
"CEIL",
"CEILING",
"CHAR",
"CHAR_LENGTH",
"CHARACTER",
"CHARACTER_LENGTH",
"CHECK",
"CLOB",
"CLOSE",
"COALESCE",
"COLLATE",
......@@ -115,7 +108,6 @@ public class SQLConstants {
"CONVERT",
"CORR",
"CORRESPONDING",
"COUNT",
"COVAR_POP",
"COVAR_SAMP",
"CREATE",
......@@ -123,21 +115,11 @@ public class SQLConstants {
"CUBE",
"CUME_DIST",
"CURRENT",
"CURRENT_DATE",
"CURRENT_DEFAULT_TRANSFORM_GROUP",
"CURRENT_PATH",
"CURRENT_ROLE",
"CURRENT_TIME",
"CURRENT_TIMESTAMP",
"CURRENT_TRANSFORM_GROUP_FOR_TYPE",
"CURRENT_USER",
"CURSOR",
"CYCLE",
"DATE",
"DAY",
"DEALLOCATE",
"DEC",
"DECIMAL",
"DECLARE",
"DEFAULT",
"DELETE",
......@@ -147,7 +129,6 @@ public class SQLConstants {
"DETERMINISTIC",
"DISCONNECT",
"DISTINCT",
"DOUBLE",
"DROP",
"DYNAMIC",
"EACH",
......@@ -167,8 +148,6 @@ public class SQLConstants {
"FALSE",
"FETCH",
"FILTER",
"FLOAT",
"FLOOR",
"FOR",
"FOREIGN",
"FREE",
......@@ -191,8 +170,6 @@ public class SQLConstants {
"INOUT",
"INSENSITIVE",
"INSERT",
"INT",
"INTEGER",
"INTERSECT",
"INTERSECTION",
"INTERVAL",
......@@ -202,20 +179,16 @@ public class SQLConstants {
"LANGUAGE",
"LARGE",
"LATERAL",
"LEADING",
"LEFT",
"LIKE",
"LN",
"LOCAL",
"LOCALTIME",
"LOCALTIMESTAMP",
"LOWER",
"MATCH",
"MAX",
"MEMBER",
"MERGE",
"METHOD",
"MIN",
"MINUTE",
"MOD",
"MODIFIES",
......@@ -234,7 +207,6 @@ public class SQLConstants {
"NULL",
"NULLIF",
"NUMERIC",
"OCTET_LENGTH",
"OF",
"OLD",
"ON",
......@@ -249,11 +221,7 @@ public class SQLConstants {
"OVERLAY",
"PARAMETER",
"PARTITION",
"PERCENT_RANK",
"PERCENTILE_CONT",
"PERCENTILE_DISC",
"POSITION",
"POWER",
"PRECISION",
"PREPARE",
"PRIMARY",
......@@ -266,15 +234,6 @@ public class SQLConstants {
"REF",
"REFERENCES",
"REFERENCING",
"REGR_AVGX",
"REGR_AVGY",
"REGR_COUNT",
"REGR_INTERCEPT",
"REGR_R2",
"REGR_SLOPE",
"REGR_SXX",
"REGR_SXY",
"REGR_SYY",
"RELEASE",
"RESULT",
"RETURN",
......@@ -304,22 +263,17 @@ public class SQLConstants {
"SQLEXCEPTION",
"SQLSTATE",
"SQLWARNING",
"SQRT",
"START",
"STATIC",
"STDDEV_POP",
"STDDEV_SAMP",
"SUBMULTISET",
"SUBSTRING",
"SUM",
"SYMMETRIC",
"SYSTEM",
"SYSTEM_USER",
"TABLE",
"TABLESAMPLE",
"THEN",
"TIME",
"TIMESTAMP",
"TIMEZONE_HOUR",
"TIMEZONE_MINUTE",
"TO",
......@@ -328,15 +282,12 @@ public class SQLConstants {
"TRANSLATION",
"TREAT",
"TRIGGER",
"TRIM",
"TRUE",
"UESCAPE",
"UNION",
"UNIQUE",
"UNKNOWN",
"UNNEST",
"UPDATE",
"UPPER",
"USER",
"USING",
"VALUE",
......@@ -356,6 +307,47 @@ public class SQLConstants {
"YEAR",
};
public static final String[] SQL2003_FUNCTIONS = {
"ABS",
"AVG",
"CHAR_LENGTH",
"CHARACTER_LENGTH",
"COUNT",
"CURRENT_DATE",
"CURRENT_DEFAULT_TRANSFORM_GROUP",
"CURRENT_PATH",
"CURRENT_ROLE",
"CURRENT_TIME",
"CURRENT_TIMESTAMP",
"CURRENT_TRANSFORM_GROUP_FOR_TYPE",
"CURRENT_USER",
"FLOOR",
"LEADING",
"LOWER",
"MAX",
"MIN",
"OCTET_LENGTH",
"PERCENT_RANK",
"PERCENTILE_CONT",
"PERCENTILE_DISC",
"POWER",
"REGR_AVGX",
"REGR_AVGY",
"REGR_COUNT",
"REGR_INTERCEPT",
"REGR_R2",
"REGR_SLOPE",
"REGR_SXX",
"REGR_SXY",
"REGR_SYY",
"SQRT",
"SUBSTRING",
"SUM",
"TRIM",
"UESCAPE",
"UPPER",
};
public static final String[] SQL2003_NON_RESERVED_KEYWORDS = {
"A",
"ABSOLUTE",
......@@ -573,9 +565,12 @@ public class SQLConstants {
"MODIFY",
};
public static final String[] DEFAULT_TYPES = {
"BOOLEAN",
"CHAR",
"VARCHAR",
"BINARY",
"VARBINARY",
"INT",
"INTEGER",
"SMALLINT",
"BIGINT",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册