Merge pull request #976 from zhujunxxxxx/master

修复表达式执行错误issue#975
This commit is contained in:
Yako
2015-10-23 11:50:26 +08:00
2 changed files with 34 additions and 0 deletions
@@ -1049,6 +1049,20 @@ public class SQLEvalVisitorUtils {
x.putAttribute(EVAL_VALUE, result);
break;
}
case BooleanAnd:
{
boolean first = eq(leftValue, true);
boolean second = eq(rightValue, true);
x.putAttribute(EVAL_VALUE, first&&second);
break;
}
case BooleanOr:
{
boolean first = eq(leftValue, true);
boolean second = eq(rightValue, true);
x.putAttribute(EVAL_VALUE, first||second);
break;
}
default:
break;
}
@@ -0,0 +1,20 @@
package com.alibaba.druid.bvt.sql.eval;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
import com.alibaba.druid.util.JdbcConstants;
public class EvalAndOrTest extends TestCase {
public void test_and() throws Exception {
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>0 && ?>0", 1,0));
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "2>1 && 100>10"));
}
public void test_or() throws Exception {
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "10>0 || 2>0"));
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "10>0 || 2<0"));
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "2>10 || 100<10"));
}
}