-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMySQLInOperation.java
More file actions
71 lines (59 loc) · 2.09 KB
/
MySQLInOperation.java
File metadata and controls
71 lines (59 loc) · 2.09 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sqlancer.mysql.ast;
import java.util.List;
import sqlancer.IgnoreMeException;
/**
* @see <a href="https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_in">Comparison Functions and
* Operators</a>
*/
public class MySQLInOperation implements MySQLExpression {
private final MySQLExpression expr;
private final List<MySQLExpression> listElements;
private final boolean isTrue;
public MySQLInOperation(MySQLExpression expr, List<MySQLExpression> listElements, boolean isTrue) {
this.expr = expr;
this.listElements = listElements;
this.isTrue = isTrue;
}
public MySQLExpression getExpr() {
return expr;
}
public List<MySQLExpression> getListElements() {
return listElements;
}
@Override
public MySQLConstant getExpectedValue() {
MySQLConstant leftVal = expr.getExpectedValue();
if (leftVal.isNull()) {
return MySQLConstant.createNullConstant();
}
/* workaround for https://bugs.mysql.com/bug.php?id=95957 */
if (leftVal.isInt() && !leftVal.isSigned()) {
throw new IgnoreMeException();
}
boolean isNull = false;
for (MySQLExpression rightExpr : listElements) {
MySQLConstant rightVal = rightExpr.getExpectedValue();
/* workaround for https://bugs.mysql.com/bug.php?id=95957 */
if (rightVal.isInt() && !rightVal.isSigned()) {
throw new IgnoreMeException();
}
MySQLConstant convertedRightVal = rightVal;
MySQLConstant isEquals = leftVal.isEquals(convertedRightVal);
if (isEquals.isNull()) {
isNull = true;
} else {
if (isEquals.getInt() == 1) {
return MySQLConstant.createBoolean(isTrue);
}
}
}
if (isNull) {
return MySQLConstant.createNullConstant();
} else {
return MySQLConstant.createBoolean(!isTrue);
}
}
public boolean isTrue() {
return isTrue;
}
}