Search in sources :

Example 1 with VisitorFeature

use of com.alibaba.druid.sql.visitor.VisitorFeature in project druid by alibaba.

the class SQLUtils method toSQLString.

public static String toSQLString(SQLObject sqlObject, DbType dbType, FormatOption option, VisitorFeature... features) {
    StringBuilder out = new StringBuilder();
    SQLASTOutputVisitor visitor = createOutputVisitor(out, dbType);
    if (option == null) {
        option = DEFAULT_FORMAT_OPTION;
    }
    visitor.setUppCase(option.isUppCase());
    visitor.setPrettyFormat(option.isPrettyFormat());
    visitor.setParameterized(option.isParameterized());
    int featuresValue = option.features;
    if (features != null) {
        for (VisitorFeature feature : features) {
            visitor.config(feature, true);
            featuresValue |= feature.mask;
        }
    }
    visitor.setFeatures(featuresValue);
    sqlObject.accept(visitor);
    String sql = out.toString();
    return sql;
}
Also used : VisitorFeature(com.alibaba.druid.sql.visitor.VisitorFeature) SQLASTOutputVisitor(com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)

Aggregations

SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)1 VisitorFeature (com.alibaba.druid.sql.visitor.VisitorFeature)1