diff --git a/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index d5561c0148..8b9adb8d47 100644 --- a/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1115,7 +1115,22 @@ public class DataSetTableService { } } - private String handlePlainSelect(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception { + private void handleSelectItems(PlainSelect plainSelect, String dsType) throws Exception{ + List selectItems = new ArrayList<>(); + for (SelectItem selectItem : plainSelect.getSelectItems()) { + SelectExpressionItem selectExpressionItem = (SelectExpressionItem) selectItem; + if (selectExpressionItem.getExpression() instanceof SubSelect) { + SubSelect subSelect = (SubSelect) selectExpressionItem.getExpression(); + Select select = (Select) CCJSqlParserUtil.parse (removeVariables(subSelect.getSelectBody().toString(), dsType)); + subSelect.setSelectBody(select.getSelectBody()); + ((SelectExpressionItem) selectItem).setExpression(subSelect); + } + selectItems.add(selectItem); + } + plainSelect.setSelectItems(selectItems); + } + + private void handleFromItems(PlainSelect plainSelect, String dsType) throws Exception{ FromItem fromItem = plainSelect.getFromItem(); if (fromItem instanceof SubSelect) { SelectBody selectBody = ((SubSelect) fromItem).getSelectBody(); @@ -1123,7 +1138,9 @@ public class DataSetTableService { Select subSelectTmp = (Select) CCJSqlParserUtil.parse(removeVariables(selectBody.toString(), dsType)); subSelect.setSelectBody(subSelectTmp.getSelectBody()); if (dsType.equals(DatasourceTypes.oracle.getType())) { - subSelect.setAlias(new Alias(fromItem.getAlias().toString(), false)); + if(fromItem.getAlias() != null){ + subSelect.setAlias(new Alias(fromItem.getAlias().toString(), false)); + } } else { if (fromItem.getAlias() == null) { throw new Exception("Failed to parse sql, Every derived table must have its own alias!"); @@ -1132,6 +1149,8 @@ public class DataSetTableService { } plainSelect.setFromItem(subSelect); } + } + private void handleJoins(PlainSelect plainSelect, String dsType) throws Exception{ List joins = plainSelect.getJoins(); if (joins != null) { List joinsList = new ArrayList<>(); @@ -1157,27 +1176,29 @@ public class DataSetTableService { } plainSelect.setJoins(joinsList); } - Expression expr = plainSelect.getWhere(); - if (expr == null) { - return handleWith(plainSelect, statementSelect, dsType); - } - StringBuilder stringBuilder = new StringBuilder(); - BinaryExpression binaryExpression = null; - try { - binaryExpression = (BinaryExpression) expr; - } catch (Exception e) { - } - if (binaryExpression != null) { - if (!(binaryExpression.getLeftExpression() instanceof BinaryExpression) && !(binaryExpression.getLeftExpression() instanceof InExpression) && hasVariable(binaryExpression.getRightExpression().toString())) { - stringBuilder.append(SubstitutedSql); - } else { - expr.accept(getExpressionDeParser(stringBuilder)); - } - } else { - expr.accept(getExpressionDeParser(stringBuilder)); - } - plainSelect.setWhere(CCJSqlParserUtil.parseCondExpression(stringBuilder.toString())); - return handleWith(plainSelect, statementSelect, dsType); + } + private String handleWhere(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception{ + Expression expr = plainSelect.getWhere(); + if (expr == null) { + return handleWith(plainSelect, statementSelect, dsType); + } + StringBuilder stringBuilder = new StringBuilder(); + BinaryExpression binaryExpression = null; + try { + binaryExpression = (BinaryExpression) expr; + } catch (Exception e) { + } + if (binaryExpression != null) { + if (!(binaryExpression.getLeftExpression() instanceof BinaryExpression) && !(binaryExpression.getLeftExpression() instanceof InExpression) && hasVariable(binaryExpression.getRightExpression().toString())) { + stringBuilder.append(SubstitutedSql); + } else { + expr.accept(getExpressionDeParser(stringBuilder)); + } + } else { + expr.accept(getExpressionDeParser(stringBuilder)); + } + plainSelect.setWhere(CCJSqlParserUtil.parseCondExpression(stringBuilder.toString())); + return handleWith(plainSelect, statementSelect, dsType); } private String handleWith(PlainSelect plainSelect, Select select, String dsType) throws Exception { @@ -1198,6 +1219,15 @@ public class DataSetTableService { return builder.toString(); } + private String handlePlainSelect(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception { + handleSelectItems(plainSelect, dsType); + handleFromItems(plainSelect, dsType); + handleJoins(plainSelect, dsType); + return handleWhere(plainSelect, statementSelect, dsType); + } + + + public Map getDBPreview(DataSetTableRequest dataSetTableRequest) throws Exception { Datasource ds = datasourceMapper.selectByPrimaryKey(dataSetTableRequest.getDataSourceId()); if (ds == null) { diff --git a/core/frontend/src/lang/en.js b/core/frontend/src/lang/en.js index be6b4ca743..e4cf36a696 100644 --- a/core/frontend/src/lang/en.js +++ b/core/frontend/src/lang/en.js @@ -1945,7 +1945,7 @@ export default { please_input_max_pool_size: 'Please enter the maximum number of connections', please_input_max_idle_time: 'Please enter the maximum idle (seconds)', please_input_acquire_increment: 'Please enter the growth number', - please_input_query_timeout: 'Please enter query timeout', + please_input_query_timeout: 'Please enter query timeout,no less then zero', please_input_connect_timeout: 'Please enter the connection timeout (seconds)', no_less_then_0: 'Parameters in advanced settings cannot be less than zero', port_no_less_then_0: 'Port cannot be less than zero', diff --git a/core/frontend/src/lang/tw.js b/core/frontend/src/lang/tw.js index c441734b79..fac1efde46 100644 --- a/core/frontend/src/lang/tw.js +++ b/core/frontend/src/lang/tw.js @@ -1937,7 +1937,7 @@ export default { please_input_max_pool_size: '請輸入最大連接數', please_input_max_idle_time: '請輸入最大空閑(秒)', please_input_acquire_increment: '請輸入增長數', - please_input_query_timeout: '請輸入查詢超時', + please_input_query_timeout: '請輸入查詢超時,不小于零', please_input_connect_timeout: '請輸輸入連接超時(秒)', no_less_then_0: '高級設置中的參數不能小於零', port_no_less_then_0: '端口不能小於零', diff --git a/core/frontend/src/lang/zh.js b/core/frontend/src/lang/zh.js index 47258ecad2..4447e2f1cf 100644 --- a/core/frontend/src/lang/zh.js +++ b/core/frontend/src/lang/zh.js @@ -1937,7 +1937,7 @@ export default { please_input_max_pool_size: '请输入最大连接数', please_input_max_idle_time: '请输入最大空闲(秒)', please_input_acquire_increment: '请输入增长数', - please_input_query_timeout: '请输入查询超时', + please_input_query_timeout: '请输入查询超时,不小于零', please_input_connect_timeout: '请输入连接超时(秒)', no_less_then_0: '高级设置中的参数不能小于零', port_no_less_then_0: '端口不能小于零', diff --git a/core/frontend/src/views/system/datasource/DsConfiguration.vue b/core/frontend/src/views/system/datasource/DsConfiguration.vue index 0b59837c3d..1223b9430f 100644 --- a/core/frontend/src/views/system/datasource/DsConfiguration.vue +++ b/core/frontend/src/views/system/datasource/DsConfiguration.vue @@ -999,8 +999,7 @@ export default { { required: true, validator: this.isNumber, - message: i18n.t('datasource.please_input_query_timeout'), - trigger: 'blur' + trigger: ['blur', 'change'] } ], dataPath: [ @@ -1161,6 +1160,7 @@ export default { }, isNumber(rule, value, callback) { console.log(value) + console.log(!value) if (!value) { callback(new Error(i18n.t('datasource.please_input_query_timeout'))) return @@ -1168,8 +1168,9 @@ export default { let isNumber = false var reg = /^\d+$/; isNumber = reg.test(value); + console.log(!isNumber) if (!isNumber) { - callback(new Error(i18n.t('chart.value_error'))) + callback(new Error(i18n.t('datasource.please_input_query_timeout'))) return } callback()