Merge remote-tracking branch 'upstream/master'

This commit is contained in:
wenshao
2013-06-07 18:49:30 +08:00
12 changed files with 167 additions and 115 deletions
@@ -797,6 +797,9 @@ public class SQLEvalVisitorUtils {
wallConditionContext.setConstArithmetic(true);
}
leftValue = processValue(leftValue);
rightValue = processValue(rightValue);
if (leftValue == null || rightValue == null) {
return false;
}
@@ -890,6 +893,17 @@ public class SQLEvalVisitorUtils {
return false;
}
@SuppressWarnings("rawtypes")
private static Object processValue(Object value) {
if (value instanceof List) {
List list = (List) value;
if (list.size() == 1) {
return processValue(list.get(0));
}
}
return value;
}
private static boolean isAlwayTrueLikePattern(SQLExpr x) {
if (x instanceof SQLCharExpr) {
String text = ((SQLCharExpr) x).getText();
@@ -1223,7 +1237,7 @@ public class SQLEvalVisitorUtils {
}
if (a instanceof String || b instanceof String) {
return ((String) a).compareTo((String) b) > 0;
return castToString(a).compareTo(castToString(b)) > 0;
}
if (a instanceof BigDecimal || b instanceof BigDecimal) {
@@ -38,8 +38,10 @@ public class Isnull implements Function {
SQLExpr condition = parameters.get(0);
condition.accept(visitor);
Object itemValue = condition.getAttributes().get(EVAL_VALUE);
if (itemValue == null || itemValue == EVAL_VALUE_NULL) {
if (itemValue == EVAL_VALUE_NULL) {
return Boolean.TRUE;
} else if (itemValue == null) {
return null;
} else {
return Boolean.FALSE;
}
@@ -22,10 +22,10 @@ import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
import com.alibaba.druid.sql.visitor.SQLEvalVisitor;
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
public class Right implements Function {
public final static Right instance = new Right();
public Object eval(SQLEvalVisitor visitor, SQLMethodInvokeExpr x) {
if (x.getParameters().size() != 2) {
return SQLEvalVisitor.EVAL_ERROR;
@@ -45,7 +45,11 @@ public class Right implements Function {
String strValue = param0Value.toString();
int intValue = SQLEvalVisitorUtils.castToInteger(param1Value);
String result = strValue.substring(strValue.length() - intValue, strValue.length());
int start = strValue.length() - intValue;
if (start < 0) {
start = 0;
}
String result = strValue.substring(start, strValue.length());
return result;
}
}