Skip to content

Commit 2702ad9

Browse files
committed
修复解析器for update错误.
baomidou#2229 baomidou#2364
1 parent 723514f commit 2702ad9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/TableNameParser.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ public TableNameParser(final String sql) {
8989
if (isFromToken(currentToken)) {
9090
processFromToken(tokens, index);
9191
} else if (shouldProcess(currentToken)) {
92-
String nextToken = tokens[index++];
93-
considerInclusion(nextToken);
94-
9592
if (moreTokens(tokens, index)) {
96-
nextToken = tokens[index++];
93+
String nextToken = tokens[index++];
94+
considerInclusion(nextToken);
9795
}
9896
}
9997
}

mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/toolkit/TableNameParserTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ public void testSqlWithMultipleCommentsInTheMiddleAndEnd() {
476476
String sql = "select * -- I like stars \n from foo f -- I like foo \n join bar b -- I also like bar \n on f.id = b.id -- comment ending with update";
477477
assertThat(new TableNameParser(sql).tables()).isEqualTo(asSet("foo","bar"));
478478
}
479+
480+
@Test
481+
void testSelectForUpdate() {
482+
//TODO 暂时解决不能使用的问题,当碰到for update nowait这样的,后面的nowait会被当做成表但也不是很影响苗老板的动态表过滤.
483+
assertThat(new TableNameParser("select * from mp where id = 1 for update").tables()).isEqualTo(asSet("mp"));
484+
}
479485

480486
private static Collection<String> asSet(String... a) {
481487
Set<String> result = new HashSet<String>();

0 commit comments

Comments
 (0)