use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement in project druid by alibaba.
the class PGSQLStatementParser method parseWith.
public SQLStatement parseWith() {
PGWithClause with = this.parseWithClause();
if (lexer.token() == Token.INSERT) {
PGInsertStatement stmt = this.parseInsert();
stmt.setWith(with);
return stmt;
}
if (lexer.token() == Token.SELECT) {
PGSelectStatement stmt = this.parseSelect();
stmt.setWith(with);
return stmt;
}
if (lexer.token() == Token.DELETE) {
PGDeleteStatement stmt = this.parseDeleteStatement();
stmt.setWith(with);
return stmt;
}
throw new ParserException("TODO");
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement 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.stmt.PGDeleteStatement in project druid by alibaba.
the class PGDeleteTest method test_1.
public void test_1() {
String sql = "delete from test01 as a where a.id = 2";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
assertTrue(statementList.size() == 1);
assertTrue(statemen instanceof PGDeleteStatement);
PGDeleteStatement delete = (PGDeleteStatement) statemen;
assertTrue(delete.getAlias().equalsIgnoreCase("a"));
assertTrue(delete.getTableName().getSimpleName().equals("test01"));
}
use of com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement in project druid by alibaba.
the class PGSQLStatementParser method parseDeleteStatement.
public PGDeleteStatement parseDeleteStatement() {
lexer.nextToken();
PGDeleteStatement deleteStatement = new PGDeleteStatement();
if (lexer.token() == (Token.FROM)) {
lexer.nextToken();
}
if (lexer.token() == (Token.ONLY)) {
lexer.nextToken();
deleteStatement.setOnly(true);
}
SQLName tableName = exprParser.name();
deleteStatement.setTableName(tableName);
if (lexer.token() == Token.AS) {
accept(Token.AS);
}
if (lexer.token() == Token.IDENTIFIER) {
deleteStatement.setAlias(lexer.stringVal());
lexer.nextToken();
}
if (lexer.token() == Token.USING) {
lexer.nextToken();
for (; ; ) {
SQLName name = this.exprParser.name();
deleteStatement.getUsing().add(name);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
}
if (lexer.token() == (Token.WHERE)) {
lexer.nextToken();
if (lexer.token() == Token.CURRENT) {
lexer.nextToken();
accept(Token.OF);
SQLName cursorName = this.exprParser.name();
SQLExpr where = new SQLCurrentOfCursorExpr(cursorName);
deleteStatement.setWhere(where);
} else {
SQLExpr where = this.exprParser.expr();
deleteStatement.setWhere(where);
}
}
if (lexer.token() == Token.RETURNING) {
lexer.nextToken();
accept(Token.STAR);
deleteStatement.setReturning(true);
}
return deleteStatement;
}
Aggregations