mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -41,8 +41,8 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
public SQLBinaryOpExpr(SQLExpr left, SQLExpr right, SQLBinaryOperator operator){
|
||||
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
setLeft(left);
|
||||
setRight(right);
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,9 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
|
||||
public void setValueExpr(SQLExpr valueExpr) {
|
||||
if (valueExpr != null) {
|
||||
valueExpr.setParent(this);
|
||||
}
|
||||
this.valueExpr = valueExpr;
|
||||
}
|
||||
|
||||
@@ -71,6 +74,9 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
|
||||
public void setElseExpr(SQLExpr elseExpr) {
|
||||
if (elseExpr != null) {
|
||||
elseExpr.setParent(this);
|
||||
}
|
||||
this.elseExpr = elseExpr;
|
||||
}
|
||||
|
||||
@@ -78,6 +84,13 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public void addItem(Item item) {
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
this.items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.valueExpr);
|
||||
@@ -99,8 +112,8 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
public Item(SQLExpr conditionExpr, SQLExpr valueExpr){
|
||||
|
||||
this.conditionExpr = conditionExpr;
|
||||
this.valueExpr = valueExpr;
|
||||
setConditionExpr(conditionExpr);
|
||||
setValueExpr(valueExpr);
|
||||
}
|
||||
|
||||
public SQLExpr getConditionExpr() {
|
||||
@@ -108,6 +121,9 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
|
||||
public void setConditionExpr(SQLExpr conditionExpr) {
|
||||
if (conditionExpr != null) {
|
||||
conditionExpr.setParent(this);
|
||||
}
|
||||
this.conditionExpr = conditionExpr;
|
||||
}
|
||||
|
||||
@@ -116,6 +132,9 @@ public class SQLCaseExpr extends SQLExprImpl implements Serializable {
|
||||
}
|
||||
|
||||
public void setValueExpr(SQLExpr valueExpr) {
|
||||
if (valueExpr != null) {
|
||||
valueExpr.setParent(this);
|
||||
}
|
||||
this.valueExpr = valueExpr;
|
||||
}
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ public class SQLExprParser extends SQLParser {
|
||||
accept(Token.THEN);
|
||||
SQLExpr valueExpr = expr();
|
||||
SQLCaseExpr.Item caseItem = new SQLCaseExpr.Item(testExpr, valueExpr);
|
||||
caseExpr.getItems().add(caseItem);
|
||||
caseExpr.addItem(caseItem);
|
||||
|
||||
while (lexer.token() == Token.WHEN) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user