use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlSelectTest_exportTables method test_1.
public void test_1() throws Exception {
String sql = "SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
// print(statementList);
assertEquals(1, statementList.size());
StringBuffer out = new StringBuffer();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
visitor.setExportTables(true);
stmt.accept(visitor);
assertEquals("SELECT *\n" + "FROM table1\n" + //
"\tINNER JOIN table2 ON table1.id = table2.id;", out.toString());
assertNotNull(visitor.getTables());
assertEquals(2, visitor.getTables().size());
assertEquals("[table1, table2]", visitor.getTables().toString());
}
use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.
the class MySqlSelectTest_exportTables method test_0.
public void test_0() throws Exception {
String sql = "select *\n" + "from my_table\n" + "where level between 10-5 and 10+5\n" + "order by -ABS(10 - level) desc\n" + "limit 0,100";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
// print(statementList);
assertEquals(1, statementList.size());
StringBuffer out = new StringBuffer();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
visitor.setExportTables(true);
stmt.accept(visitor);
assertEquals("SELECT *\n" + "FROM my_table\n" + "WHERE level BETWEEN 10 - 5 AND 10 + 5\n" + "ORDER BY -ABS(10 - level) DESC\n" + //
"LIMIT 0, 100", out.toString());
assertNotNull(visitor.getTables());
assertEquals(1, visitor.getTables().size());
assertTrue(visitor.getTables().contains("my_table"));
}
Aggregations