mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 05:20:15 +08:00
Merge remote-tracking branch 'origin/oracle-value-processor' into oracle-value-processor
This commit is contained in:
@ -96,7 +96,7 @@ public class DlTemplateServiceImpl implements DlTemplateService {
|
||||
//RemoveSpecialGO(param);
|
||||
DbType dbType =
|
||||
JdbcUtils.parse2DruidDbType(Chat2DBContext.getConnectInfo().getDbType());
|
||||
List<String> sqlList = SqlUtils.parse(param.getSql(), dbType);
|
||||
List<String> sqlList = SqlUtils.parse(param.getSql(), dbType,true);
|
||||
Connection connection = Chat2DBContext.getConnection();
|
||||
try {
|
||||
// connection.setAutoCommit(false);
|
||||
|
@ -493,7 +493,7 @@ public class SQLExecutor implements CommandExecutor {
|
||||
// parse sql
|
||||
String type = Chat2DBContext.getConnectInfo().getDbType();
|
||||
DbType dbType = JdbcUtils.parse2DruidDbType(type);
|
||||
List<String> sqlList = SqlUtils.parse(command.getScript(), dbType);
|
||||
List<String> sqlList = SqlUtils.parse(command.getScript(), dbType,true);
|
||||
|
||||
if (CollectionUtils.isEmpty(sqlList)) {
|
||||
throw new BusinessException("dataSource.sqlAnalysisError");
|
||||
|
@ -125,10 +125,10 @@ public class SqlUtils {
|
||||
|
||||
private static final String EVENT_REGEX = "(?i)\\bcreate\\s+event\\b.*?\\bend\\b";
|
||||
|
||||
public static List<String> parse(String sql, DbType dbType) {
|
||||
public static List<String> parse(String sql, DbType dbType, boolean removeComment) {
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
sql = SQLParserUtils.removeComment(sql, dbType);
|
||||
|
||||
if (StringUtils.isBlank(sql)) {
|
||||
return list;
|
||||
}
|
||||
@ -137,7 +137,7 @@ public class SqlUtils {
|
||||
SqlSplitter sqlSplitter = new SqlSplitter(PlSqlLexer.class, ";", false);
|
||||
sqlSplitter.setRemoveCommentPrefix(true);
|
||||
List<SplitSqlString> sqls = sqlSplitter.split(sql);
|
||||
return sqls.stream().map(splitSqlString -> SQLParserUtils.removeComment(splitSqlString.getStr(), dbType)).collect(Collectors.toList());
|
||||
return sqls.stream().map(splitSqlString -> removeComment ? SQLParserUtils.removeComment(splitSqlString.getStr(), dbType) : splitSqlString.getStr()).collect(Collectors.toList());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("sqlSplitter error", e);
|
||||
@ -149,11 +149,14 @@ public class SqlUtils {
|
||||
sql = updateNow(sql, dbType);
|
||||
SqlSplitProcessor sqlSplitProcessor = new SqlSplitProcessor(dbType, true, true);
|
||||
sqlSplitProcessor.setDelimiter(";");
|
||||
return split(sqlSplitProcessor, sql, dbType);
|
||||
return split(sqlSplitProcessor, sql, dbType, removeComment);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("sqlSplitProcessor error", e);
|
||||
}
|
||||
if (removeComment) {
|
||||
sql = SQLParserUtils.removeComment(sql, dbType);
|
||||
}
|
||||
// sql = removeDelimiter(sql);
|
||||
if (StringUtils.isBlank(sql)) {
|
||||
return list;
|
||||
@ -172,7 +175,11 @@ public class SqlUtils {
|
||||
try {
|
||||
return splitWithCreateEvent(sql, dbType);
|
||||
} catch (Exception e1) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, dbType);
|
||||
if(removeComment) {
|
||||
return SQLParserUtils.splitAndRemoveComment(sql, dbType);
|
||||
}{
|
||||
return SQLParserUtils.split(sql, dbType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
@ -280,7 +287,7 @@ public class SqlUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<String> split(SqlSplitProcessor processor, String sql, DbType dbType) {
|
||||
private static List<String> split(SqlSplitProcessor processor, String sql, DbType dbType, boolean removeComment) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
List<SplitSqlString> sqls = processor.split(buffer, sql);
|
||||
String bufferStr = buffer.toString();
|
||||
@ -301,7 +308,11 @@ public class SqlUtils {
|
||||
// String sqlstr = SQLParserUtils.removeComment(sql, dbType);
|
||||
// return Lists.newArrayList(sqlstr);
|
||||
}
|
||||
return sqls.stream().map(splitSqlString -> SQLParserUtils.removeComment(splitSqlString.getStr(), dbType)).collect(Collectors.toList());
|
||||
return sqls.stream().map(splitSqlString -> removeComment ? SQLParserUtils.removeComment(splitSqlString.getStr(), dbType) : splitSqlString.getStr()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
public static String quoteObjectName(String name) {
|
||||
|
Reference in New Issue
Block a user