use of com.alibaba.druid.sql.visitor.ParameterizedVisitor in project druid by alibaba.
the class ExportAndParameterizedVisitorTestCase method testParameterizedVisitor.
public void testParameterizedVisitor() {
// final String sql =
// "insert into tab01(a,b,c) values('a1','bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1',5)";
Object[][] sqlAndExpectedCases = { { "insert into tab01(a,b,c) values('a1','b1',5)", 3, "a1" }, { "select * from tab01 where a=1 and b='b1'", 2, 1 }, { "update tab01 set d='d1' where a=1 and b='b1'", 3, "d1" }, { "delete from tab01 where a=1 and b='b1'", 2, 1.0 } };
String[] dbTypes = { "mysql", "oracle", "db2", JdbcConstants.POSTGRESQL, JdbcUtils.JTDS, "not-found" };
// String[] dbTypes = { JdbcUtils.JTDS};
for (String dbType : dbTypes) {
System.out.println("dbType:" + dbType);
for (Object[] arr : sqlAndExpectedCases) {
final String sql = (String) arr[0];
StringBuilder out = new StringBuilder();
final SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
final ParameterizedVisitor pVisitor = (ParameterizedVisitor) ExportParameterVisitorUtils.createExportParameterVisitor(out, dbType);
final SQLStatement parseStatement = parser.parseStatement();
parseStatement.accept(pVisitor);
// final ExportParameterVisitor vistor2 = new MySqlExportParameterVisitor();
// parseStatement.accept(vistor2);
final ExportParameterVisitor vistor2 = (ExportParameterVisitor) pVisitor;
System.out.println("before:" + sql);
System.out.println("after:" + out);
System.out.println("size:" + vistor2.getParameters());
final int expectedSize = (Integer) arr[1];
Assert.assertEquals(expectedSize, vistor2.getParameters().size());
}
}
}
Aggregations