forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgresLikeOperation.java
More file actions
38 lines (31 loc) · 1.18 KB
/
PostgresLikeOperation.java
File metadata and controls
38 lines (31 loc) · 1.18 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
package sqlancer.postgres.ast;
import sqlancer.LikeImplementationHelper;
import sqlancer.common.ast.BinaryNode;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
public class PostgresLikeOperation extends BinaryNode<PostgresExpression> implements PostgresExpression {
public PostgresLikeOperation(PostgresExpression left, PostgresExpression right) {
super(left, right);
}
@Override
public PostgresDataType getExpressionType() {
return PostgresDataType.BOOLEAN;
}
@Override
public PostgresConstant getExpectedValue() {
PostgresConstant leftVal = getLeft().getExpectedValue();
PostgresConstant rightVal = getRight().getExpectedValue();
if (leftVal == null || rightVal == null) {
return null;
}
if (leftVal.isNull() || rightVal.isNull()) {
return PostgresConstant.createNullConstant();
} else {
boolean val = LikeImplementationHelper.match(leftVal.asString(), rightVal.asString(), 0, 0, true);
return PostgresConstant.createBooleanConstant(val);
}
}
@Override
public String getOperatorRepresentation() {
return "LIKE";
}
}