mirror of
https://github.com/dataease/dataease.git
synced 2026-06-16 20:42:07 +08:00
fix: 【数据集】编辑sql外部参数名称为空时也可成功设置默认值
This commit is contained in:
@@ -42,10 +42,10 @@ public class DeSqlparserUtils {
|
||||
private List<SqlVariableDetails> defaultsSqlVariableDetails = new ArrayList<>();
|
||||
|
||||
public String handleVariableDefaultValue(String sql, String sqlVariableDetails, boolean isEdit, boolean isFromDataSet, List<SqlVariableDetails> parameters, boolean isCross, Map<Long, DatasourceSchemaDTO> 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<Long, DatasourceSchemaDTO> 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<XpackPluginsDatasourceVO> xpackPluginsDatasourceVOS = pluginManage.queryPluginDs();
|
||||
List<XpackPluginsDatasourceVO> 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<Long, DatasourceSchemaDTO> 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<XpackPluginsDatasourceVO> xpackPluginsDatasourceVOS = pluginManage.queryPluginDs();
|
||||
// List<XpackPluginsDatasourceVO> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user