Skip to content

Commit 1aee4f3

Browse files
committed
for #701: fix bug for limit parse parameters index incorrect
1 parent 6602ade commit 1aee4f3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

sharding-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/MySQLLimitClauseParser.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public void parse(final SelectStatement selectStatement) {
7474
selectStatement.setLimit(getLimitWithOffset(valueIndex, valueBeginPosition, value, isParameterForValue, selectStatement));
7575
return;
7676
}
77-
if (!isParameterForValue) {
77+
if (isParameterForValue) {
78+
selectStatement.increaseParametersIndex();
79+
} else {
7880
selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, value));
7981
}
8082
Limit limit = new Limit(DatabaseType.MySQL);
@@ -99,10 +101,14 @@ private Limit getLimitWithComma(final int index, final int valueBeginPosition, f
99101
throw new SQLParsingException(lexerEngine);
100102
}
101103
lexerEngine.nextToken();
102-
if (!isParameterForValue) {
104+
if (isParameterForValue) {
105+
selectStatement.increaseParametersIndex();
106+
} else {
103107
selectStatement.getSqlTokens().add(new OffsetToken(valueBeginPosition, value));
104108
}
105-
if (!isParameterForRowCount) {
109+
if (isParameterForRowCount) {
110+
selectStatement.increaseParametersIndex();
111+
} else {
106112
selectStatement.getSqlTokens().add(new RowCountToken(rowCountBeginPosition, rowCountValue));
107113
}
108114
Limit result = new Limit(DatabaseType.MySQL);
@@ -127,10 +133,14 @@ private Limit getLimitWithOffset(final int index, final int valueBeginPosition,
127133
throw new SQLParsingException(lexerEngine);
128134
}
129135
lexerEngine.nextToken();
130-
if (!isParameterForOffset) {
136+
if (isParameterForOffset) {
137+
selectStatement.increaseParametersIndex();
138+
} else {
131139
selectStatement.getSqlTokens().add(new OffsetToken(offsetBeginPosition, offsetValue));
132140
}
133-
if (!isParameterForValue) {
141+
if (isParameterForValue) {
142+
selectStatement.increaseParametersIndex();
143+
} else {
134144
selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, value));
135145
}
136146
Limit result = new Limit(DatabaseType.MySQL);

sharding-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dql/select/SelectStatement.java

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public SelectStatement mergeSubQueryStatement() {
177177
SelectStatement result = processLimitForSubQuery();
178178
processItems(result);
179179
processOrderByItems(result);
180+
result.setParametersIndex(getParametersIndex());
180181
return result;
181182
}
182183

0 commit comments

Comments
 (0)