use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExprGroup in project druid by alibaba.
the class LargeOrTest method test_largeOr.
public void test_largeOr() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append("SELECT 1 FROM T WHERE ID = ?");
for (int i = 0; i < 10000; ++i) {
buf.append(" OR ID = ?");
}
String sql = buf.toString();
OracleStatementParser parser = new OracleStatementParser(sql, SQLParserFeature.EnableSQLBinaryOpExprGroup);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
SQLSelectQueryBlock select = (SQLSelectQueryBlock) stmt.getSelect().getQuery();
SQLBinaryOpExprGroup where = (SQLBinaryOpExprGroup) select.getWhere();
SQLBinaryOpExpr last = (SQLBinaryOpExpr) where.getItems().get(0);
Assert.assertEquals(SQLBinaryOperator.Equality, last.getOperator());
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExprGroup in project druid by alibaba.
the class SQLDeleteStatement method removeCondition.
public boolean removeCondition(SQLExpr condition) {
if (condition == null) {
return false;
}
if (where instanceof SQLBinaryOpExprGroup) {
SQLBinaryOpExprGroup group = (SQLBinaryOpExprGroup) where;
int removedCount = 0;
List<SQLExpr> items = group.getItems();
for (int i = items.size() - 1; i >= 0; i--) {
if (items.get(i).equals(condition)) {
items.remove(i);
removedCount++;
}
}
if (items.size() == 0) {
where = null;
}
return removedCount > 0;
}
if (where instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr binaryOpWhere = (SQLBinaryOpExpr) where;
SQLBinaryOperator operator = binaryOpWhere.getOperator();
if (operator == SQLBinaryOperator.BooleanAnd || operator == SQLBinaryOperator.BooleanOr) {
List<SQLExpr> items = SQLBinaryOpExpr.split(binaryOpWhere);
int removedCount = 0;
for (int i = items.size() - 1; i >= 0; i--) {
SQLExpr item = items.get(i);
if (item.equals(condition)) {
if (SQLUtils.replaceInParent(item, null)) {
removedCount++;
}
}
}
return removedCount > 0;
}
}
if (condition.equals(where)) {
where = null;
return true;
}
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExprGroup in project druid by alibaba.
the class SQLUpdateStatement method removeCondition.
public boolean removeCondition(SQLExpr condition) {
if (condition == null) {
return false;
}
if (where instanceof SQLBinaryOpExprGroup) {
SQLBinaryOpExprGroup group = (SQLBinaryOpExprGroup) where;
int removedCount = 0;
List<SQLExpr> items = group.getItems();
for (int i = items.size() - 1; i >= 0; i--) {
if (items.get(i).equals(condition)) {
items.remove(i);
removedCount++;
}
}
if (items.size() == 0) {
where = null;
}
return removedCount > 0;
}
if (where instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr binaryOpWhere = (SQLBinaryOpExpr) where;
SQLBinaryOperator operator = binaryOpWhere.getOperator();
if (operator == SQLBinaryOperator.BooleanAnd || operator == SQLBinaryOperator.BooleanOr) {
List<SQLExpr> items = SQLBinaryOpExpr.split(binaryOpWhere);
int removedCount = 0;
for (int i = items.size() - 1; i >= 0; i--) {
SQLExpr item = items.get(i);
if (item.equals(condition)) {
if (SQLUtils.replaceInParent(item, null)) {
removedCount++;
}
}
}
return removedCount > 0;
}
}
if (condition.equals(where)) {
where = null;
return true;
}
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLBinaryOpExprGroup in project druid by alibaba.
the class LargeOrTest method test_largeAnd.
public void test_largeAnd() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append("SELECT 1 FROM T WHERE ID = ?");
for (int i = 0; i < 10000; ++i) {
buf.append(" AND ID = ?");
}
String sql = buf.toString();
OracleStatementParser parser = new OracleStatementParser(sql, SQLParserFeature.EnableSQLBinaryOpExprGroup);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
SQLSelectQueryBlock select = (SQLSelectQueryBlock) stmt.getSelect().getQuery();
SQLBinaryOpExprGroup where = (SQLBinaryOpExprGroup) select.getWhere();
SQLBinaryOpExpr last = (SQLBinaryOpExpr) where.getItems().get(0);
Assert.assertEquals(SQLBinaryOperator.Equality, last.getOperator());
}
Aggregations