mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved wallfilter. support update column check.
This commit is contained in:
@@ -490,4 +490,22 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements SQLReplaceable, Seri
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean conditionContainsColumn(String column) {
|
||||
if (left == null || right == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (left instanceof SQLIdentifierExpr) {
|
||||
if (((SQLIdentifierExpr) left).nameEquals(column)) {
|
||||
return true;
|
||||
}
|
||||
} else if (right instanceof SQLIdentifierExpr) {
|
||||
if (((SQLIdentifierExpr) right).nameEquals(column)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,4 +178,8 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean nameEquals(String name) {
|
||||
return SQLUtils.nameEquals(this.name, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,4 +199,8 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean nameEquals(String name) {
|
||||
return SQLUtils.nameEquals(this.name, name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLUpdateSetItem extends SQLObjectImpl {
|
||||
@@ -60,4 +62,12 @@ public class SQLUpdateSetItem extends SQLObjectImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public boolean columnMatch(String column) {
|
||||
if (this.column instanceof SQLIdentifierExpr) {
|
||||
return ((SQLIdentifierExpr) this.column).nameEquals(column);
|
||||
} else if (this.column instanceof SQLPropertyExpr) {
|
||||
((SQLPropertyExpr) this.column).nameEquals(column);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,14 @@ public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceab
|
||||
|
||||
public SQLName getTableName() {
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
|
||||
return (SQLName) exprTableSource.getExpr();
|
||||
return ((SQLExprTableSource) tableSource).getName();
|
||||
}
|
||||
|
||||
if (tableSource instanceof SQLJoinTableSource) {
|
||||
SQLTableSource left = ((SQLJoinTableSource) tableSource).getLeft();
|
||||
if (left instanceof SQLExprTableSource) {
|
||||
return ((SQLExprTableSource) left).getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1395,8 +1395,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
setMode(x, Mode.Update);
|
||||
|
||||
SQLName identName = x.getTableName();
|
||||
if (identName != null) {
|
||||
SQLTableSource tableSource = x.getTableSource();
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLName identName = ((SQLExprTableSource) tableSource).getName();
|
||||
String ident = identName.toString();
|
||||
setCurrentTable(ident);
|
||||
|
||||
@@ -1406,7 +1407,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
putAliasMap(aliasMap, ident, ident);
|
||||
} else {
|
||||
x.getTableSource().accept(this);
|
||||
tableSource.accept(this);
|
||||
}
|
||||
|
||||
accept(x.getFrom());
|
||||
|
||||
Reference in New Issue
Block a user