From 2cd811104787b76629f0055932d8bad785ac7d8a Mon Sep 17 00:00:00 2001 From: junjie Date: Tue, 11 May 2021 11:11:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E9=9B=86):sql=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/service/dataset/DataSetTableService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 8f2efbe720..6473127af4 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -74,6 +74,11 @@ public class DataSetTableService { public DatasetTable save(DatasetTable datasetTable) throws Exception { checkName(datasetTable); + if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql")) { + DataSetTableRequest dataSetTableRequest = new DataSetTableRequest(); + BeanUtils.copyBean(dataSetTableRequest, datasetTable); + getSQLPreview(dataSetTableRequest); + } if (StringUtils.isEmpty(datasetTable.getId())) { datasetTable.setId(UUID.randomUUID().toString()); datasetTable.setCreateBy(AuthUtils.getUser().getUsername()); @@ -320,6 +325,10 @@ public class DataSetTableService { DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(ds); String sql = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getSql(); + // 使用输入的sql先预执行一次 + datasourceRequest.setQuery(sql); + datasourceProvider.fetchResultAndField(datasourceRequest); + // 正式执行 datasourceRequest.setQuery("SELECT * FROM (" + sql + ") AS tmp LIMIT 0,1000"); Map result = datasourceProvider.fetchResultAndField(datasourceRequest); List data = result.get("dataList");