Unverified 提交 40351e70 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #929 from katzyn/offset_fetch

Remove Mode.supportOffsetFetch
...@@ -154,7 +154,7 @@ public class DbContextRule implements Rule { ...@@ -154,7 +154,7 @@ public class DbContextRule implements Rule {
break; break;
} }
String alias = up.substring(0, i); String alias = up.substring(0, i);
if (ParserUtil.isKeyword(alias, true)) { if (ParserUtil.isKeyword(alias)) {
break; break;
} }
s = s.substring(alias.length()); s = s.substring(alias.length());
...@@ -301,7 +301,7 @@ public class DbContextRule implements Rule { ...@@ -301,7 +301,7 @@ public class DbContextRule implements Rule {
return s; return s;
} }
String alias = up.substring(0, i); String alias = up.substring(0, i);
if ("SET".equals(alias) || ParserUtil.isKeyword(alias, true)) { if ("SET".equals(alias) || ParserUtil.isKeyword(alias)) {
return s; return s;
} }
if (newAlias) { if (newAlias) {
......
...@@ -2022,38 +2022,34 @@ public class Parser { ...@@ -2022,38 +2022,34 @@ public class Parser {
command.setOrder(orderList); command.setOrder(orderList);
currentSelect = oldSelect; currentSelect = oldSelect;
} }
if (database.getMode().supportOffsetFetch) { // make sure aggregate functions will not work here
// make sure aggregate functions will not work here Select temp = currentSelect;
Select temp = currentSelect; currentSelect = null;
currentSelect = null; // http://sqlpro.developpez.com/SQL2008/
if (readIf("OFFSET")) {
// http://sqlpro.developpez.com/SQL2008/ command.setOffset(readExpression().optimize(session));
if (readIf("OFFSET")) { if (!readIf("ROW")) {
command.setOffset(readExpression().optimize(session)); readIf("ROWS");
if (!readIf("ROW")) {
readIf("ROWS");
}
} }
if (readIf("FETCH")) { }
if (!readIf("FIRST")) { if (readIf("FETCH")) {
read("NEXT"); if (!readIf("FIRST")) {
} read("NEXT");
if (readIf("ROW")) { }
command.setLimit(ValueExpression.get(ValueInt.get(1))); if (readIf("ROW")) {
} else { command.setLimit(ValueExpression.get(ValueInt.get(1)));
Expression limit = readExpression().optimize(session); } else {
command.setLimit(limit); Expression limit = readExpression().optimize(session);
if (!readIf("ROW")) { command.setLimit(limit);
read("ROWS"); if (!readIf("ROW")) {
} read("ROWS");
} }
read("ONLY");
} }
read("ONLY");
currentSelect = temp;
} }
currentSelect = temp;
if (readIf("LIMIT")) { if (readIf("LIMIT")) {
Select temp = currentSelect; temp = currentSelect;
// make sure aggregate functions will not work here // make sure aggregate functions will not work here
currentSelect = null; currentSelect = null;
Expression limit = readExpression().optimize(session); Expression limit = readExpression().optimize(session);
...@@ -4195,7 +4191,7 @@ public class Parser { ...@@ -4195,7 +4191,7 @@ public class Parser {
// if not yet converted to uppercase, do it now // if not yet converted to uppercase, do it now
s = StringUtils.toUpperEnglish(s); s = StringUtils.toUpperEnglish(s);
} }
return getSaveTokenType(s, database.getMode().supportOffsetFetch, false); return getSaveTokenType(s, false);
} }
private boolean isKeyword(String s) { private boolean isKeyword(String s) {
...@@ -4203,11 +4199,11 @@ public class Parser { ...@@ -4203,11 +4199,11 @@ public class Parser {
// if not yet converted to uppercase, do it now // if not yet converted to uppercase, do it now
s = StringUtils.toUpperEnglish(s); s = StringUtils.toUpperEnglish(s);
} }
return ParserUtil.isKeyword(s, false); return ParserUtil.isKeyword(s);
} }
private static int getSaveTokenType(String s, boolean supportOffsetFetch, boolean functionsAsKeywords) { private static int getSaveTokenType(String s, boolean functionsAsKeywords) {
return ParserUtil.getSaveTokenType(s, supportOffsetFetch, functionsAsKeywords); return ParserUtil.getSaveTokenType(s, functionsAsKeywords);
} }
private Column parseColumnForTable(String columnName, private Column parseColumnForTable(String columnName,
......
...@@ -99,13 +99,6 @@ public class Mode { ...@@ -99,13 +99,6 @@ public class Mode {
*/ */
public boolean squareBracketQuotedNames; public boolean squareBracketQuotedNames;
/**
* Support for the syntax
* [OFFSET .. ROW|ROWS] [FETCH FIRST .. ROW|ROWS ONLY]
* as an alternative for LIMIT .. OFFSET.
*/
public boolean supportOffsetFetch = Constants.VERSION_MINOR >= 4;
/** /**
* The system columns 'CTID' and 'OID' are supported. * The system columns 'CTID' and 'OID' are supported.
*/ */
...@@ -216,7 +209,6 @@ public class Mode { ...@@ -216,7 +209,6 @@ public class Mode {
mode = new Mode(ModeEnum.DB2.name()); mode = new Mode(ModeEnum.DB2.name());
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.supportOffsetFetch = true;
mode.sysDummy1 = true; mode.sysDummy1 = true;
mode.isolationLevelInSelectOrInsertStatement = true; mode.isolationLevelInSelectOrInsertStatement = true;
// See // See
...@@ -232,7 +224,6 @@ public class Mode { ...@@ -232,7 +224,6 @@ public class Mode {
mode = new Mode(ModeEnum.Derby.name()); mode = new Mode(ModeEnum.Derby.name());
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.uniqueIndexNullsHandling = UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES; mode.uniqueIndexNullsHandling = UniqueIndexNullsHandling.FORBID_ANY_DUPLICATES;
mode.supportOffsetFetch = true;
mode.sysDummy1 = true; mode.sysDummy1 = true;
mode.isolationLevelInSelectOrInsertStatement = true; mode.isolationLevelInSelectOrInsertStatement = true;
// Derby does not support client info properties as of version 10.12.1.1 // Derby does not support client info properties as of version 10.12.1.1
...@@ -298,7 +289,6 @@ public class Mode { ...@@ -298,7 +289,6 @@ public class Mode {
mode = new Mode(ModeEnum.PostgreSQL.name()); mode = new Mode(ModeEnum.PostgreSQL.name());
mode.aliasColumnName = true; mode.aliasColumnName = true;
mode.nullConcatIsNull = true; mode.nullConcatIsNull = true;
mode.supportOffsetFetch = true;
mode.systemColumns = true; mode.systemColumns = true;
mode.logIsLogBase10 = true; mode.logIsLogBase10 = true;
mode.regexpReplaceBackslashReferences = true; mode.regexpReplaceBackslashReferences = true;
......
...@@ -45,14 +45,13 @@ public class ParserUtil { ...@@ -45,14 +45,13 @@ public class ParserUtil {
* Checks if this string is a SQL keyword. * Checks if this string is a SQL keyword.
* *
* @param s the token to check * @param s the token to check
* @param supportOffsetFetch if OFFSET and FETCH are keywords
* @return true if it is a keyword * @return true if it is a keyword
*/ */
public static boolean isKeyword(String s, boolean supportOffsetFetch) { public static boolean isKeyword(String s) {
if (s == null || s.length() == 0) { if (s == null || s.length() == 0) {
return false; return false;
} }
return getSaveTokenType(s, supportOffsetFetch, false) != IDENTIFIER; return getSaveTokenType(s, false) != IDENTIFIER;
} }
/** /**
...@@ -79,18 +78,17 @@ public class ParserUtil { ...@@ -79,18 +78,17 @@ public class ParserUtil {
return false; return false;
} }
} }
return getSaveTokenType(s, true, functionsAsKeywords) == IDENTIFIER; return getSaveTokenType(s, functionsAsKeywords) == IDENTIFIER;
} }
/** /**
* Get the token type. * Get the token type.
* *
* @param s the token * @param s the token
* @param supportOffsetFetch whether offset / fetch are supported
* @param functionsAsKeywords whether "current data / time" functions are keywords * @param functionsAsKeywords whether "current data / time" functions are keywords
* @return the token type * @return the token type
*/ */
public static int getSaveTokenType(String s, boolean supportOffsetFetch, boolean functionsAsKeywords) { public static int getSaveTokenType(String s, boolean functionsAsKeywords) {
switch (s.charAt(0)) { switch (s.charAt(0)) {
case 'A': case 'A':
return getKeywordOrIdentifier(s, "ALL", KEYWORD); return getKeywordOrIdentifier(s, "ALL", KEYWORD);
...@@ -116,7 +114,9 @@ public class ParserUtil { ...@@ -116,7 +114,9 @@ public class ParserUtil {
} }
return getKeywordOrIdentifier(s, "EXISTS", KEYWORD); return getKeywordOrIdentifier(s, "EXISTS", KEYWORD);
case 'F': case 'F':
if ("FROM".equals(s)) { if ("FETCH".equals(s)) {
return KEYWORD;
} else if ("FROM".equals(s)) {
return KEYWORD; return KEYWORD;
} else if ("FOR".equals(s)) { } else if ("FOR".equals(s)) {
return KEYWORD; return KEYWORD;
...@@ -124,8 +124,6 @@ public class ParserUtil { ...@@ -124,8 +124,6 @@ public class ParserUtil {
return KEYWORD; return KEYWORD;
} else if ("FULL".equals(s)) { } else if ("FULL".equals(s)) {
return KEYWORD; return KEYWORD;
} else if (supportOffsetFetch && "FETCH".equals(s)) {
return KEYWORD;
} }
return getKeywordOrIdentifier(s, "FALSE", FALSE); return getKeywordOrIdentifier(s, "FALSE", FALSE);
case 'G': case 'G':
...@@ -156,9 +154,9 @@ public class ParserUtil { ...@@ -156,9 +154,9 @@ public class ParserUtil {
} }
return getKeywordOrIdentifier(s, "NULL", NULL); return getKeywordOrIdentifier(s, "NULL", NULL);
case 'O': case 'O':
if ("ON".equals(s)) { if ("OFFSET".equals(s)) {
return KEYWORD; return KEYWORD;
} else if (supportOffsetFetch && "OFFSET".equals(s)) { } else if ("ON".equals(s)) {
return KEYWORD; return KEYWORD;
} }
return getKeywordOrIdentifier(s, "ORDER", KEYWORD); return getKeywordOrIdentifier(s, "ORDER", KEYWORD);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论