com.zhuang.data.util.druid.SassMySqlUtils Maven / Gradle / Ivy
package com.zhuang.data.util.druid;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.parser.SQLParserUtils;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.alibaba.druid.util.JdbcConstants;
import java.util.List;
import java.util.function.Supplier;
public class SassMySqlUtils {
public static String parseSql(String sql, List tableInfoList, String fieldName, Supplier valueSupplier) {
SQLStatementParser sqlStatementParser = SQLParserUtils.createSQLStatementParser(sql, JdbcConstants.MYSQL);
List sqlStatementList = sqlStatementParser.parseStatementList();
SassModifyMySqlVisitor sassModifyMySqlVisitor = new SassModifyMySqlVisitor(tableInfoList, fieldName, valueSupplier);
sqlStatementList.forEach(c -> c.accept(sassModifyMySqlVisitor));
if (sassModifyMySqlVisitor.hasModify()) {
StringBuilder sbSql = new StringBuilder();
sqlStatementList.forEach(c -> sbSql.append('\n').append(c.toString()));
return sbSql.toString();
} else {
return null;
}
}
}