From f337c73c11a47df25903ffabed4e77070a21f0fc Mon Sep 17 00:00:00 2001 From: taojinlong Date: Wed, 29 Nov 2023 12:13:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E8=A7=A3=E6=9E=90sql=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/dataease/service/dataset/DataSetTableService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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..057f561df7 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 @@ -1123,7 +1123,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!"); From 02d678a9b6120cd694430c5757cf31e0ab071c7f Mon Sep 17 00:00:00 2001 From: taojinlong Date: Wed, 29 Nov 2023 12:22:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E6=A0=A1=E9=AA=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/frontend/src/lang/en.js | 2 +- core/frontend/src/lang/tw.js | 2 +- core/frontend/src/lang/zh.js | 2 +- .../src/views/system/datasource/DsConfiguration.vue | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/frontend/src/lang/en.js b/core/frontend/src/lang/en.js index 19d7844838..187004dd64 100644 --- a/core/frontend/src/lang/en.js +++ b/core/frontend/src/lang/en.js @@ -1944,7 +1944,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 af5aa0f52d..cf3a0c0a50 100644 --- a/core/frontend/src/lang/tw.js +++ b/core/frontend/src/lang/tw.js @@ -1936,7 +1936,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 dc0ca4b1fd..9a7081548b 100644 --- a/core/frontend/src/lang/zh.js +++ b/core/frontend/src/lang/zh.js @@ -1936,7 +1936,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() From 2062cfd4e6fd3a9623b5c1d4e50ef5e7e4ef32f2 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Wed, 29 Nov 2023 12:59:43 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20SQL=E5=8F=98=E9=87=8F=E8=AF=AF?= =?UTF-8?q?=E6=8A=A5=E9=94=99=20#6624?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-) 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 057f561df7..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(); @@ -1134,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<>(); @@ -1159,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 { @@ -1200,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) {