Search in sources :

Example 16 with OracleOutputVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.

the class OracleSelectGroupingTest 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());
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 17 with OracleOutputVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.

the class SQLMergeTest method merge.

private String merge() {
    StringBuilder out = new StringBuilder();
    OracleOutputVisitor visitor = new OracleOutputVisitor(out) {

        public boolean visit(SQLInListExpr x) {
            x.getExpr().accept(this);
            if (x.isNot()) {
                print(" NOT IN (##)");
            } else {
                print(" IN (##)");
            }
            return false;
        }
    };
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    for (SQLStatement statement : statementList) {
        statement.accept(visitor);
        visitor.println();
    }
    return out.toString();
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 18 with OracleOutputVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.

the class Demo0 method test_demo_0.

public void test_demo_0() throws Exception {
    String sql = "SELECT SYSDATE FROM DUAL";
    // parser得到AST
    SQLStatementParser parser = new OracleStatementParser(sql);
    // 
    List<SQLStatement> stmtList = parser.parseStatementList();
    // 将AST通过visitor输出
    StringBuilder out = new StringBuilder();
    OracleOutputVisitor visitor = new OracleOutputVisitor(out);
    for (SQLStatement stmt : stmtList) {
        stmt.accept(visitor);
        out.append(";");
    }
    System.out.println(out.toString());
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 19 with OracleOutputVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.

the class OracleTest method output.

protected String output(List<SQLStatement> stmtList) {
    StringBuilder out = new StringBuilder();
    OracleOutputVisitor visitor = new OracleOutputVisitor(out);
    for (SQLStatement stmt : stmtList) {
        stmt.accept(visitor);
    }
    return out.toString();
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 20 with OracleOutputVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor in project druid by alibaba.

the class CallTest 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());
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)20 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)18 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)11 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)6 Column (com.alibaba.druid.stat.TableStat.Column)5 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)3 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)2 SQLAllColumnExpr (com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr)2 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)2 SQLSelectGroupByClause (com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause)2 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)2 DB2SelectQueryBlock (com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock)2 DB2OutputVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2OutputVisitor)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)2 OracleSelectQueryBlock (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock)2 PGSelectQueryBlock (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock)2 PGOutputVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor)2 SQLServerSelectQueryBlock (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock)2