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

When use mybatis recent version how to use executeQuery() #2891

Closed
yunzhongshu opened this issue Aug 19, 2019 · 6 comments
Closed

When use mybatis recent version how to use executeQuery() #2891

yunzhongshu opened this issue Aug 19, 2019 · 6 comments
Assignees

Comments

@yunzhongshu
Copy link

yunzhongshu commented Aug 19, 2019

Question

When using mybatis3.4.x for query. It will invoke PreparedStatementHandler.query, it's code is :

  public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
    PreparedStatement ps = (PreparedStatement) statement;
    ps.execute();
    return resultSetHandler.<E> handleResultSets(ps);
  }

It will invoke the PreparedStatement.execute() not the PreparedStatement.executeQuery(), so it can't invoke the ShardingPrepareStatement.executeQuery() too.
So How Can i invoke的executeQuery() when use Mybatis?

Thanks a lot!

@terrymanu
Copy link
Member

ShardingSphere is faced on JDBC layer, it doesn't care about ORM.
Do you find some error during your program?
Can you provide error message?

@terrymanu terrymanu self-assigned this Aug 19, 2019
@yunzhongshu
Copy link
Author

No error, execute() don't merge the result, but it processLimit before (When limit=10, offset=100, it will set the limit=0, offset=110), last the execute() will return the page result of 0 to 110, not 10 offset 100.

@terrymanu
Copy link
Member

There is no relationship with mybatis and its version.
Can you try example first and make example is correct, and compare what is the diff with your code?

@yunzhongshu
Copy link
Author

Yes, I have tried.
When I use sql : ... limit #{offset},#{limit}, it will replace the rowCount and offset, the code in the Limit.java:

    private void rewrite(final List<Object> parameters, final boolean isFetchAll, final DatabaseType databaseType) {
        int rewriteOffset = 0;
        int rewriteRowCount;
        if (isFetchAll) {
            rewriteRowCount = Integer.MAX_VALUE;
        } else if (isNeedRewriteRowCount(databaseType)) {
            rewriteRowCount = null == rowCount ? -1 : getOffsetValue() + rowCount.getValue();
        } else {
            rewriteRowCount = rowCount.getValue();
        }
        if (null != offset && offset.getIndex() > -1) {
            parameters.set(offset.getIndex(), rewriteOffset);
        }
        if (null != rowCount && rowCount.getIndex() > -1) {
            parameters.set(rowCount.getIndex(), rewriteRowCount);
        }
    }

@yunzhongshu
Copy link
Author

supplement: sharding version is 3.1.0

@terrymanu terrymanu removed their assignment Aug 19, 2019
@tuohai666
Copy link
Member

Duplicate with #2062 #1759 #1722 #1672 #1643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants