From c821c8361f4085d370c11b33f61255df4991a930 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 8 Sep 2025 15:19:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=80=90=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E3=80=91=E7=BC=96=E8=BE=91sql=E5=A4=96=E9=83=A8=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E7=A7=B0=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=B9=9F?= =?UTF-8?q?=E5=8F=AF=E6=88=90=E5=8A=9F=E8=AE=BE=E7=BD=AE=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/utils/DeSqlparserUtils.java | 83 ++++++++++--------- .../main/resources/i18n/core_en_US.properties | 1 + .../main/resources/i18n/core_zh_CN.properties | 1 + .../main/resources/i18n/core_zh_TW.properties | 1 + 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/commons/utils/DeSqlparserUtils.java b/core/core-backend/src/main/java/io/dataease/commons/utils/DeSqlparserUtils.java index ee91b8bf65..f0c7f68797 100644 --- a/core/core-backend/src/main/java/io/dataease/commons/utils/DeSqlparserUtils.java +++ b/core/core-backend/src/main/java/io/dataease/commons/utils/DeSqlparserUtils.java @@ -42,10 +42,10 @@ public class DeSqlparserUtils { private List defaultsSqlVariableDetails = new ArrayList<>(); public String handleVariableDefaultValue(String sql, String sqlVariableDetails, boolean isEdit, boolean isFromDataSet, List parameters, boolean isCross, Map dsMap, PluginManageApi pluginManage, UserFormVO userEntity) { - DatasourceSchemaDTO ds = dsMap.entrySet().iterator().next().getValue(); - if (StringUtils.isEmpty(sql)) { - DEException.throwException(Translator.get("i18n_sql_not_empty")); - } +// DatasourceSchemaDTO ds = dsMap.entrySet().iterator().next().getValue(); +// if (StringUtils.isEmpty(sql)) { +// DEException.throwException(Translator.get("i18n_sql_not_empty")); +// } this.userEntity = userEntity; sql = sql.trim(); if (sql.endsWith(";")) { @@ -64,6 +64,9 @@ public class DeSqlparserUtils { Matcher m = p.matcher(sqlItemWithParam); while (m.find()) { String sqlVariable = m.group(); + if(sqlVariable.substring(2, sqlVariable.length() - 1).trim().isEmpty()){ + DEException.throwException(Translator.get("i18n_sql_variable_name_empty")); + } boolean replaceParamItem = false; SqlVariableDetails defaultsSqlVariableDetail = null; for (SqlVariableDetails sqlVariableDetail : defaultsSqlVariableDetails) { @@ -141,42 +144,42 @@ public class DeSqlparserUtils { } } - try { - if (!isCross) { - Map.Entry next = dsMap.entrySet().iterator().next(); - DatasourceSchemaDTO value = next.getValue(); - - String prefix = ""; - String suffix = ""; - if (Arrays.stream(DatasourceConfiguration.DatasourceType.values()).map(DatasourceConfiguration.DatasourceType::getType).toList().contains(value.getType())) { - DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(value.getType()); - prefix = datasourceType.getPrefix(); - suffix = datasourceType.getSuffix(); - } else { - if (LicenseUtil.licenseValid()) { - List xpackPluginsDatasourceVOS = pluginManage.queryPluginDs(); - List list = xpackPluginsDatasourceVOS.stream().filter(ele -> StringUtils.equals(ele.getType(), value.getType())).toList(); - if (ObjectUtils.isNotEmpty(list)) { - XpackPluginsDatasourceVO first = list.getFirst(); - prefix = first.getPrefix(); - suffix = first.getSuffix(); - } else { - DEException.throwException("当前数据源插件不存在"); - } - } - } - - Pattern patternCross = Pattern.compile("(`.*?`)"); - Matcher matcherCross = patternCross.matcher(sql); - while (matcherCross.find()) { - String group = matcherCross.group(); - String info = group.substring(1, group.length() - 1); - sql = sql.replaceAll(group, prefix + info + suffix); - } - } - } catch (Exception e) { - e.printStackTrace(); - } +// try { +// if (!isCross) { +// Map.Entry next = dsMap.entrySet().iterator().next(); +// DatasourceSchemaDTO value = next.getValue(); +// +// String prefix = ""; +// String suffix = ""; +// if (Arrays.stream(DatasourceConfiguration.DatasourceType.values()).map(DatasourceConfiguration.DatasourceType::getType).toList().contains(value.getType())) { +// DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(value.getType()); +// prefix = datasourceType.getPrefix(); +// suffix = datasourceType.getSuffix(); +// } else { +// if (LicenseUtil.licenseValid()) { +// List xpackPluginsDatasourceVOS = pluginManage.queryPluginDs(); +// List list = xpackPluginsDatasourceVOS.stream().filter(ele -> StringUtils.equals(ele.getType(), value.getType())).toList(); +// if (ObjectUtils.isNotEmpty(list)) { +// XpackPluginsDatasourceVO first = list.getFirst(); +// prefix = first.getPrefix(); +// suffix = first.getSuffix(); +// } else { +// DEException.throwException("当前数据源插件不存在"); +// } +// } +// } +// +// Pattern patternCross = Pattern.compile("(`.*?`)"); +// Matcher matcherCross = patternCross.matcher(sql); +// while (matcherCross.find()) { +// String group = matcherCross.group(); +// String info = group.substring(1, group.length() - 1); +// sql = sql.replaceAll(group, prefix + info + suffix); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } return sql; } diff --git a/core/core-backend/src/main/resources/i18n/core_en_US.properties b/core/core-backend/src/main/resources/i18n/core_en_US.properties index 7b4fbe07d4..33f9c064fc 100644 --- a/core/core-backend/src/main/resources/i18n/core_en_US.properties +++ b/core/core-backend/src/main/resources/i18n/core_en_US.properties @@ -211,3 +211,4 @@ i18n_invalid_address=Invalid address! i18n_unsupported_protocol=Unsupported protocol! i18n_excel_error_first_row=Empty cells are not allowed in the middle of the first row! i18n_app_error_no_api=Current API data source is not supported. +i18n_sql_variable_name_empty=Variable name cannot be empty! diff --git a/core/core-backend/src/main/resources/i18n/core_zh_CN.properties b/core/core-backend/src/main/resources/i18n/core_zh_CN.properties index 111555f8bc..4a83bd0ca9 100644 --- a/core/core-backend/src/main/resources/i18n/core_zh_CN.properties +++ b/core/core-backend/src/main/resources/i18n/core_zh_CN.properties @@ -210,3 +210,4 @@ i18n_invalid_address=\u65E0\u6548\u7684\u5730\u5740\uFF01 i18n_unsupported_protocol=\u4E0D\u652F\u6301\u7684\u534F\u8BAE\uFF01 i18n_excel_error_first_row=\u9996\u884C\u884C\u4E2D\u4E0D\u5141\u8BB8\u6709\u7A7A\u5355\u5143\u683C\uFF01 i18n_app_error_no_api=\u5F53\u524D\u4E0D\u652F\u6301API\u6570\u636E\u6E90\u3002 +i18n_sql_variable_name_empty=\u53d8\u91cf\u4e0d\u80fd\u4e3a\u7a7a\uff01 diff --git a/core/core-backend/src/main/resources/i18n/core_zh_TW.properties b/core/core-backend/src/main/resources/i18n/core_zh_TW.properties index e04a7d1a2d..e7c9395bc2 100644 --- a/core/core-backend/src/main/resources/i18n/core_zh_TW.properties +++ b/core/core-backend/src/main/resources/i18n/core_zh_TW.properties @@ -210,3 +210,4 @@ i18n_invalid_address=\u7121\u6548\u7684\u5730\u5740\uFF01 i18n_unsupported_protocol=\u4E0D\u652F\u63F4\u7684\u5354\u8B70\uFF01 i18n_excel_error_first_row=\u9996\u884C\u884C\u4E2D\u4E0D\u5141\u8A31\u6709\u7A7A\u5132\u5B58\u683C\uFF01 i18n_app_error_no_api=\u7576\u524D\u4E0D\u652F\u63F4API\u6578\u64DA\u6E90\u3002 +i18n_sql_variable_name_empty=\u8b8a\u6578\u4e0d\u80fd\u70ba\u7a7a\uff01