修复动态表名处理 update ignore 错误.

https://github.com/baomidou/mybatis-plus/issues/6050
This commit is contained in:
nieqiurong 2024-04-11 14:06:23 +08:00
parent 3cf9540f5d
commit df8a130101
2 changed files with 23 additions and 0 deletions

View File

@ -41,7 +41,9 @@ public final class TableNameParser {
private static final String TOKEN_SET = "set";
private static final String TOKEN_OF = "of";
private static final String TOKEN_DUAL = "dual";
private static final String IGNORE = "ignore";
private static final String TOKEN_DELETE = "delete";
private static final String TOKEN_UPDATE = "update";
private static final String TOKEN_CREATE = "create";
private static final String TOKEN_INDEX = "index";
@ -107,6 +109,10 @@ public final class TableNameParser {
} else if (concerned.contains(current.toLowerCase())) {
if (hasMoreTokens(tokens, index)) {
SqlToken next = tokens.get(index++);
if (TOKEN_UPDATE.equalsIgnoreCase(current)
&& IGNORE.equalsIgnoreCase(next.getValue())) {
next = tokens.get(index++);
}
visitNameToken(next, visitor);
}
}

View File

@ -492,6 +492,23 @@ public class TableNameParserTest {
assertThat(new TableNameParser(sql).tables()).isEqualTo(asSet("cf_procedure"));
}
@Test
public void testUpdateIgnore() {
String sql = "update ignore student set name = 'abc' where id = 4";
assertThat(new TableNameParser(sql).tables()).isEqualTo(asSet("student"));
sql = "UPDATE IGNORE student set name = 'abc' where id = 4";
assertThat(new TableNameParser(sql).tables()).isEqualTo(asSet("student"));
}
@Test
public void testInsertIgnore() {
String sql = "INSERT IGNORE INTO student (userid,username) VALUES (2,'swan'),(4,'bear') ;";
assertThat(new TableNameParser(sql).tables()).isEqualTo(asSet("student"));
}
private static Collection<String> asSet(String... a) {
Set<String> result = new HashSet<>();
Collections.addAll(result, a);