mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sql wall. for issue #2411
This commit is contained in:
@@ -93,15 +93,17 @@ public class PagerUtils {
|
||||
return limitSQLServer(select, dbType, offset, count, check);
|
||||
}
|
||||
|
||||
if (query instanceof SQLSelectQueryBlock) {
|
||||
return limitQueryBlock(select, dbType, offset, count, check);
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
return limitQueryBlock(select, dbType, offset, count, check);
|
||||
}
|
||||
|
||||
private static boolean limitQueryBlock(SQLSelect select, String dbType, int offset, int count, boolean check) {
|
||||
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) select.getQuery();
|
||||
SQLSelectQuery query = select.getQuery();
|
||||
if (query instanceof SQLUnionQuery) {
|
||||
SQLUnionQuery union = (SQLUnionQuery) query;
|
||||
return limitUnion(union, dbType, offset, count, check);
|
||||
}
|
||||
|
||||
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
|
||||
if (JdbcConstants.MYSQL.equals(dbType) || //
|
||||
JdbcConstants.MARIADB.equals(dbType) || //
|
||||
JdbcConstants.H2.equals(dbType)) {
|
||||
@@ -400,6 +402,37 @@ public class PagerUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean limitUnion(SQLUnionQuery queryBlock, String dbType, int offset, int count, boolean check) {
|
||||
SQLLimit limit = queryBlock.getLimit();
|
||||
if (limit != null) {
|
||||
if (offset > 0) {
|
||||
limit.setOffset(new SQLIntegerExpr(offset));
|
||||
}
|
||||
|
||||
if (check && limit.getRowCount() instanceof SQLNumericLiteralExpr) {
|
||||
int rowCount = ((SQLNumericLiteralExpr) limit.getRowCount()).getNumber().intValue();
|
||||
if (rowCount <= count && offset <= 0) {
|
||||
return false;
|
||||
}
|
||||
} else if (check && limit.getRowCount() instanceof SQLVariantRefExpr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
limit.setRowCount(new SQLIntegerExpr(count));
|
||||
}
|
||||
|
||||
if (limit == null) {
|
||||
limit = new SQLLimit();
|
||||
if (offset > 0) {
|
||||
limit.setOffset(new SQLIntegerExpr(offset));
|
||||
}
|
||||
limit.setRowCount(new SQLIntegerExpr(count));
|
||||
queryBlock.setLimit(limit);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String count(SQLSelect select, String dbType) {
|
||||
if (select.getOrderBy() != null) {
|
||||
select.setOrderBy(null);
|
||||
|
||||
Reference in New Issue
Block a user