Search in sources :

Example 6 with MySqlExportParameterVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor in project druid by alibaba.

the class ExportParameters method test_export_parameters.

public void test_export_parameters() throws Exception {
    String sql = "select * from t where id = 3 and name = 'abc'";
    List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
    StringBuilder out = new StringBuilder();
    ExportParameterVisitor visitor = new MySqlExportParameterVisitor(out);
    for (SQLStatement stmt : stmtList) {
        stmt.accept(visitor);
    }
    String paramteredSql = out.toString();
    System.out.println(paramteredSql);
    // [3, "abc"]
    List<Object> paramters = visitor.getParameters();
    for (Object param : paramters) {
        System.out.println(param);
    }
}
Also used : MySqlExportParameterVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor) ExportParameterVisitor(com.alibaba.druid.sql.visitor.ExportParameterVisitor) MySqlExportParameterVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 MySqlExportParameterVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor)6 ExportParameterVisitor (com.alibaba.druid.sql.visitor.ExportParameterVisitor)6 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)5