-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMySQLCaseOperator.java
More file actions
48 lines (38 loc) · 1.76 KB
/
MySQLCaseOperator.java
File metadata and controls
48 lines (38 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package sqlancer.mysql.ast;
import java.util.List;
import sqlancer.common.ast.newast.NewCaseOperatorNode;
public class MySQLCaseOperator extends NewCaseOperatorNode<MySQLExpression> implements MySQLExpression {
public MySQLCaseOperator(MySQLExpression switchCondition, List<MySQLExpression> whenExprs,
List<MySQLExpression> thenExprs, MySQLExpression elseExpr) {
super(switchCondition, whenExprs, thenExprs, elseExpr);
}
@Override
public MySQLConstant getExpectedValue() {
int nrConditions = getConditions().size();
MySQLExpression switchCondition = getSwitchCondition();
List<MySQLExpression> whenExprs = getConditions();
List<MySQLExpression> thenExprs = getExpressions();
MySQLExpression elseExpr = getElseExpr();
if (switchCondition != null) {
MySQLConstant switchValue = switchCondition.getExpectedValue();
for (int i = 0; i < nrConditions; i++) {
MySQLConstant whenValue = whenExprs.get(i).getExpectedValue();
MySQLConstant isConditionMatched = switchValue.isEquals(whenValue);
if (!isConditionMatched.isNull() && isConditionMatched.asBooleanNotNull()) {
return thenExprs.get(i).getExpectedValue();
}
}
} else {
for (int i = 0; i < nrConditions; i++) {
MySQLConstant whenValue = whenExprs.get(i).getExpectedValue();
if (!whenValue.isNull() && whenValue.asBooleanNotNull()) {
return thenExprs.get(i).getExpectedValue();
}
}
}
if (elseExpr != null) {
return elseExpr.getExpectedValue();
}
return MySQLConstant.createNullConstant();
}
}