Search in sources :

Example 1 with PGWithQuery

use of com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery in project druid by alibaba.

the class PGSQLStatementParser method parseWithClause.

public PGWithClause parseWithClause() {
    lexer.nextToken();
    PGWithClause withClause = new PGWithClause();
    if (lexer.token() == Token.RECURSIVE) {
        lexer.nextToken();
        withClause.setRecursive(true);
    }
    for (; ; ) {
        PGWithQuery withQuery = withQuery();
        withClause.getWithQuery().add(withQuery);
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        } else {
            break;
        }
    }
    return withClause;
}
Also used : PGWithClause(com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause) PGWithQuery(com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery)

Example 2 with PGWithQuery

use of com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery in project druid by alibaba.

the class PGASTVisitorAdapterTest method test_adapter.

public void test_adapter() throws Exception {
    PGASTVisitorAdapter adapter = new PGASTVisitorAdapter();
    new WindowClause().accept(adapter);
    new FetchClause().accept(adapter);
    new ForClause().accept(adapter);
    new PGWithQuery().accept(adapter);
    new PGWithClause().accept(adapter);
    new PGDeleteStatement().accept(adapter);
    new PGFunctionTableSource().accept(adapter);
}
Also used : PGWithQuery(com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery) PGWithClause(com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause) PGFunctionTableSource(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGFunctionTableSource) PGASTVisitorAdapter(com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitorAdapter) ForClause(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause) FetchClause(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause) WindowClause(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause) PGDeleteStatement(com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement)

Example 3 with PGWithQuery

use of com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery in project druid by alibaba.

the class PGSQLStatementParser method withQuery.

private PGWithQuery withQuery() {
    PGWithQuery withQuery = new PGWithQuery();
    if (lexer.token() == Token.LITERAL_ALIAS) {
        withQuery.setName(new SQLIdentifierExpr("\"" + lexer.stringVal() + "\""));
    } else {
        withQuery.setName(new SQLIdentifierExpr(lexer.stringVal()));
    }
    lexer.nextToken();
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        for (; ; ) {
            SQLExpr expr = this.exprParser.expr();
            withQuery.addColumn(expr);
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            } else {
                break;
            }
        }
        accept(Token.RPAREN);
    }
    accept(Token.AS);
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        SQLStatement query;
        if (lexer.token() == Token.SELECT) {
            query = this.parseSelect();
        } else if (lexer.token() == Token.INSERT) {
            query = this.parseInsert();
        } else if (lexer.token() == Token.UPDATE) {
            query = this.parseUpdateStatement();
        } else if (lexer.token() == Token.DELETE) {
            query = this.parseDeleteStatement();
        } else if (lexer.token() == Token.VALUES) {
            query = this.parseSelect();
        } else {
            throw new ParserException("syntax error, support token '" + lexer.token() + "'");
        }
        withQuery.setQuery(query);
        accept(Token.RPAREN);
    }
    return withQuery;
}
Also used : PGWithQuery(com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

PGWithQuery (com.alibaba.druid.sql.dialect.postgresql.ast.PGWithQuery)3 PGWithClause (com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 PGDeleteStatement (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement)1 PGFunctionTableSource (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGFunctionTableSource)1 FetchClause (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause)1 ForClause (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause)1 WindowClause (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause)1 PGASTVisitorAdapter (com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitorAdapter)1