mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor parser, rename bracket to parenthesized
This commit is contained in:
@@ -39,7 +39,7 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements SQLReplaceable, Seri
|
||||
|
||||
|
||||
|
||||
private boolean bracket = false;
|
||||
private boolean parenthesized = false;
|
||||
|
||||
// only for parameterized output
|
||||
protected transient List<SQLObject> mergedList;
|
||||
@@ -154,12 +154,12 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements SQLReplaceable, Seri
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public boolean isBracket() {
|
||||
return bracket;
|
||||
public boolean isParenthesized() {
|
||||
return parenthesized;
|
||||
}
|
||||
|
||||
public void setBracket(boolean bracket) {
|
||||
this.bracket = bracket;
|
||||
public void setParenthesized(boolean parenthesized) {
|
||||
this.parenthesized = parenthesized;
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
@@ -244,7 +244,7 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements SQLReplaceable, Seri
|
||||
}
|
||||
x.operator = operator;
|
||||
x.dbType = dbType;
|
||||
x.bracket = bracket;
|
||||
x.parenthesized = parenthesized;
|
||||
|
||||
if (hint != null) {
|
||||
x.hint = hint.clone();
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
|
||||
public interface SQLSelectQuery extends SQLObject {
|
||||
boolean isBracket();
|
||||
void setBracket(boolean bracket);
|
||||
boolean isParenthesized();
|
||||
void setParenthesized(boolean paren);
|
||||
|
||||
SQLSelectQuery clone();
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
@@ -512,14 +509,6 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
}
|
||||
this.setFrom(from);
|
||||
}
|
||||
|
||||
public boolean isParenthesized() {
|
||||
return parenthesized;
|
||||
}
|
||||
|
||||
public void setParenthesized(boolean parenthesized) {
|
||||
this.parenthesized = parenthesized;
|
||||
}
|
||||
|
||||
public boolean isForUpdate() {
|
||||
return forUpdate;
|
||||
@@ -1016,13 +1005,13 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBracket() {
|
||||
public boolean isParenthesized() {
|
||||
return parenthesized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBracket(boolean bracket) {
|
||||
this.parenthesized = bracket;
|
||||
public void setParenthesized(boolean paren) {
|
||||
this.parenthesized = paren;
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSource(String alias) {
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLDbTypedObject;
|
||||
import com.alibaba.druid.sql.ast.SQLLimit;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -31,7 +29,7 @@ import java.util.List;
|
||||
|
||||
public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLDbTypedObject {
|
||||
|
||||
private boolean bracket = false;
|
||||
private boolean parenthesized = false;
|
||||
|
||||
private List<SQLSelectQuery> relations = new ArrayList<SQLSelectQuery>();
|
||||
private SQLUnionOperator operator = SQLUnionOperator.UNION;
|
||||
@@ -52,6 +50,10 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
|
||||
}
|
||||
|
||||
public SQLUnionQuery(DbType dbType){
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public SQLUnionQuery(SQLSelectQuery left, SQLUnionOperator operator, SQLSelectQuery right){
|
||||
this.setLeft(left);
|
||||
this.operator = operator;
|
||||
@@ -63,6 +65,10 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
return relations;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return relations.isEmpty();
|
||||
}
|
||||
|
||||
public void addRelation(SQLSelectQuery relation) {
|
||||
if (relation != null) {
|
||||
relation.setParent(this);
|
||||
@@ -162,18 +168,18 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public boolean isBracket() {
|
||||
return bracket;
|
||||
public boolean isParenthesized() {
|
||||
return parenthesized;
|
||||
}
|
||||
|
||||
public void setBracket(boolean bracket) {
|
||||
this.bracket = bracket;
|
||||
public void setParenthesized(boolean paren) {
|
||||
this.parenthesized = paren;
|
||||
}
|
||||
|
||||
public SQLUnionQuery clone() {
|
||||
SQLUnionQuery x = new SQLUnionQuery();
|
||||
|
||||
x.bracket = bracket;
|
||||
x.parenthesized = parenthesized;
|
||||
|
||||
for (SQLSelectQuery relation : relations) {
|
||||
SQLSelectQuery r = relation.clone();
|
||||
@@ -234,7 +240,7 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
}
|
||||
|
||||
public List<SQLSelectQuery> getChildren() {
|
||||
boolean bracket = this.bracket && !(parent instanceof SQLUnionQueryTableSource);
|
||||
boolean bracket = this.parenthesized && !(parent instanceof SQLUnionQueryTableSource);
|
||||
|
||||
if (relations.size() > 2) {
|
||||
return relations;
|
||||
@@ -246,7 +252,7 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
if ((!bracket)
|
||||
&& left instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) left).getOperator() == operator
|
||||
&& !right.isBracket()
|
||||
&& !right.isParenthesized()
|
||||
&& orderBy == null) {
|
||||
|
||||
SQLUnionQuery leftUnion = (SQLUnionQuery) left;
|
||||
@@ -258,10 +264,10 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
SQLSelectQuery leftLeft = leftUnion.getLeft();
|
||||
SQLSelectQuery leftRight = leftUnion.getRight();
|
||||
|
||||
if ((!leftUnion.isBracket())
|
||||
if ((!leftUnion.isParenthesized())
|
||||
&& leftUnion.getOrderBy() == null
|
||||
&& (!leftLeft.isBracket())
|
||||
&& (!leftRight.isBracket())
|
||||
&& (!leftLeft.isParenthesized())
|
||||
&& (!leftRight.isParenthesized())
|
||||
&& leftLeft instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) leftLeft).getOperator() == operator) {
|
||||
rights.add(leftRight);
|
||||
@@ -288,7 +294,7 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
|
||||
SQLUnionQuery that = (SQLUnionQuery) o;
|
||||
|
||||
if (bracket != that.bracket) return false;
|
||||
if (parenthesized != that.parenthesized) return false;
|
||||
if (relations != null ? !relations.equals(that.relations) : that.relations != null) return false;
|
||||
if (operator != that.operator) return false;
|
||||
if (orderBy != null ? !orderBy.equals(that.orderBy) : that.orderBy != null) return false;
|
||||
@@ -298,7 +304,7 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery, SQLD
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (bracket ? 1 : 0);
|
||||
int result = (parenthesized ? 1 : 0);
|
||||
result = 31 * result + (relations != null ? relations.hashCode() : 0);
|
||||
result = 31 * result + (operator != null ? operator.hashCode() : 0);
|
||||
result = 31 * result + (orderBy != null ? orderBy.hashCode() : 0);
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLValuesQuery extends SQLObjectImpl implements SQLSelectQuery {
|
||||
private boolean bracket = false;
|
||||
private boolean parenthesized = false;
|
||||
|
||||
private List<SQLExpr> values = new ArrayList<SQLExpr>();
|
||||
|
||||
@@ -46,18 +46,18 @@ public class SQLValuesQuery extends SQLObjectImpl implements SQLSelectQuery {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBracket() {
|
||||
return bracket;
|
||||
public boolean isParenthesized() {
|
||||
return parenthesized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBracket(boolean bracket) {
|
||||
this.bracket = bracket;
|
||||
public void setParenthesized(boolean paren) {
|
||||
this.parenthesized = paren;
|
||||
}
|
||||
|
||||
public SQLValuesQuery clone() {
|
||||
SQLValuesQuery x = new SQLValuesQuery();
|
||||
x.bracket = bracket;
|
||||
x.parenthesized = parenthesized;
|
||||
|
||||
for (int i = 0; i < values.size(); ++i) {
|
||||
SQLExpr value = values.get(i).clone();
|
||||
|
||||
@@ -21,8 +21,6 @@ import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLListExpr;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsObject;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -32,7 +30,7 @@ import java.util.List;
|
||||
* Created by wenshao on 23/02/2017.
|
||||
*/
|
||||
public class SQLValuesTableSource extends SQLTableSourceImpl implements SQLSelectQuery, SQLReplaceable {
|
||||
private boolean bracket;
|
||||
private boolean parenthesized;
|
||||
private List<SQLListExpr> values = new ArrayList<SQLListExpr>();
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
@@ -76,13 +74,13 @@ public class SQLValuesTableSource extends SQLTableSourceImpl implements SQLSelec
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBracket() {
|
||||
return bracket;
|
||||
public boolean isParenthesized() {
|
||||
return parenthesized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBracket(boolean bracket) {
|
||||
this.bracket = bracket;
|
||||
public void setParenthesized(boolean paren) {
|
||||
this.parenthesized = paren;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
@@ -114,7 +113,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLSelectQuery select = query();
|
||||
select.setBracket(true);
|
||||
select.setParenthesized(true);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
return queryRest(select, acceptUnion);
|
||||
@@ -383,7 +382,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
SQLSelectQuery query = queryRest(select.getQuery(), false);
|
||||
if (query instanceof SQLUnionQuery && select.getWithSubQuery() == null) {
|
||||
select.getQuery().setBracket(true);
|
||||
select.getQuery().setParenthesized(true);
|
||||
tableSource = new SQLUnionQueryTableSource((SQLUnionQuery) query);
|
||||
} else {
|
||||
tableSource = new SQLSubqueryTableSource(select);
|
||||
@@ -401,7 +400,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
SQLSelectQuery query = queryRest(select.getQuery(), true);
|
||||
if (query instanceof SQLUnionQuery && select.getWithSubQuery() == null) {
|
||||
select.getQuery().setBracket(true);
|
||||
select.getQuery().setParenthesized(true);
|
||||
tableSource = new SQLUnionQueryTableSource((SQLUnionQuery) query);
|
||||
} else {
|
||||
tableSource = new SQLSubqueryTableSource(select);
|
||||
@@ -416,7 +415,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
SQLSelectQuery query = queryRest(unionQuery, true);
|
||||
if (query instanceof SQLUnionQuery) {
|
||||
unionQuery.setBracket(true);
|
||||
unionQuery.setParenthesized(true);
|
||||
tableSource = new SQLUnionQueryTableSource((SQLUnionQuery) query);
|
||||
} else {
|
||||
tableSource = new SQLSubqueryTableSource(unionQuery);
|
||||
|
||||
@@ -94,7 +94,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
public boolean visit(MySqlSelectQueryBlock x) {
|
||||
final boolean bracket = x.isBracket();
|
||||
final boolean bracket = x.isParenthesized();
|
||||
if (bracket) {
|
||||
print('(');
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
printlnComments(x.getBeforeCommentsDirect());
|
||||
}
|
||||
|
||||
final boolean bracket = x.isBracket();
|
||||
final boolean bracket = x.isParenthesized();
|
||||
if (bracket) {
|
||||
print('(');
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
if (sqlExpr instanceof SQLBinaryOpExpr) {
|
||||
((SQLBinaryOpExpr) sqlExpr).setBracket(true);
|
||||
((SQLBinaryOpExpr) sqlExpr).setParenthesized(true);
|
||||
}
|
||||
|
||||
if ((lexer.token == Token.UNION || lexer.token == Token.MINUS || lexer.token == Token.EXCEPT)
|
||||
@@ -3299,7 +3299,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
if (operator == SQLBinaryOperator.BooleanAnd
|
||||
|| operator == SQLBinaryOperator.BooleanOr) {
|
||||
if (binaryOpExpr.isBracket()) {
|
||||
if (binaryOpExpr.isParenthesized()) {
|
||||
binaryOpExpr.setHint(new SQLCommentHint(text));
|
||||
} else {
|
||||
SQLExpr right = binaryOpExpr.getRight();
|
||||
|
||||
@@ -100,9 +100,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
}
|
||||
|
||||
protected SQLUnionQuery createSQLUnionQuery() {
|
||||
SQLUnionQuery union = new SQLUnionQuery();
|
||||
union.setDbType(dbType);
|
||||
return union;
|
||||
return new SQLUnionQuery(dbType);
|
||||
}
|
||||
|
||||
public SQLUnionQuery unionRest(SQLUnionQuery union) {
|
||||
@@ -149,9 +147,7 @@ public class SQLSelectParser extends SQLParser {
|
||||
}
|
||||
|
||||
SQLUnionQuery union = createSQLUnionQuery();
|
||||
if (union.getRelations().isEmpty()) {
|
||||
union.setLeft(selectQuery);
|
||||
}
|
||||
union.setLeft(selectQuery);
|
||||
|
||||
if (lexer.token == Token.ALL) {
|
||||
union.setOperator(SQLUnionOperator.UNION_ALL);
|
||||
|
||||
@@ -44,7 +44,6 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitorAdapter;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.PGUtils;
|
||||
@@ -2382,12 +2381,12 @@ class SchemaResolveVisitorFactory {
|
||||
SQLSelectQuery left = x.getLeft();
|
||||
SQLSelectQuery right = x.getRight();
|
||||
|
||||
boolean bracket = x.isBracket() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
boolean bracket = x.isParenthesized() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
|
||||
if ((!bracket)
|
||||
&& left instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) left).getOperator() == operator
|
||||
&& !right.isBracket()
|
||||
&& !right.isParenthesized()
|
||||
&& x.getOrderBy() == null) {
|
||||
|
||||
SQLUnionQuery leftUnion = (SQLUnionQuery) left;
|
||||
@@ -2402,10 +2401,10 @@ class SchemaResolveVisitorFactory {
|
||||
SQLSelectQuery leftLeft = leftUnion.getLeft();
|
||||
SQLSelectQuery leftRight = leftUnion.getRight();
|
||||
|
||||
if ((!leftUnion.isBracket())
|
||||
if ((!leftUnion.isParenthesized())
|
||||
&& leftUnion.getOrderBy() == null
|
||||
&& (!leftLeft.isBracket())
|
||||
&& (!leftRight.isBracket())
|
||||
&& (!leftLeft.isParenthesized())
|
||||
&& (!leftRight.isParenthesized())
|
||||
&& leftLeft instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) leftLeft).getOperator() == operator) {
|
||||
rights.add(leftRight);
|
||||
|
||||
@@ -582,7 +582,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
quote = true;
|
||||
break;
|
||||
default:
|
||||
quote = ((SQLBinaryOpExpr) testExpr).isBracket();
|
||||
quote = ((SQLBinaryOpExpr) testExpr).isParenthesized();
|
||||
break;
|
||||
}
|
||||
} else if (testExpr instanceof SQLInListExpr
|
||||
@@ -614,7 +614,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (beginExpr instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpBegin = (SQLBinaryOpExpr) beginExpr;
|
||||
incrementIndent();
|
||||
if (binaryOpBegin.isBracket()
|
||||
if (binaryOpBegin.isParenthesized()
|
||||
|| binaryOpBegin.getOperator().isLogical()
|
||||
|| binaryOpBegin.getOperator().isRelational()) {
|
||||
print('(');
|
||||
@@ -647,7 +647,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (endExpr instanceof SQLBinaryOpExpr) {
|
||||
SQLBinaryOpExpr binaryOpEnd = (SQLBinaryOpExpr) endExpr;
|
||||
incrementIndent();
|
||||
if (binaryOpEnd.isBracket()
|
||||
if (binaryOpEnd.isParenthesized()
|
||||
|| binaryOpEnd.getOperator().isLogical()
|
||||
|| binaryOpEnd.getOperator().isRelational()) {
|
||||
print('(');
|
||||
@@ -801,7 +801,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (itemOp.priority > operator.priority) {
|
||||
bracket = true;
|
||||
} else {
|
||||
bracket = binaryOpExpr.isBracket() & !parameterized;
|
||||
bracket = binaryOpExpr.isParenthesized() & !parameterized;
|
||||
}
|
||||
if (bracket) {
|
||||
print('(');
|
||||
@@ -1020,7 +1020,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|| rightOp == SQLBinaryOperator.BooleanOr;
|
||||
|
||||
if (rightOp.priority >= op.priority
|
||||
|| (binaryRight.isBracket()
|
||||
|| (binaryRight.isParenthesized()
|
||||
&& rightOp != op
|
||||
&& rightOp.isLogical()
|
||||
&& op.isLogical()
|
||||
@@ -1090,7 +1090,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
bracket = true;
|
||||
} else if ((leftOp == SQLBinaryOperator.Is || leftOp == SQLBinaryOperator.IsNot) && !op.isLogical()) {
|
||||
bracket = true;
|
||||
} else if (binaryLeft.isBracket()) {
|
||||
} else if (binaryLeft.isParenthesized()) {
|
||||
if (leftOp != op && ((leftOp.isLogical() && op.isLogical()) || op == SQLBinaryOperator.Is)) {
|
||||
bracket = true;
|
||||
} else {
|
||||
@@ -1595,7 +1595,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
quote = true;
|
||||
break;
|
||||
default:
|
||||
quote = ((SQLBinaryOpExpr) expr).isBracket();
|
||||
quote = ((SQLBinaryOpExpr) expr).isParenthesized();
|
||||
break;
|
||||
}
|
||||
} else if (expr instanceof SQLNotExpr
|
||||
@@ -3713,13 +3713,13 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
SQLSelectQuery left = x.getLeft();
|
||||
SQLSelectQuery right = x.getRight();
|
||||
|
||||
boolean bracket = x.isBracket() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
boolean bracket = x.isParenthesized() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
|
||||
SQLOrderBy orderBy = x.getOrderBy();
|
||||
if ((!bracket)
|
||||
&& left instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) left).getOperator() == operator
|
||||
&& !right.isBracket()
|
||||
&& !right.isParenthesized()
|
||||
&& x.getLimit() == null
|
||||
&& orderBy == null) {
|
||||
|
||||
@@ -3728,7 +3728,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (right instanceof SQLSelectQueryBlock) {
|
||||
SQLSelectQueryBlock rightQueryBlock = (SQLSelectQueryBlock) right;
|
||||
if (rightQueryBlock.getOrderBy() != null || rightQueryBlock.getLimit() != null) {
|
||||
rightQueryBlock.setBracket(true);
|
||||
rightQueryBlock.setParenthesized(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3745,14 +3745,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
if (leftRight instanceof SQLSelectQueryBlock) {
|
||||
SQLSelectQueryBlock leftRightQueryBlock = (SQLSelectQueryBlock) leftRight;
|
||||
if (leftRightQueryBlock.getOrderBy() != null || leftRightQueryBlock.getLimit() != null) {
|
||||
leftRightQueryBlock.setBracket(true);
|
||||
leftRightQueryBlock.setParenthesized(true);
|
||||
}
|
||||
}
|
||||
|
||||
if ((!leftUnion.isBracket())
|
||||
if ((!leftUnion.isParenthesized())
|
||||
&& leftUnion.getOrderBy() == null
|
||||
&& (!leftLeft.isBracket())
|
||||
&& (!leftRight.isBracket())
|
||||
&& (!leftLeft.isParenthesized())
|
||||
&& (!leftRight.isParenthesized())
|
||||
&& leftLeft instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) leftLeft).getOperator() == operator) {
|
||||
rights.add(leftRight);
|
||||
@@ -3792,7 +3792,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
} else {
|
||||
SQLSelectQuery leftLeft = leftUnion.getLeft();
|
||||
SQLSelectQuery leftRigt = leftUnion.getRight();
|
||||
if ((!leftUnion.isBracket())
|
||||
if ((!leftUnion.isParenthesized())
|
||||
&& leftUnion.getRight() instanceof SQLSelectQueryBlock
|
||||
&& leftUnion.getLeft() != null
|
||||
&& leftUnion.getLimit() == null
|
||||
@@ -3828,7 +3828,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
println();
|
||||
|
||||
boolean needParen = false;
|
||||
if ((!right.isBracket())
|
||||
if ((!right.isParenthesized())
|
||||
&& right instanceof SQLSelectQueryBlock) {
|
||||
SQLSelectQueryBlock rightQuery = (SQLSelectQueryBlock) right;
|
||||
if (rightQuery.getOrderBy() != null || rightQuery.getLimit() != null) {
|
||||
|
||||
@@ -3004,12 +3004,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLSelectQuery left = x.getLeft();
|
||||
SQLSelectQuery right = x.getRight();
|
||||
|
||||
boolean bracket = x.isBracket() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
boolean bracket = x.isParenthesized() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
|
||||
if ((!bracket)
|
||||
&& left instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) left).getOperator() == operator
|
||||
&& !right.isBracket()
|
||||
&& !right.isParenthesized()
|
||||
&& x.getOrderBy() == null) {
|
||||
|
||||
SQLUnionQuery leftUnion = (SQLUnionQuery) left;
|
||||
@@ -3024,10 +3024,10 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
SQLSelectQuery leftLeft = leftUnion.getLeft();
|
||||
SQLSelectQuery leftRight = leftUnion.getRight();
|
||||
|
||||
if ((!leftUnion.isBracket())
|
||||
if ((!leftUnion.isParenthesized())
|
||||
&& leftUnion.getOrderBy() == null
|
||||
&& (!leftLeft.isBracket())
|
||||
&& (!leftRight.isBracket())
|
||||
&& (!leftLeft.isParenthesized())
|
||||
&& (!leftRight.isParenthesized())
|
||||
&& leftLeft instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) leftLeft).getOperator() == operator) {
|
||||
rights.add(leftRight);
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExecuteImmediateStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleLockTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
@@ -2291,12 +2290,12 @@ public class WallVisitorUtils {
|
||||
SQLSelectQuery left = x.getLeft();
|
||||
SQLSelectQuery right = x.getRight();
|
||||
|
||||
boolean bracket = x.isBracket() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
boolean bracket = x.isParenthesized() && !(x.getParent() instanceof SQLUnionQueryTableSource);
|
||||
|
||||
if ((!bracket)
|
||||
&& left instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) left).getOperator() == operator
|
||||
&& !right.isBracket()
|
||||
&& !right.isParenthesized()
|
||||
&& x.getOrderBy() == null) {
|
||||
|
||||
SQLUnionQuery leftUnion = (SQLUnionQuery) left;
|
||||
@@ -2308,10 +2307,10 @@ public class WallVisitorUtils {
|
||||
SQLSelectQuery leftLeft = leftUnion.getLeft();
|
||||
SQLSelectQuery leftRight = leftUnion.getRight();
|
||||
|
||||
if ((!leftUnion.isBracket())
|
||||
if ((!leftUnion.isParenthesized())
|
||||
&& leftUnion.getOrderBy() == null
|
||||
&& (!leftLeft.isBracket())
|
||||
&& (!leftRight.isBracket())
|
||||
&& (!leftLeft.isParenthesized())
|
||||
&& (!leftRight.isParenthesized())
|
||||
&& leftLeft instanceof SQLUnionQuery
|
||||
&& ((SQLUnionQuery) leftLeft).getOperator() == operator) {
|
||||
rights.add(leftRight);
|
||||
|
||||
Reference in New Issue
Block a user