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

problem in SQLServerStatementSQLVisitor.class #32354

Open
JINWANDALAOHU250 opened this issue Aug 1, 2024 · 3 comments
Open

problem in SQLServerStatementSQLVisitor.class #32354

JINWANDALAOHU250 opened this issue Aug 1, 2024 · 3 comments

Comments

@JINWANDALAOHU250
Copy link

Bug Report

Which version of ShardingSphere did you use?

 <dependency>
  <groupId>org.apache.shardingsphere</groupId>
  <artifactId>shardingsphere-jdbc-core</artifactId>
  <version>5.3.2</version>
</dependency>

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

execute sql like

SELECT
	* 
FROM
	message_mst 
WHERE
	readed = 0 
ORDER BY
	msg.create_dt DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY

then parse to

Actual SQL: slave :::
SELECT
	* 
FROM
	message_mst 
WHERE
	readed = 0 
ORDER BY
	msg.create_dt DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY

::: [10, 5]

Actual behavior

### Cause: java.sql.SQLException: Unknown exception: Index: 2, Size: 2
; uncategorized SQLException for SQL []; SQL state [HY000]; error code [30000]; Unknown exception: Index: 2, Size: 2; nested exception is java.sql.SQLException: Unknown exception: Index: 2, Size: 2

Reason analyze (If you can)

In class SQLServerStatementSQLVisitor.class#visitOrderBy ,offset paramIndex and rowcount paramIndex not right, caused PaginationContext get param in List params out of bounds.

// SQLServerStatementSQLVisitor
... line 788
                // param index is 'parameterMarkerSegments.size() - 1'
                offset = new ParameterMarkerLimitValueSegment(ctx.expr(0).start.getStartIndex(), ctx.expr(0).stop.getStopIndex(), parameterMarkerSegments.size());
...
...
                // param index is 'parameterMarkerSegments.size() - 1'
                rowcount = new ParameterMarkerLimitValueSegment(ctx.expr(1).start.getStartIndex(), ctx.expr(1).stop.getStopIndex(), parameterMarkerSegments.size());
...

// PaginationContext
...line 56
// getParameterIndex() caused Unknown exception: Index: 2, Size: 2
Object obj = null == params || params.isEmpty() ? 0L : params.get(((ParameterMarkerPaginationValueSegment) paginationValueSegment).getParameterIndex());
...

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

SpringBoot + Mybatis + Similar to the sql mentioned above

Example codes for reproduce this issue (such as a github link).

@terrymanu
Copy link
Member

No plan to enhance with SQLServer for now, does any one want to do it?

@JINWANDALAOHU250
Copy link
Author

JINWANDALAOHU250 commented Aug 2, 2024

Is it that I want to be simple, I think it should only take parameterMarkerSegments.size() - 1 to solve this problem

@terrymanu
Copy link
Member

I cannot suggest without investigate.
Please try.

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

2 participants