mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正大SQL的问题
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@899 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -783,12 +783,15 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
public final SQLExpr andRest(SQLExpr expr) throws ParserException {
|
||||
if (lexer.token() == Token.AND || lexer.token() == Token.AMPAMP) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = relational();
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.AND || lexer.token() == Token.AMPAMP) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = relational();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanAnd, rightExp);
|
||||
expr = andRest(expr);
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanAnd, rightExp);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return expr;
|
||||
@@ -800,18 +803,21 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
public final SQLExpr orRest(SQLExpr expr) throws ParserException {
|
||||
if (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = and();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanOr, rightExp);
|
||||
expr = orRest(expr);
|
||||
} else if (lexer.token() == Token.XOR) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = and();
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = and();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanXor, rightExp);
|
||||
expr = orRest(expr);
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanOr, rightExp);
|
||||
} else if (lexer.token() == Token.XOR) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = and();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanXor, rightExp);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return expr;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.druid.sql.oracle.bvt;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
|
||||
public class LargeOrTest extends TestCase {
|
||||
|
||||
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);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
SQLSelectQueryBlock select = (SQLSelectQueryBlock) stmt.getSelect().getQuery();
|
||||
SQLBinaryOpExpr where = (SQLBinaryOpExpr) select.getWhere();
|
||||
SQLBinaryOpExpr last = (SQLBinaryOpExpr) where.getRight();
|
||||
Assert.assertEquals(SQLBinaryOperator.Equality, last.getOperator());
|
||||
}
|
||||
|
||||
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);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
SQLSelectQueryBlock select = (SQLSelectQueryBlock) stmt.getSelect().getQuery();
|
||||
SQLBinaryOpExpr where = (SQLBinaryOpExpr) select.getWhere();
|
||||
SQLBinaryOpExpr last = (SQLBinaryOpExpr) where.getRight();
|
||||
Assert.assertEquals(SQLBinaryOperator.Equality, last.getOperator());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user