-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMySQLBetweenOperation.java
More file actions
52 lines (42 loc) · 2.11 KB
/
MySQLBetweenOperation.java
File metadata and controls
52 lines (42 loc) · 2.11 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
package sqlancer.mysql.ast;
import sqlancer.IgnoreMeException;
import sqlancer.mysql.ast.MySQLBinaryComparisonOperation.BinaryComparisonOperator;
import sqlancer.mysql.ast.MySQLBinaryLogicalOperation.MySQLBinaryLogicalOperator;
public class MySQLBetweenOperation implements MySQLExpression {
private final MySQLExpression expr;
private final MySQLExpression left;
private final MySQLExpression right;
public MySQLBetweenOperation(MySQLExpression expr, MySQLExpression left, MySQLExpression right) {
this.expr = expr;
this.left = left;
this.right = right;
}
public MySQLExpression getExpr() {
return expr;
}
public MySQLExpression getLeft() {
return left;
}
public MySQLExpression getRight() {
return right;
}
@Override
public MySQLConstant getExpectedValue() {
MySQLExpression[] arr = { left, right, expr };
MySQLConstant convertedExpr = MySQLComputableFunction.castToMostGeneralType(expr.getExpectedValue(), arr);
MySQLConstant convertedLeft = MySQLComputableFunction.castToMostGeneralType(left.getExpectedValue(), arr);
MySQLConstant convertedRight = MySQLComputableFunction.castToMostGeneralType(right.getExpectedValue(), arr);
/* workaround for https://bugs.mysql.com/bug.php?id=96006 */
if (convertedLeft.isInt() && convertedLeft.getInt() < 0 || convertedRight.isInt() && convertedRight.getInt() < 0
|| convertedExpr.isInt() && convertedExpr.getInt() < 0) {
throw new IgnoreMeException();
}
MySQLBinaryComparisonOperation leftComparison = new MySQLBinaryComparisonOperation(convertedLeft, convertedExpr,
BinaryComparisonOperator.LESS_EQUALS);
MySQLBinaryComparisonOperation rightComparison = new MySQLBinaryComparisonOperation(convertedExpr,
convertedRight, BinaryComparisonOperator.LESS_EQUALS);
MySQLBinaryLogicalOperation andOperation = new MySQLBinaryLogicalOperation(leftComparison, rightComparison,
MySQLBinaryLogicalOperator.AND);
return andOperation.getExpectedValue();
}
}