Search in sources :

Example 1 with DB2ASTVisitorAdapter

use of com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitorAdapter in project druid by alibaba.

the class Issue2038 method test_for_demo.

public void test_for_demo() throws Exception {
    String sql = "select * from (select * from t union all select * from t1 union all select * from t3) xx";
    List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, DbType.db2);
    SQLASTVisitor visitor = new DB2ASTVisitorAdapter() {

        public boolean visit(SQLUnionQuery x) {
            System.out.println("union");
            return true;
        }

        public boolean visit(DB2SelectQueryBlock x) {
            System.out.println("select");
            return true;
        }
    };
    for (SQLStatement stmt : stmtList) {
        stmt.accept(visitor);
    }
}
Also used : SQLASTVisitor(com.alibaba.druid.sql.visitor.SQLASTVisitor) DB2ASTVisitorAdapter(com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitorAdapter) SQLUnionQuery(com.alibaba.druid.sql.ast.statement.SQLUnionQuery) DB2SelectQueryBlock(com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLUnionQuery (com.alibaba.druid.sql.ast.statement.SQLUnionQuery)1 DB2SelectQueryBlock (com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock)1 DB2ASTVisitorAdapter (com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitorAdapter)1 SQLASTVisitor (com.alibaba.druid.sql.visitor.SQLASTVisitor)1