Skip to content

Commit

Permalink
* 对offset fetch next增强,以兼容sqlserver2012
Browse files Browse the repository at this point in the history
  • Loading branch information
fjn committed Dec 2, 2020
1 parent dcd8cd5 commit 5bc71b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public boolean isBindLimitParametersFirst() {
public static class SQLServer2000Dialect extends AbstractTransactSQLDialect {
public SQLServer2000Dialect() {
setLimitHandler(new TopLimitHandler());
setDelegate(null);
}

@Override
Expand Down Expand Up @@ -140,6 +141,7 @@ public boolean isBindLimitParametersFirst() {
public static class SQLServer2005Dialect extends AbstractTransactSQLDialect {
public SQLServer2005Dialect() {
setLimitHandler(new SQLServer2005LimitHandler());
setDelegate(null);
}

@Override
Expand Down Expand Up @@ -175,45 +177,20 @@ public char getAfterQuote() {

@Name("sqlserver2008")
public static class SQLServer2008Dialect extends SQLServer2005Dialect {
public SQLServer2008Dialect() {
setLimitHandler(new OffsetFetchFirstOnlyLimitHandler());
}

@Override
public boolean isSupportsLimit() {
return true;
}

@Override
public boolean isUseMaxForLimit() {
return true;
}

@Override
public boolean isSupportsLimitOffset() {
return true;
}

@Override
public boolean isSupportsVariableLimit() {
return true;
}
}

@Override
public char getBeforeQuote() {
return '[';
@Name("sqlserver2012")
public static class SQLServer2012Dialect extends SQLServer2008Dialect {
public SQLServer2012Dialect() {
setLimitHandler(new OffsetFetchFirstOnlyLimitHandler().setSupportSimplifyFirstOnly(false));
}

@Override
public char getAfterQuote() {
return ']';
public boolean isBindLimitParametersInReverseOrder() {
return false;
}
}

@Name("sqlserver2012")
public static class SQLServer2012Dialect extends SQLServer2008Dialect {
}

@Name("sqlserver2014")
public static class SQLServer2014Dialect extends SQLServer2012Dialect {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ protected String getLimitString(String sql, long offset, int limit) {
sql2.append(sql);

if (getDialect().isUseLimitInVariableMode()) {
if (hasOffset) {
if (hasOffset || !supportSimplifyFirstOnly) {
sql2.append(" OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
} else {
sql2.append(" FETCH FIRST ? ROWS ONLY");
}
} else {
if (hasOffset) {
if (hasOffset || !supportSimplifyFirstOnly) {
sql2.append(" OFFSET " + offset + " ROWS FETCH NEXT " + limit + " ROWS ONLY");
} else {
sql2.append(" FETCH FIRST " + limit + " ROWS ONLY");
Expand All @@ -107,7 +107,7 @@ protected String getLimitString(String sql, long offset, int limit) {
private boolean isSupportUsingIndexClauseInSelectEnd = false;
private boolean supportForUpdate = true;
private boolean supportWithInSelectEnd = true;

private boolean supportSimplifyFirstOnly = true;
public boolean isSupportUsingIndexClauseInSelectEnd() {
return isSupportUsingIndexClauseInSelectEnd;
}
Expand All @@ -134,4 +134,13 @@ public OffsetFetchFirstOnlyLimitHandler setSupportWithInSelectEnd(boolean suppor
this.supportWithInSelectEnd = supportWithInSelectEnd;
return this;
}

public boolean isSupportSimplifyFirstOnly() {
return supportSimplifyFirstOnly;
}

public OffsetFetchFirstOnlyLimitHandler setSupportSimplifyFirstOnly(boolean supportSimplifyFirstOnly) {
this.supportSimplifyFirstOnly = supportSimplifyFirstOnly;
return this;
}
}

0 comments on commit 5bc71b7

Please sign in to comment.