瀏覽代碼

feat: 支持获取表不存在则创建语句的表名称

支持获取`create table if not exists table_name`语句的表名称
Serenity 2 月之前
父節點
當前提交
3c7ee002b8

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

@@ -99,6 +99,8 @@ public final class TableNameParser {
             visitNameToken(tokens.get(index + 1), visitor);
         } else if (isCreateIndex(first, tokens, index)) {
             visitNameToken(tokens.get(index + 4), visitor);
+        } else if (isCreateTableIfNotExist(first, tokens, index)) {
+            visitNameToken(tokens.get(index + 5), visitor);
         } else {
             while (hasMoreTokens(tokens, index)) {
                 String current = tokens.get(index++).getValue();
@@ -179,6 +181,18 @@ public final class TableNameParser {
         }
         return false;
     }
+    
+    private boolean isCreateTableIfNotExist(String current, List<SqlToken> tokens, int index) {
+        index++; // Point to next token
+        if (TOKEN_CREATE.equalsIgnoreCase(current) && hasIthToken(tokens, index)) {
+            String tableIfNotExist = tokens.get(index).getValue();
+            tableIfNotExist += tokens.get(++index).getValue();
+            tableIfNotExist += tokens.get(++index).getValue();
+            tableIfNotExist += tokens.get(++index).getValue();
+            return "tableifnotexists".equalsIgnoreCase(tableIfNotExist);
+        }
+        return false;
+    }
 
     /**
      * @param current 当前token