From f0399ceee5664097bf1c61c51d97f83e07c79309 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 13 Jul 2023 18:00:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feature:=20=E5=A2=9E=E5=8A=A0=20ignore=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21ceffc --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +*.class +*.log +*.ctxt +.mtj.tmp/ +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar +hs_err_pid* +replay_pid* +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.project +.classpath +.idea/**/* +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +.idea/sonarlint/ +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser -- Gitee From 6b50f6082f58acb4410f92a824bc4adc43829a5a Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 13 Jul 2023 19:02:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feature:=20=E5=A2=9E=E5=8A=A0=20Junit5=20?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 46451b2..0c0fcb5 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ 1.7.26 3.5.1 2.5.10 + 5.9.3 @@ -38,6 +39,13 @@ ${mybatis-plus.version} provided + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + @@ -78,9 +86,6 @@ org.apache.maven.plugins maven-surefire-plugin 2.12.4 - - true - org.apache.maven.plugins -- Gitee From cd4f32365bda389942f6a56f807c818691cdc8c7 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 13 Jul 2023 19:08:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dstrict=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E5=AD=97=E6=AE=B5=E5=90=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?as=E6=97=B6=E5=AD=97=E6=AE=B5=E8=AF=86=E5=88=AB=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kingon/sql/builder/util/SqlNameUtils.java | 6 ++-- .../sql/builder/util/SqlNameUtilsTest.java | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java diff --git a/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java b/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java index f04e7f6..29d8cde 100644 --- a/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java +++ b/src/main/java/club/kingon/sql/builder/util/SqlNameUtils.java @@ -25,7 +25,7 @@ public class SqlNameUtils { public static String handleName(String name) { if (GlobalConfig.OPEN_STRICT_MODE && name != null) { - return Arrays.stream(name.split("\\.")).map(SqlNameUtils::handleStrictName).collect(Collectors.joining(".")); + return Arrays.stream(name.split("\\.")).map(String::trim).map(SqlNameUtils::handleStrictName).collect(Collectors.joining(".")); } return name; } @@ -34,8 +34,8 @@ public class SqlNameUtils { if (!"*".equals(name) && !name.contains("(")) { if (name.contains(",")) { return Arrays.stream(name.split(",")).map(String::trim).map(SqlNameUtils::handleName).collect(Collectors.joining(", ")); - } else if (name.contains("as")) { - String[] columnAndAlias = name.split("as"); + } else if (name.matches(".*\\s+as\\s+.*")) { + String[] columnAndAlias = name.split("\\s+as\\s+"); return handleName(columnAndAlias[0].trim()) + " as " + handleName(columnAndAlias[1].trim()); } else if (name.startsWith("`") || name.contains("->")) { return name; diff --git a/src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java b/src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java new file mode 100644 index 0000000..1dc2e6a --- /dev/null +++ b/src/test/java/club/kingon/sql/builder/util/SqlNameUtilsTest.java @@ -0,0 +1,35 @@ +package club.kingon.sql.builder.util; + +import club.kingon.sql.builder.config.GlobalConfig; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class SqlNameUtilsTest { + @BeforeEach + void setUp() { + GlobalConfig.OPEN_STRICT_MODE = true; + } + + @Test + void testHandleName() { + assertEquals("*", SqlNameUtils.handleName("*")); + assertEquals("*", SqlNameUtils.handleName(" * ")); + assertEquals("`table`.*", SqlNameUtils.handleName("table.*")); + assertEquals("`table`.*", SqlNameUtils.handleName("`table`.*")); + assertEquals("`table`.*", SqlNameUtils.handleName(" table.* ")); + assertEquals("`table`.`field`", SqlNameUtils.handleName("table.field")); + assertEquals("`table`.`field`", SqlNameUtils.handleName("`table`.`field`")); + assertEquals("`table`.`field`", SqlNameUtils.handleName(" table.field ")); + assertEquals("`table` as `table1`", SqlNameUtils.handleName("table as table1")); + assertEquals("`table` as `table1`", SqlNameUtils.handleName("`table` as `table1`")); + assertEquals("`table` as `table1`", SqlNameUtils.handleName(" table as table1 ")); + assertEquals("`task_table` as `task`", SqlNameUtils.handleName("task_table as task")); + assertEquals("`task`", SqlNameUtils.handleName("task")); + assertEquals("`task`", SqlNameUtils.handleName("`task`")); + assertEquals("`task`", SqlNameUtils.handleName(" task ")); + assertEquals("`as`", SqlNameUtils.handleName("as")); + assertEquals("`as`", SqlNameUtils.handleName(" as ")); + } +} \ No newline at end of file -- Gitee