All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zhuang.data.util.druid.SassMySqlUtils Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy