forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresBetweenOperation.java
More file actions
66 lines (55 loc) · 2.61 KB
/
Copy pathPostgresBetweenOperation.java
File metadata and controls
66 lines (55 loc) · 2.61 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
package sqlancer.postgres.ast;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
import sqlancer.postgres.ast.PostgresBinaryComparisonOperation.PostgresBinaryComparisonOperator;
import sqlancer.postgres.ast.PostgresBinaryLogicalOperation.BinaryLogicalOperator;
public final class PostgresBetweenOperation implements PostgresExpression {
private final PostgresExpression expr;
private final PostgresExpression left;
private final PostgresExpression right;
private final boolean isSymmetric;
public PostgresBetweenOperation(PostgresExpression expr, PostgresExpression left, PostgresExpression right,
boolean symmetric) {
this.expr = expr;
this.left = left;
this.right = right;
isSymmetric = symmetric;
}
public PostgresExpression getExpr() {
return expr;
}
public PostgresExpression getLeft() {
return left;
}
public PostgresExpression getRight() {
return right;
}
public boolean isSymmetric() {
return isSymmetric;
}
@Override
public PostgresConstant getExpectedValue() {
PostgresBinaryComparisonOperation leftComparison = new PostgresBinaryComparisonOperation(left, expr,
PostgresBinaryComparisonOperator.LESS_EQUALS);
PostgresBinaryComparisonOperation rightComparison = new PostgresBinaryComparisonOperation(expr, right,
PostgresBinaryComparisonOperator.LESS_EQUALS);
PostgresBinaryLogicalOperation andOperation = new PostgresBinaryLogicalOperation(leftComparison,
rightComparison, PostgresBinaryLogicalOperation.BinaryLogicalOperator.AND);
if (isSymmetric) {
PostgresBinaryComparisonOperation leftComparison2 = new PostgresBinaryComparisonOperation(right, expr,
PostgresBinaryComparisonOperator.LESS_EQUALS);
PostgresBinaryComparisonOperation rightComparison2 = new PostgresBinaryComparisonOperation(expr, left,
PostgresBinaryComparisonOperator.LESS_EQUALS);
PostgresBinaryLogicalOperation andOperation2 = new PostgresBinaryLogicalOperation(leftComparison2,
rightComparison2, PostgresBinaryLogicalOperation.BinaryLogicalOperator.AND);
PostgresBinaryLogicalOperation orOp = new PostgresBinaryLogicalOperation(andOperation, andOperation2,
BinaryLogicalOperator.OR);
return orOp.getExpectedValue();
} else {
return andOperation.getExpectedValue();
}
}
@Override
public PostgresDataType getExpressionType() {
return PostgresDataType.BOOLEAN;
}
}