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

fix(数据集): 修复SQL片段分号结尾后有空格、换行符报错的问题
This commit is contained in:
Junjun 2024-08-23 10:43:32 +08:00 committed by GitHub
commit c5e4fb5d7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View File

@ -481,8 +481,9 @@ public class SqlparserUtils {
if (StringUtils.isEmpty(sql)) {
DEException.throwException(Translator.get("i18n_sql_not_empty"));
}
if (sql.trim().endsWith(";")) {
sql = sql.trim().substring(0, sql.length() - 1);
sql = sql.trim();
if (sql.endsWith(";")) {
sql = sql.substring(0, sql.length() - 1);
}
if (StringUtils.isNotEmpty(sqlVariableDetails)) {

View File

@ -450,8 +450,9 @@ public class CopilotManage {
public String transSql(String type, String copilotSQL, Provider provider, ReceiveDTO receiveDTO) {
if (type.equals("oracle") || type.equals("sqlServer")) {
try {
if (copilotSQL.trim().endsWith(";")) {
copilotSQL = copilotSQL.trim().substring(0, copilotSQL.length() - 1);
copilotSQL = copilotSQL.trim();
if (copilotSQL.endsWith(";")) {
copilotSQL = copilotSQL.substring(0, copilotSQL.length() - 1);
}
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
datasourceSchemaDTO.setType(type);

View File

@ -20,8 +20,9 @@ public class SqlUtils {
public static Logger logger = LoggerFactory.getLogger(SqlUtils.class);
public static String addSchema(String sql, String schema) {
if (sql.trim().endsWith(";")) {
sql = sql.trim().substring(0, sql.length() - 1);
sql = sql.trim();
if (sql.endsWith(";")) {
sql = sql.substring(0, sql.length() - 1);
}
SqlParser.Config config =