Browse Source

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

https://github.com/baomidou/mybatis-plus/issues/6050
nieqiurong 1 year ago
parent
commit
df8a130101

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

@@ -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);
                     }
                 }

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

@@ -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);