mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve wall filter
This commit is contained in:
@@ -28,7 +28,9 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
private String name;
|
||||
|
||||
public SQLPropertyExpr(SQLExpr owner, String name){
|
||||
|
||||
if (owner != null) {
|
||||
owner.setParent(this);
|
||||
}
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
}
|
||||
@@ -46,6 +48,9 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
}
|
||||
|
||||
public void setOwner(SQLExpr owner) {
|
||||
if (owner != null) {
|
||||
owner.setParent(this);
|
||||
}
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
|
||||
@@ -54,4 +56,13 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
public void setName(SQLName name) {
|
||||
this.setTableSource(new SQLExprTableSource(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, getTableSource());
|
||||
acceptChild(visitor, getItems());
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ public class SQLDeleteStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public void setTableSource(SQLTableSource tableSource) {
|
||||
if (tableSource != null) {
|
||||
tableSource.setParent(this);
|
||||
}
|
||||
this.tableSource = tableSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,9 @@ public abstract class SQLInsertInto extends SQLObjectImpl {
|
||||
}
|
||||
|
||||
public void setTableSource(SQLExprTableSource tableSource) {
|
||||
if (tableSource != null) {
|
||||
tableSource.setParent(this);
|
||||
}
|
||||
this.tableSource = tableSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,9 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
|
||||
}
|
||||
|
||||
public void setLeft(SQLTableSource left) {
|
||||
if (left != null) {
|
||||
left.setParent(this);
|
||||
}
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
@@ -71,6 +74,9 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
|
||||
}
|
||||
|
||||
public void setRight(SQLTableSource right) {
|
||||
if (right != null) {
|
||||
right.setParent(this);
|
||||
}
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@@ -79,6 +85,9 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
|
||||
}
|
||||
|
||||
public void setCondition(SQLExpr condition) {
|
||||
if (condition != null) {
|
||||
condition.setParent(this);
|
||||
}
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,13 @@ public class SQLSelectQueryBlock extends SQLSelectQuery {
|
||||
}
|
||||
|
||||
public void setInto(SQLExpr into) {
|
||||
this.into = new SQLExprTableSource(into);
|
||||
this.setInto(new SQLExprTableSource(into));
|
||||
}
|
||||
|
||||
public void setInto(SQLExprTableSource into) {
|
||||
if (into != null) {
|
||||
into.setParent(this);
|
||||
}
|
||||
this.into = into;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ public class SQLTruncateStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public void addTableSource(SQLName name) {
|
||||
this.tableSources.add(new SQLExprTableSource(name));
|
||||
SQLExprTableSource tableSource = new SQLExprTableSource(name);
|
||||
tableSource.setParent(this);
|
||||
this.tableSources.add(tableSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,6 +45,9 @@ public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public void setTableSource(SQLTableSource tableSource) {
|
||||
if (tableSource != null) {
|
||||
tableSource.setParent(this);
|
||||
}
|
||||
this.tableSource = tableSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -203,12 +203,12 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected final void scanString() {
|
||||
{
|
||||
boolean hasSpecial = false;
|
||||
int startIndex = pos + 1;
|
||||
int endIndex = -1; //text.indexOf('\'', startIndex);
|
||||
int endIndex = -1; // text.indexOf('\'', startIndex);
|
||||
for (int i = startIndex; i < text.length(); ++i) {
|
||||
final char ch = text.charAt(i);
|
||||
if (ch == '\\') {
|
||||
@@ -219,13 +219,13 @@ public class MySqlLexer extends Lexer {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (endIndex == -1) {
|
||||
throw new ParserException("unclosed str");
|
||||
}
|
||||
|
||||
String stringVal = subString(startIndex, endIndex - startIndex);
|
||||
// hasSpecial = stringVal.indexOf('\\') != -1;
|
||||
// hasSpecial = stringVal.indexOf('\\') != -1;
|
||||
|
||||
if (!hasSpecial) {
|
||||
this.stringVal = stringVal;
|
||||
@@ -328,6 +328,8 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
|
||||
public void scanComment() {
|
||||
Token lastToken = this.token;
|
||||
|
||||
if (ch != '/' && ch != '-') {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
@@ -374,8 +376,14 @@ public class MySqlLexer extends Lexer {
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
}
|
||||
|
||||
if (token != Token.HINT && !isAllowComment()) {
|
||||
throw new NotAllowCommentException();
|
||||
if (token != Token.HINT) {
|
||||
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAllowComment()) {
|
||||
throw new NotAllowCommentException();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -64,10 +64,15 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (lexer.token() == Token.HINT) {
|
||||
this.exprParser.parseHints(queryBlock.getHints());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == (Token.DISTINCT)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
|
||||
|
||||
@@ -235,6 +235,10 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.DELETE) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals(LOW_PRIORITY)) {
|
||||
deleteStatement.setLowPriority(true);
|
||||
|
||||
@@ -244,6 +244,10 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
OracleSelectQueryBlock queryBlock = new OracleSelectQueryBlock();
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
parseHints(queryBlock);
|
||||
|
||||
|
||||
@@ -1462,6 +1462,10 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.DELETE) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
parseHints(deleteStatement.getHints());
|
||||
|
||||
|
||||
@@ -66,6 +66,11 @@ public class PGInsertStatement extends SQLInsertStatement implements PGSQLStatem
|
||||
public List<ValuesClause> getValuesList() {
|
||||
return valuesList;
|
||||
}
|
||||
|
||||
public void addValueCause(ValuesClause valueClause) {
|
||||
valueClause.setParent(this);
|
||||
valuesList.add(valueClause);
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
|
||||
+4
-3
@@ -110,9 +110,10 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
for (;;) {
|
||||
accept(Token.LPAREN);
|
||||
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
|
||||
this.exprParser.exprList(values.getValues());
|
||||
stmt.getValuesList().add(values);
|
||||
SQLInsertStatement.ValuesClause valuesCaluse = new SQLInsertStatement.ValuesClause();
|
||||
this.exprParser.exprList(valuesCaluse.getValues());
|
||||
stmt.addValueCause(valuesCaluse);
|
||||
|
||||
accept(Token.RPAREN);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -52,6 +52,10 @@ public class PGSelectParser extends SQLSelectParser {
|
||||
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DISTINCT) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
|
||||
|
||||
+4
@@ -66,6 +66,10 @@ public class SQLServerSelectParser extends SQLSelectParser {
|
||||
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DISTINCT) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
|
||||
|
||||
@@ -68,10 +68,20 @@ public class Lexer {
|
||||
|
||||
private int varIndex = -1;
|
||||
|
||||
protected CommentHandler commentHandler;
|
||||
|
||||
public Lexer(String input){
|
||||
this(input, true);
|
||||
}
|
||||
|
||||
public CommentHandler getCommentHandler() {
|
||||
return commentHandler;
|
||||
}
|
||||
|
||||
public void setCommentHandler(CommentHandler commentHandler) {
|
||||
this.commentHandler = commentHandler;
|
||||
}
|
||||
|
||||
public final char charAt(int index) {
|
||||
if (index >= text.length()) {
|
||||
return EOI;
|
||||
@@ -1008,4 +1018,9 @@ public class Lexer {
|
||||
public BigDecimal decimalValue() {
|
||||
return new BigDecimal(text.toCharArray(), mark, bufPos);
|
||||
}
|
||||
|
||||
public static interface CommentHandler {
|
||||
|
||||
boolean handle(Token lastToken, String comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class NotAllowCommentException extends ParserException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NotAllowCommentException(){
|
||||
super();
|
||||
this("comment not allow");
|
||||
}
|
||||
|
||||
public NotAllowCommentException(String message, Throwable e){
|
||||
|
||||
@@ -141,6 +141,10 @@ public class SQLSelectParser extends SQLParser {
|
||||
}
|
||||
|
||||
accept(Token.SELECT);
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLSelectQueryBlock queryBlock = new SQLSelectQueryBlock();
|
||||
|
||||
|
||||
@@ -617,6 +617,10 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token() == (Token.FROM)) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLName tableName = exprParser.name();
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeinKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType;
|
||||
@@ -449,4 +450,8 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLAlterTableEnableKeys x);
|
||||
|
||||
void endVisit(SQLAlterTableEnableKeys x);
|
||||
|
||||
boolean visit(SQLAlterTableStatement x);
|
||||
|
||||
void endVisit(SQLAlterTableStatement x);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeinKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCallStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType;
|
||||
@@ -831,4 +832,14 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public void endVisit(SQLAlterTableEnableKeys x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user