Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用PaginationHelper.fetchPage方法的三个地方不合理,导致不能使用 ? #12585

Open
bes2008 opened this issue Sep 2, 2024 · 3 comments
Labels
area/Config kind/discussion Category issues related to discussion plugin

Comments

@bes2008
Copy link

bes2008 commented Sep 2, 2024

Describe the bug
PaginationHelper#fetchPage设计问题,导致不能使用 ?

方法PaginationHelper#fetchPage的执行过程是先查询 count (假定为 sql-1), 再查询 指定页面的数据 (假定为sql-2)。
但方法中强制要求 sql-1, sql-2 的参数必须完全一样,就导致在执行sql-2时,无法将 offset, pagesize 以 占位符 ? 形式传入。

Expected behavior
在相关的分页sql中可以使用 占位符 ?

Actually behavior
实际上不能使用。一旦使用,在 执行select count时就会出错。

How to Reproduce
Steps to reproduce the behavior:

  1. 将任意一个数据库的插件(例如mysql)的 HistoryConfigInfoMapper # pageFindConfigHistoryFetchRows 方法中,context.getStartRow(), context.getPageSize() 参数,调整为以 ? 方式生成SQL,去执行就会报错。

例如:

public class HistoryConfigInfoMapperByMySql extends AbstractMapperByMysql implements HistoryConfigInfoMapper {

// 其它方法这里忽略

    @Override
    public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) {
        String sql =
                "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
                        + "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC  LIMIT ?, ?";
                    //    + context.getStartRow() + "," +context.getPageSize( );
        return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.DATA_ID),
                context.getWhereParameter(FieldConstant.GROUP_ID), context.getWhereParameter(FieldConstant.TENANT_ID),  context.getStartRow(), context.getPageSize()));
    }    
}
@bes2008
Copy link
Author

bes2008 commented Sep 2, 2024

paginationhelper fetch

@bes2008
Copy link
Author

bes2008 commented Sep 3, 2024

改为调用 PaginationHelper#fetchPageLimit(String sqlCountRows, Object[] args1, String sqlFetchRows, Object[] args2, int pageNo, int pageSize, RowMapper rowmapper) 可解决这个问题

@bes2008
Copy link
Author

bes2008 commented Sep 3, 2024

从代码来看,有三个地方都是需要调整为PaginationHelper#fetchPageLimit(String sqlCountRows, Object[] args1, String sqlFetchRows, Object[] args2, int pageNo, int pageSize, RowMapper rowmapper)的:

  1. 调用 ConfigInfoBetaMapper#findAllConfigInfoBetaForDumpAllFetchRows 的地方
  2. 调用 ConfigInfoTagMapper#findAllConfigInfoTagForDumpAllFetchRows 的地方
  3. 调用 HistoryConfigInfoMapper#pageFindConfigHistoryFetchRows的地方

@KomachiSion KomachiSion added plugin area/Config kind/discussion Category issues related to discussion labels Sep 3, 2024
@bes2008 bes2008 changed the title PaginationHelper.fetchPage设计问题,导致不能使用 ? 调用PaginationHelper.fetchPage方法的三个地方不合理,导致不能使用 ? Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Config kind/discussion Category issues related to discussion plugin
Projects
None yet
Development

No branches or pull requests

2 participants