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;
}
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);
}
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;
}
Aggregations