mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: add sqlServer 2005 LimitOffsetProcessor
This commit is contained in:
parent
a2d356050a
commit
722808b6ed
@ -111,26 +111,7 @@ public interface LimitOffsetProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<QueryTable> queryTables = CPI.getQueryTables(queryWrapper);
|
List<QueryTable> queryTables = CPI.getQueryTables(queryWrapper);
|
||||||
|
String originalSQL = sql.toString();
|
||||||
// String selectColumnString;
|
|
||||||
// List<QueryColumn> selectColumns = CPI.getSelectColumns(queryWrapper);
|
|
||||||
// if (selectColumns == null || selectColumns.isEmpty()){
|
|
||||||
// selectColumnString = "*";
|
|
||||||
// }else {
|
|
||||||
// StringBuilder columnsSql = new StringBuilder();
|
|
||||||
// int index = 0;
|
|
||||||
// for (QueryColumn selectColumn : selectColumns) {
|
|
||||||
// String selectColumnSql = CPI.toSelectSql(selectColumn, queryTables, dialect);
|
|
||||||
// columnsSql.append(selectColumnSql);
|
|
||||||
// if (index != selectColumns.size() - 1) {
|
|
||||||
// columnsSql.append(DELIMITER);
|
|
||||||
// }
|
|
||||||
// index++;
|
|
||||||
// }
|
|
||||||
// selectColumnString = columnsSql.toString();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
String orderByString;
|
String orderByString;
|
||||||
List<QueryOrderBy> orderBys = CPI.getOrderBys(queryWrapper);
|
List<QueryOrderBy> orderBys = CPI.getOrderBys(queryWrapper);
|
||||||
if (orderBys == null || orderBys.isEmpty()) {
|
if (orderBys == null || orderBys.isEmpty()) {
|
||||||
@ -145,11 +126,12 @@ public interface LimitOffsetProcessor {
|
|||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
originalSQL = originalSQL.substring(0, sql.lastIndexOf(ORDER_BY));
|
||||||
orderByString = orderBySql.toString();
|
orderByString = orderBySql.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder newSql = new StringBuilder("WITH temp_datas AS(");
|
StringBuilder newSql = new StringBuilder("WITH temp_datas AS(");
|
||||||
newSql.append("SELECT ROW_NUMBER() OVER (").append(orderByString).append(") as __rn,").append(sql.substring(6));
|
newSql.append("SELECT ROW_NUMBER() OVER (").append(orderByString).append(") as __rn,").append(originalSQL.substring(6));
|
||||||
newSql.append(")");
|
newSql.append(")");
|
||||||
newSql.append(" SELECT * FROM temp_datas WHERE __rn BETWEEN ").append(limitOffset + 1).append(" AND ").append(limitOffset + limitRows);
|
newSql.append(" SELECT * FROM temp_datas WHERE __rn BETWEEN ").append(limitOffset + 1).append(" AND ").append(limitOffset + limitRows);
|
||||||
newSql.append(" ORDER BY __rn");
|
newSql.append(" ORDER BY __rn");
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.mybatisflex.coretest;
|
package com.mybatisflex.coretest;
|
||||||
|
|
||||||
import com.mybatisflex.core.dialect.IDialect;
|
import com.mybatisflex.core.dialect.IDialect;
|
||||||
|
import com.mybatisflex.core.dialect.KeywordWrap;
|
||||||
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
||||||
import com.mybatisflex.core.dialect.impl.CommonsDialectImpl;
|
import com.mybatisflex.core.dialect.impl.CommonsDialectImpl;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
@ -18,9 +19,10 @@ public class SqlServer2005DialectTester {
|
|||||||
.from(ACCOUNT)
|
.from(ACCOUNT)
|
||||||
.where(ACCOUNT.ID.in("100","200"))
|
.where(ACCOUNT.ID.in("100","200"))
|
||||||
.and(ACCOUNT.SEX.eq(1))
|
.and(ACCOUNT.SEX.eq(1))
|
||||||
|
.orderBy(ACCOUNT.ID.desc())
|
||||||
.limit(10,10);
|
.limit(10,10);
|
||||||
|
|
||||||
IDialect dialect = new CommonsDialectImpl(LimitOffsetProcessor.SQLSERVER_2005);
|
IDialect dialect = new CommonsDialectImpl(KeywordWrap.SQUARE_BRACKETS,LimitOffsetProcessor.SQLSERVER_2005);
|
||||||
String sql = dialect.forSelectByQuery(query);
|
String sql = dialect.forSelectByQuery(query);
|
||||||
System.out.println(sql);
|
System.out.println(sql);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user