From 0d74ac71ecce5f3c21cacd2bd678a68cb645905c Mon Sep 17 00:00:00 2001 From: junjun Date: Mon, 21 Oct 2024 16:12:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E6=BA=90):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DSQL=20Server=E5=8F=82=E6=95=B0=E5=8C=96=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=BF=87=E6=BB=A4=E4=B8=AD=E6=96=87=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/commons/utils/SqlparserUtils.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java b/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java index df1f2a89da..0b25d9a53f 100644 --- a/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java +++ b/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java @@ -536,7 +536,7 @@ public class SqlparserUtils { } } if (filterParameter != null) { - sql = sql.replace(matcher.group(), transFilter(filterParameter)); + sql = sql.replace(matcher.group(), transFilter(filterParameter, dsMap)); } else { if (defaultsSqlVariableDetail != null && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) { if (!isEdit && isFromDataSet && defaultsSqlVariableDetail.getDefaultValueScope().equals(SqlVariableDetails.DefaultValueScope.ALLSCOPE)) { @@ -594,9 +594,14 @@ public class SqlparserUtils { } - private static String transFilter(SqlVariableDetails sqlVariableDetails) { + private static String transFilter(SqlVariableDetails sqlVariableDetails, Map dsMap) { if (sqlVariableDetails.getOperator().equals("in")) { - return "'" + String.join("','", sqlVariableDetails.getValue()) + "'"; + if (StringUtils.equalsIgnoreCase(dsMap.entrySet().iterator().next().getValue().getType(), DatasourceConfiguration.DatasourceType.sqlServer.getType()) + && sqlVariableDetails.getDeType() == 0) { + return "N'" + String.join("', N'", sqlVariableDetails.getValue()) + "'"; + } else { + return "'" + String.join("','", sqlVariableDetails.getValue()) + "'"; + } } else if (sqlVariableDetails.getOperator().equals("between")) { if (sqlVariableDetails.getDeType() == 1) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(sqlVariableDetails.getType().size() > 1 ? (String) sqlVariableDetails.getType().get(1).replace("DD", "dd").replace("YYYY", "yyyy") : "yyyy");