|
1 | 1 | package sqlancer.mysql.oracle; |
2 | 2 |
|
3 | 3 | import java.sql.SQLException; |
4 | | -import java.util.ArrayList; |
5 | | -import java.util.Collections; |
6 | | -import java.util.List; |
7 | 4 |
|
8 | | -import sqlancer.ComparatorHelper; |
9 | | -import sqlancer.Randomly; |
| 5 | +import sqlancer.Reproducer; |
| 6 | +import sqlancer.common.oracle.TLPWhereOracle; |
| 7 | +import sqlancer.common.oracle.TestOracle; |
| 8 | +import sqlancer.common.query.ExpectedErrors; |
| 9 | +import sqlancer.mysql.MySQLErrors; |
10 | 10 | import sqlancer.mysql.MySQLGlobalState; |
11 | | -import sqlancer.mysql.MySQLVisitor; |
| 11 | +import sqlancer.mysql.MySQLSchema; |
| 12 | +import sqlancer.mysql.MySQLSchema.MySQLColumn; |
| 13 | +import sqlancer.mysql.MySQLSchema.MySQLTable; |
| 14 | +import sqlancer.mysql.ast.MySQLExpression; |
| 15 | +import sqlancer.mysql.ast.MySQLJoin; |
| 16 | +import sqlancer.mysql.ast.MySQLSelect; |
| 17 | +import sqlancer.mysql.gen.MySQLExpressionGenerator; |
12 | 18 |
|
13 | | -public class MySQLTLPWhereOracle extends MySQLQueryPartitioningBase { |
| 19 | +public class MySQLTLPWhereOracle implements TestOracle<MySQLGlobalState> { |
| 20 | + |
| 21 | + private final TLPWhereOracle<MySQLSelect, MySQLJoin, MySQLExpression, MySQLSchema, MySQLTable, MySQLColumn, MySQLGlobalState> oracle; |
14 | 22 |
|
15 | 23 | public MySQLTLPWhereOracle(MySQLGlobalState state) { |
16 | | - super(state); |
| 24 | + MySQLExpressionGenerator gen = new MySQLExpressionGenerator(state); |
| 25 | + ExpectedErrors expectedErrors = ExpectedErrors.newErrors().with(MySQLErrors.getExpressionErrors()) |
| 26 | + .withRegex(MySQLErrors.getExpressionRegexErrors()).build(); |
| 27 | + |
| 28 | + this.oracle = new TLPWhereOracle<>(state, gen, expectedErrors); |
17 | 29 | } |
18 | 30 |
|
19 | 31 | @Override |
20 | 32 | public void check() throws SQLException { |
21 | | - super.check(); |
22 | | - select.setWhereClause(null); |
23 | | - String originalQueryString = MySQLVisitor.asString(select); |
24 | | - |
25 | | - List<String> resultSet = ComparatorHelper.getResultSetFirstColumnAsString(originalQueryString, errors, state); |
26 | | - |
27 | | - if (Randomly.getBoolean()) { |
28 | | - select.setOrderByClauses(gen.generateOrderBys()); |
29 | | - } |
30 | | - select.setOrderByClauses(Collections.emptyList()); |
31 | | - select.setWhereClause(predicate); |
32 | | - String firstQueryString = MySQLVisitor.asString(select); |
33 | | - select.setWhereClause(negatedPredicate); |
34 | | - String secondQueryString = MySQLVisitor.asString(select); |
35 | | - select.setWhereClause(isNullPredicate); |
36 | | - String thirdQueryString = MySQLVisitor.asString(select); |
37 | | - List<String> combinedString = new ArrayList<>(); |
38 | | - List<String> secondResultSet = ComparatorHelper.getCombinedResultSet(firstQueryString, secondQueryString, |
39 | | - thirdQueryString, combinedString, Randomly.getBoolean(), state, errors); |
40 | | - ComparatorHelper.assumeResultSetsAreEqual(resultSet, secondResultSet, originalQueryString, combinedString, |
41 | | - state); |
| 33 | + oracle.check(); |
42 | 34 | } |
43 | 35 |
|
| 36 | + @Override |
| 37 | + public String getLastQueryString() { |
| 38 | + return oracle.getLastQueryString(); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public Reproducer<MySQLGlobalState> getLastReproducer() { |
| 43 | + return oracle.getLastReproducer(); |
| 44 | + } |
44 | 45 | } |
0 commit comments