forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresInOperation.java
More file actions
65 lines (54 loc) · 1.92 KB
/
PostgresInOperation.java
File metadata and controls
65 lines (54 loc) · 1.92 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
package sqlancer.postgres.ast;
import java.util.List;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
public class PostgresInOperation implements PostgresExpression {
private final PostgresExpression expr;
private final List<PostgresExpression> listElements;
private final boolean isTrue;
public PostgresInOperation(PostgresExpression expr, List<PostgresExpression> listElements, boolean isTrue) {
this.expr = expr;
this.listElements = listElements;
this.isTrue = isTrue;
}
public PostgresExpression getExpr() {
return expr;
}
public List<PostgresExpression> getListElements() {
return listElements;
}
@Override
public PostgresConstant getExpectedValue() {
PostgresConstant leftValue = expr.getExpectedValue();
if (leftValue == null) {
return null;
}
if (leftValue.isNull()) {
return PostgresConstant.createNullConstant();
}
boolean isNull = false;
for (PostgresExpression expr : getListElements()) {
PostgresConstant rightExpectedValue = expr.getExpectedValue();
if (rightExpectedValue == null) {
return null;
}
if (rightExpectedValue.isNull()) {
isNull = true;
} else if (rightExpectedValue.isEquals(this.expr.getExpectedValue()).isBoolean()
&& rightExpectedValue.isEquals(this.expr.getExpectedValue()).asBoolean()) {
return PostgresConstant.createBooleanConstant(isTrue);
}
}
if (isNull) {
return PostgresConstant.createNullConstant();
} else {
return PostgresConstant.createBooleanConstant(!isTrue);
}
}
public boolean isTrue() {
return isTrue;
}
@Override
public PostgresDataType getExpressionType() {
return PostgresDataType.BOOLEAN;
}
}