use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.
the class OracleOutputVisitorTest_Aggregate method test_0.
public void test_0() throws Exception {
String sql = "SELECT MAX(salary) from emp where F1 = Date '2011-10-01'";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertEquals(true, visitor.containsTable("emp"));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertEquals(true, visitor.getColumns().contains(new Column("emp", "salary")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("emp", "F1")));
StringBuilder buf = new StringBuilder();
OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
stmt.accept(outputVisitor);
Assert.assertEquals("SELECT MAX(salary)\nFROM emp\nWHERE F1 = DATE '2011-10-01'", buf.toString());
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.
the class OracleOutputVisitorTest_selectJoin method test_0.
public void test_0() throws Exception {
String sql = "SELECT e.salary from employee e join department d where e.depId = d.id";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(true, visitor.containsTable("employee"));
Assert.assertEquals(true, visitor.containsTable("department"));
Assert.assertEquals(3, visitor.getColumns().size());
Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "salary")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "depId")));
Assert.assertEquals(true, visitor.getColumns().contains(new Column("department", "id")));
StringBuilder buf = new StringBuilder();
OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
stmt.accept(outputVisitor);
Assert.assertEquals("SELECT e.salary\nFROM employee e\n\tJOIN department d\nWHERE e.depId = d.id", buf.toString());
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.
the class TestUtils method outputOracle.
public static String outputOracle(List<SQLStatement> stmtList) {
StringBuilder out = new StringBuilder();
OracleOutputVisitor visitor = new OracleOutputVisitor(out);
for (SQLStatement stmt : stmtList) {
stmt.accept(visitor);
}
return out.toString();
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.
the class OracleSelectParserTest method output.
private void output(List<SQLStatement> stmtList) {
StringBuilder out = new StringBuilder();
OracleOutputVisitor visitor = new OracleOutputVisitor(out);
for (SQLStatement stmt : stmtList) {
stmt.accept(visitor);
visitor.println();
}
System.out.println(out.toString());
}
use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.
the class OracleSQLParserTest method output.
private String output(List<SQLStatement> stmtList) {
StringBuilder out = new StringBuilder();
OracleOutputVisitor visitor = new OracleOutputVisitor(out);
for (SQLStatement stmt : stmtList) {
stmt.accept(visitor);
}
return out.toString();
}
Aggregations