mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sql parser
This commit is contained in:
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.ast.expr;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -127,4 +128,7 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return SQLUtils.toSQLString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,15 +82,6 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.RegExp, rightExp);
|
||||
}
|
||||
|
||||
if (identifierEquals("RLIKE")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = equality();
|
||||
|
||||
rightExp = relationalRest(rightExp);
|
||||
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.RegExp, rightExp);
|
||||
}
|
||||
|
||||
return super.relationalRest(expr);
|
||||
}
|
||||
|
||||
@@ -117,15 +108,6 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotRegExp, rightExp);
|
||||
}
|
||||
|
||||
if (identifierEquals("RLIKE")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = primary();
|
||||
|
||||
rightExp = relationalRest(rightExp);
|
||||
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotRLike, rightExp);
|
||||
}
|
||||
|
||||
return super.notRationalRest(expr);
|
||||
}
|
||||
|
||||
|
||||
@@ -498,7 +498,7 @@ public class SQLExprParser extends SQLParser {
|
||||
break;
|
||||
case BANG:
|
||||
lexer.nextToken();
|
||||
SQLExpr bangExpr = expr();
|
||||
SQLExpr bangExpr = primary();
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Not, bangExpr);
|
||||
break;
|
||||
case LITERAL_HEX:
|
||||
@@ -1234,6 +1234,13 @@ public class SQLExprParser extends SQLParser {
|
||||
rightExp = primary();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Escape, rightExp);
|
||||
}
|
||||
} else if (identifierEquals("RLIKE")) {
|
||||
lexer.nextToken();
|
||||
rightExp = equality();
|
||||
|
||||
rightExp = relationalRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.RLike, rightExp);
|
||||
} else if (lexer.token() == (Token.NOT)) {
|
||||
lexer.nextToken();
|
||||
expr = notRationalRest(expr);
|
||||
@@ -1307,6 +1314,13 @@ public class SQLExprParser extends SQLParser {
|
||||
expr = new SQLBetweenExpr(expr, true, beginExpr, endExpr);
|
||||
|
||||
return expr;
|
||||
} else if (identifierEquals("RLIKE")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = primary();
|
||||
|
||||
rightExp = relationalRest(rightExp);
|
||||
|
||||
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotRLike, rightExp);
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.alibaba.druid.bvt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
|
||||
public class OrTest extends TestCase {
|
||||
public void test_xx() throws Exception {
|
||||
String sql = "select * from t where not match('', '') or (c > 0 and d >0)";
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, null);
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
System.out.println(stmt.toString());
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class LogicalOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT !(1 + 1);", text);
|
||||
Assert.assertEquals("SELECT !1 + 1;", text);
|
||||
}
|
||||
|
||||
public void test_8() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user