Merge pull request #12811 from dataease/pr@dev-v2@fix_ds

fix(数据源): 修复SQL Server参数化无法过滤中文的问题
This commit is contained in:
Junjun 2024-10-21 16:13:56 +08:00 committed by GitHub
commit 642d839bed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<Long, DatasourceSchemaDTO> 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");