-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMySQLOracleFactory.java
More file actions
79 lines (67 loc) · 2.86 KB
/
MySQLOracleFactory.java
File metadata and controls
79 lines (67 loc) · 2.86 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
72
73
74
75
76
77
78
79
package sqlancer.mysql;
import java.sql.SQLException;
import java.util.Optional;
import sqlancer.OracleFactory;
import sqlancer.common.oracle.CERTOracle;
import sqlancer.common.oracle.TLPWhereOracle;
import sqlancer.common.oracle.TestOracle;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLancerResultSet;
import sqlancer.mysql.gen.MySQLExpressionGenerator;
import sqlancer.mysql.oracle.MySQLDQPOracle;
import sqlancer.mysql.oracle.MySQLFuzzer;
import sqlancer.mysql.oracle.MySQLPivotedQuerySynthesisOracle;
public enum MySQLOracleFactory implements OracleFactory<MySQLGlobalState> {
TLP_WHERE {
@Override
public TestOracle<MySQLGlobalState> create(MySQLGlobalState globalState) throws SQLException {
MySQLExpressionGenerator gen = new MySQLExpressionGenerator(globalState);
ExpectedErrors expectedErrors = ExpectedErrors.newErrors().with(MySQLErrors.getExpressionErrors())
.withRegex(MySQLErrors.getExpressionRegexErrors()).build();
return new TLPWhereOracle<>(globalState, gen, expectedErrors);
}
},
PQS {
@Override
public TestOracle<MySQLGlobalState> create(MySQLGlobalState globalState) throws SQLException {
return new MySQLPivotedQuerySynthesisOracle(globalState);
}
@Override
public boolean requiresAllTablesToContainRows() {
return true;
}
},
CERT {
@Override
public TestOracle<MySQLGlobalState> create(MySQLGlobalState globalState) throws SQLException {
MySQLExpressionGenerator gen = new MySQLExpressionGenerator(globalState);
ExpectedErrors expectedErrors = ExpectedErrors.newErrors().with(MySQLErrors.getExpressionErrors())
.withRegex(MySQLErrors.getExpressionRegexErrors()).build();
CERTOracle.CheckedFunction<SQLancerResultSet, Optional<Long>> rowCountParser = (rs) -> {
int rowCount = rs.getInt(10);
return Optional.of((long) rowCount);
};
CERTOracle.CheckedFunction<SQLancerResultSet, Optional<String>> queryPlanParser = (rs) -> {
String operation = rs.getString(2);
return Optional.of(operation);
};
return new CERTOracle<>(globalState, gen, expectedErrors, rowCountParser, queryPlanParser);
}
@Override
public boolean requiresAllTablesToContainRows() {
return true;
}
},
FUZZER {
@Override
public TestOracle<MySQLGlobalState> create(MySQLGlobalState globalState) throws Exception {
return new MySQLFuzzer(globalState);
}
},
DQP {
@Override
public TestOracle<MySQLGlobalState> create(MySQLGlobalState globalState) throws SQLException {
return new MySQLDQPOracle(globalState);
}
};
}