forked from github/dataease
fix: 解析 sql 空指针异常
This commit is contained in:
parent
05f510d3af
commit
f29aa2ca95
@ -962,14 +962,22 @@ public class DataSetTableService {
|
||||
public String removeVariables(String sql) throws Exception {
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(sql);
|
||||
boolean hasVariables = false;
|
||||
while (matcher.find()) {
|
||||
hasVariables = true;
|
||||
sql = sql.replace(matcher.group(), SubstitutedParams);
|
||||
}
|
||||
if(!hasVariables){
|
||||
return sql;
|
||||
}
|
||||
CCJSqlParserUtil.parse(sql, parser -> parser.withSquareBracketQuotation(true));
|
||||
Statement statement = CCJSqlParserUtil.parse(sql);
|
||||
Select select = (Select) statement;
|
||||
PlainSelect plainSelect = ((PlainSelect) select.getSelectBody());
|
||||
Expression expr = plainSelect.getWhere();
|
||||
if(expr == null){
|
||||
return sql;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
BinaryExpression binaryExpression = (BinaryExpression)expr;
|
||||
|
||||
|
@ -143,7 +143,8 @@ public class DatasourceService {
|
||||
}
|
||||
|
||||
if(datasourceDTO.getType().equalsIgnoreCase(DatasourceTypes.mysql.toString())){
|
||||
datasourceDTO.setConfiguration(datasourceDTO.getConfiguration());
|
||||
MysqlConfiguration mysqlConfiguration = new Gson().fromJson(datasourceDTO.getConfiguration(), MysqlConfiguration.class);
|
||||
datasourceDTO.setConfiguration(new Gson().toJson(mysqlConfiguration));
|
||||
}
|
||||
if (datasourceDTO.getType().equalsIgnoreCase(DatasourceTypes.api.toString())) {
|
||||
List<ApiDefinition> apiDefinitionList = new Gson().fromJson(datasourceDTO.getConfiguration(), new TypeToken<ArrayList<ApiDefinition>>() {}.getType());
|
||||
|
Loading…
Reference in New Issue
Block a user