mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user