mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for visitor
This commit is contained in:
@@ -70,6 +70,7 @@ public class SQLInSubQueryExpr extends SQLExprImpl implements Serializable {
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor,this.expr);
|
||||
acceptChild(visitor, this.subQuery);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,14 @@ public class PGCurrentOfExpr extends PGSQLObjectImpl implements SQLExpr {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private SQLExpr cursor;
|
||||
|
||||
public PGCurrentOfExpr() {
|
||||
|
||||
}
|
||||
|
||||
public PGCurrentOfExpr(SQLExpr cursor) {
|
||||
this.cursor = cursor;
|
||||
}
|
||||
|
||||
public SQLExpr getCursor() {
|
||||
return cursor;
|
||||
|
||||
@@ -14,8 +14,17 @@ public class PGDeleteStatement extends SQLDeleteStatement implements PGSQLStatem
|
||||
private PGWithClause with;
|
||||
private boolean only = false;
|
||||
private List<SQLName> using = new ArrayList<SQLName>(2);
|
||||
private boolean returning;
|
||||
private String alias;
|
||||
|
||||
public boolean isReturning() {
|
||||
return returning;
|
||||
}
|
||||
|
||||
public void setReturning(boolean returning) {
|
||||
this.returning = returning;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
@@ -47,7 +56,7 @@ public class PGDeleteStatement extends SQLDeleteStatement implements PGSQLStatem
|
||||
public void setWith(PGWithClause with) {
|
||||
this.with = with;
|
||||
}
|
||||
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
}
|
||||
|
||||
@@ -105,6 +105,8 @@ public class PGLexer extends Lexer {
|
||||
map.put("CASCADE", Token.CASCADE);
|
||||
map.put("RESTRICT", Token.RESTRICT);
|
||||
map.put("USING", Token.USING);
|
||||
map.put("CURRENT", Token.CURRENT);
|
||||
map.put("RETURNING", Token.RETURNING);
|
||||
|
||||
DEFAULT_MYSQL_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
+18
-2
@@ -6,6 +6,7 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGCurrentOfExpr;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.PGTruncateStatement;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
@@ -59,8 +60,23 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == (Token.WHERE)) {
|
||||
lexer.nextToken();
|
||||
SQLExpr where = this.exprParser.expr();
|
||||
deleteStatement.setWhere(where);
|
||||
|
||||
if (lexer.token() == Token.CURRENT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.OF);
|
||||
SQLName cursorName = this.exprParser.name();
|
||||
SQLExpr where = new PGCurrentOfExpr(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;
|
||||
|
||||
@@ -303,6 +303,11 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
print("WHERE ");
|
||||
x.getWhere().accept(this);
|
||||
}
|
||||
|
||||
if (x.isReturning()) {
|
||||
println();
|
||||
print("RETURNING *");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -125,6 +125,8 @@ public enum Token {
|
||||
CASCADE("CASCADE"),
|
||||
RESTRICT("RESTRICT"),
|
||||
USING("USING"),
|
||||
CURRENT("CURRENT"),
|
||||
RETURNING("RETURNING"),
|
||||
|
||||
// oracle
|
||||
START("START"),
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
@@ -364,6 +365,11 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLInSubQueryExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLDeleteStatement x) {
|
||||
aliasLocal.set(null);
|
||||
|
||||
Reference in New Issue
Block a user