mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
0.2.15
This commit is contained in:
@@ -165,8 +165,12 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
return this.methodRest(new SQLIdentifierExpr("VALUES"), true);
|
||||
case BINARY:
|
||||
lexer.nextToken();
|
||||
SQLUnaryExpr binaryExpr = new SQLUnaryExpr(SQLUnaryOperator.BINARY, expr());
|
||||
return primaryRest(binaryExpr);
|
||||
if (lexer.token() == Token.COMMA || lexer.token() == Token.SEMI || lexer.token() == Token.EOF) {
|
||||
return new SQLIdentifierExpr("BINARY");
|
||||
} else {
|
||||
SQLUnaryExpr binaryExpr = new SQLUnaryExpr(SQLUnaryOperator.BINARY, expr());
|
||||
return primaryRest(binaryExpr);
|
||||
}
|
||||
default:
|
||||
return super.primary();
|
||||
}
|
||||
@@ -550,8 +554,9 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
SQLExpr var = primary();
|
||||
|
||||
String ident = null;
|
||||
if (var instanceof SQLIdentifierExpr) {
|
||||
String ident = ((SQLIdentifierExpr) var).getName();
|
||||
ident = ((SQLIdentifierExpr) var).getName();
|
||||
|
||||
if ("GLOBAL".equalsIgnoreCase(ident)) {
|
||||
ident = lexer.stringVal();
|
||||
@@ -565,18 +570,26 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
var = new SQLVariantRefExpr(ident);
|
||||
}
|
||||
}
|
||||
|
||||
if ("NAMES".equalsIgnoreCase(ident)) {
|
||||
// skip
|
||||
} else if ("CHARACTER".equalsIgnoreCase(ident)) {
|
||||
var = new SQLIdentifierExpr("CHARACTER SET");
|
||||
accept(Token.SET);
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
} else {
|
||||
if (lexer.token() == Token.COLONEQ) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
accept(Token.EQ);
|
||||
}
|
||||
}
|
||||
|
||||
item.setValue(this.expr());
|
||||
|
||||
item.setTarget(var);
|
||||
if (lexer.token() == Token.COLONEQ) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
accept(Token.EQ);
|
||||
}
|
||||
if (lexer.token() == Token.BINARY) {
|
||||
lexer.nextToken();
|
||||
item.setValue(new SQLIdentifierExpr("BINARY"));
|
||||
} else {
|
||||
item.setValue(expr());
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
@@ -2812,4 +2813,14 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
public void endVisit(MySqlAlterTableImportTablespace x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAssignItem x) {
|
||||
x.getTarget().accept(this);
|
||||
if (!"NAMES".equalsIgnoreCase(x.getTarget().toString())) {
|
||||
print(" = ");
|
||||
}
|
||||
x.getValue().accept(this);
|
||||
return false;
|
||||
}
|
||||
} //
|
||||
|
||||
@@ -131,7 +131,8 @@ public class OracleExprParser extends SQLExprParser {
|
||||
"SUM", //
|
||||
"VAR_POP", //
|
||||
"VAR_SAMP", //
|
||||
"VARIANCE" //
|
||||
"VARIANCE", //
|
||||
"WM_CONCAT"
|
||||
};
|
||||
|
||||
public OracleExprParser(Lexer lexer){
|
||||
|
||||
@@ -169,14 +169,14 @@ public class SQLSelectParser extends SQLParser {
|
||||
protected void withSubquery(SQLSelect select) {
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
SQLWithSubqueryClause withQueryClause = new SQLWithSubqueryClause();
|
||||
|
||||
|
||||
if (lexer.token == Token.RECURSIVE || identifierEquals("RECURSIVE")) {
|
||||
lexer.nextToken();
|
||||
withQueryClause.setRecursive(true);
|
||||
}
|
||||
|
||||
|
||||
for (;;) {
|
||||
SQLWithSubqueryClause.Entry entry = new SQLWithSubqueryClause.Entry();
|
||||
entry.setName((SQLIdentifierExpr) this.exprParser.name());
|
||||
@@ -252,7 +252,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
expr = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextTokenComma();
|
||||
|
||||
|
||||
if (lexer.token() != Token.COMMA) {
|
||||
expr = this.exprParser.primaryRest(expr);
|
||||
expr = this.exprParser.exprRest(expr);
|
||||
@@ -261,13 +261,13 @@ public class SQLSelectParser extends SQLParser {
|
||||
expr = expr();
|
||||
}
|
||||
final String alias = as();
|
||||
|
||||
|
||||
final SQLSelectItem selectItem = new SQLSelectItem(expr, alias);
|
||||
selectList.add(selectItem);
|
||||
if (lexer.token() != Token.COMMA) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
@@ -388,9 +388,13 @@ public class SQLSelectParser extends SQLParser {
|
||||
join.setCondition(expr());
|
||||
} else if (identifierEquals("USING")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
this.exprParser.exprList(join.getUsing());
|
||||
accept(Token.RPAREN);
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(join.getUsing());
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
join.getUsing().add(this.expr());
|
||||
}
|
||||
}
|
||||
|
||||
return parseTableSourceRest(join);
|
||||
|
||||
@@ -1080,6 +1080,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
printAndAccept(x.getUsing(), ", ");
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
print(" AS ");
|
||||
print(x.getAlias());
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
|
||||
|
||||
@@ -624,7 +624,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
|
||||
public boolean visit(SQLJoinTableSource x) {
|
||||
return true;
|
||||
x.getLeft().accept(this);
|
||||
x.getRight().accept(this);
|
||||
if (x.getCondition() != null) {
|
||||
x.getCondition().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLPropertyExpr x) {
|
||||
@@ -874,7 +879,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public boolean visit(SQLUpdateStatement x) {
|
||||
setAliasMap();
|
||||
|
||||
|
||||
setMode(x, Mode.Update);
|
||||
|
||||
SQLName identName = x.getTableName();
|
||||
@@ -999,7 +1004,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLCurrentOfCursorExpr x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAddColumn x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
@@ -1021,12 +1026,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLRollbackStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLCreateViewStatement x) {
|
||||
x.getSubQuery().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableDropForeinKey x) {
|
||||
return false;
|
||||
|
||||
@@ -251,6 +251,13 @@ public abstract class WallProvider {
|
||||
}
|
||||
|
||||
public WallCheckResult check(String sql) {
|
||||
WallContext context = WallContext.current();
|
||||
|
||||
if (context != null && !this.dbType.equals(context.getDbType())) {
|
||||
WallContext.clearContext();
|
||||
}
|
||||
|
||||
WallContext.createIfNotExists(this.dbType);
|
||||
WallCheckResult result = new WallCheckResult();
|
||||
|
||||
if (config.isDoPrivilegedAllow() && ispPivileged()) {
|
||||
|
||||
@@ -447,8 +447,15 @@ public class WallVisitorUtils {
|
||||
if (Boolean.FALSE == leftResult || Boolean.FALSE == rightResult) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (leftResult == Boolean.TRUE || rightResult == Boolean.TRUE) {
|
||||
|
||||
if (leftResult == Boolean.TRUE) {
|
||||
if (x.getParent() instanceof SQLExpr) {
|
||||
final WallConditionContext current = wallConditionContextLocal.get();
|
||||
if (current != null) {
|
||||
current.setPartAlwayTrue(true);
|
||||
}
|
||||
}
|
||||
} else if (rightResult == Boolean.TRUE) {
|
||||
final WallConditionContext current = wallConditionContextLocal.get();
|
||||
if (current != null) {
|
||||
current.setPartAlwayTrue(true);
|
||||
|
||||
Reference in New Issue
Block a user