mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: add LimitOffsetProcessor.SQLSERVER
This commit is contained in:
parent
200e61d2f7
commit
c21bccc5aa
@ -131,7 +131,7 @@ public class DialectFactory {
|
||||
case DB2:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.DERBY);
|
||||
case SQLSERVER:
|
||||
return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.DERBY);
|
||||
return new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS, LimitOffsetProcessor.SQLSERVER);
|
||||
case INFORMIX:
|
||||
return new CommonsDialectImpl(KeywordWrap.DOUBLE_QUOTATION, LimitOffsetProcessor.INFORMIX);
|
||||
case SYBASE:
|
||||
|
||||
@ -15,7 +15,12 @@
|
||||
*/
|
||||
package com.mybatisflex.core.dialect;
|
||||
|
||||
import com.mybatisflex.core.query.CPI;
|
||||
import com.mybatisflex.core.query.QueryOrderBy;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.util.CollectionUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* limit 和 offset 参数的处理器
|
||||
@ -57,13 +62,32 @@ public interface LimitOffsetProcessor {
|
||||
LimitOffsetProcessor DERBY = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
// OFFSET ** ROWS FETCH NEXT ** ROWS ONLY")
|
||||
sql.append(" OFFSET ").append(limitOffset).append(" ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
sql.append(" OFFSET ").append(limitOffset).append(" ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
} else if (limitRows != null) {
|
||||
sql.append(" OFFSET 0 ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
}
|
||||
return sql;
|
||||
};
|
||||
|
||||
/**
|
||||
* derby 的处理器
|
||||
* 适合 {@link DbType#DERBY,DbType#ORACLE_12C,DbType#SQLSERVER ,DbType#POSTGRE_SQL}
|
||||
*/
|
||||
LimitOffsetProcessor SQLSERVER = (sql, queryWrapper, limitRows, limitOffset) -> {
|
||||
if (limitRows != null && limitOffset != null) {
|
||||
// OFFSET ** ROWS FETCH NEXT ** ROWS ONLY")
|
||||
sql.append(" OFFSET ").append(limitOffset).append(" ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
} else if (limitRows != null) {
|
||||
List<QueryOrderBy> orderBys = CPI.getOrderBys(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(orderBys)) {
|
||||
sql.append(" OFFSET 0 ROWS FETCH NEXT ").append(limitRows).append(" ROWS ONLY");
|
||||
} else {
|
||||
sql.insert(6, " TOP " + limitRows);
|
||||
}
|
||||
}
|
||||
return sql;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Informix 的处理器
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user