From afdc794ff657996becab4183d29a77b94b5edeea Mon Sep 17 00:00:00 2001 From: gyl <1554863190@qq.com> Date: Tue, 14 May 2024 09:53:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=88=97=E5=85=A8=E5=90=8D=E8=A7=A3=E6=9E=90=E8=A1=A8?= =?UTF-8?q?=E5=88=AB=E5=90=8D=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../term/AbstractTermFragmentBuilder.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java index fdc66adf..bfb8df8d 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java @@ -5,6 +5,7 @@ import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.metadata.RDBColumnMetadata; import org.hswebframework.ezorm.rdb.metadata.TableOrViewMetadata; +import org.hswebframework.ezorm.rdb.metadata.dialect.Dialect; import org.hswebframework.ezorm.rdb.operator.builder.fragments.NativeSql; import org.hswebframework.ezorm.rdb.operator.builder.fragments.PrepareSqlFragments; import org.hswebframework.ezorm.rdb.operator.builder.fragments.TermFragmentBuilder; @@ -115,4 +116,35 @@ protected PrepareSqlFragments appendPrepareOrNative(PrepareSqlFragments sql, Obj } return sql; } + + + /** + * 根据字段全名获取表别名 + * + * @param columnFullName 列全名 + * @param dialect 数据库方言 + * @return 表别名 + */ + protected static Optional parseTablePlainName(String columnFullName, Dialect dialect) { + if (columnFullName.contains(".")) { + String[] split = parsePlainName(columnFullName, dialect).split("\\."); + return Optional.of(split[0]); + } + return Optional.empty(); + } + + protected static String parsePlainName(String name, Dialect dialect) { + if (name == null || name.isEmpty()) { + return null; + } + char firstChar = name.charAt(0); + + if (firstChar == '`' || firstChar == '"' || firstChar == '[' || + name.startsWith(dialect.getQuoteStart())) { + + return new String(name.toCharArray(), 1, name.length() - 2); + } + + return name; + } } From f32071d815c77a300cdc48e0a8fdafcc7468b8af Mon Sep 17 00:00:00 2001 From: gyl <1554863190@qq.com> Date: Wed, 15 May 2024 15:51:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=BA=AF=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=88=AA=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fragments/term/AbstractTermFragmentBuilder.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java index bfb8df8d..95338fa2 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java @@ -137,12 +137,11 @@ protected static String parsePlainName(String name, Dialect dialect) { if (name == null || name.isEmpty()) { return null; } - char firstChar = name.charAt(0); - if (firstChar == '`' || firstChar == '"' || firstChar == '[' || - name.startsWith(dialect.getQuoteStart())) { - - return new String(name.toCharArray(), 1, name.length() - 2); + if (name.startsWith(dialect.getQuoteStart())) { + return name + .replace(dialect.getQuoteStart(), "") + .replace(dialect.getQuoteEnd(), ""); } return name; From a307b11f8eea42c0e9834e7690056c75bd388630 Mon Sep 17 00:00:00 2001 From: gyl <1554863190@qq.com> Date: Thu, 16 May 2024 10:12:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/fragments/term/AbstractTermFragmentBuilder.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java index 95338fa2..5e6d6672 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java @@ -137,13 +137,9 @@ protected static String parsePlainName(String name, Dialect dialect) { if (name == null || name.isEmpty()) { return null; } - if (name.startsWith(dialect.getQuoteStart())) { - return name - .replace(dialect.getQuoteStart(), "") - .replace(dialect.getQuoteEnd(), ""); + return name.substring(dialect.getQuoteStart().length(), name.length() - dialect.getQuoteEnd().length()); } - return name; } }