|
1 | 1 | package sqlancer.sqlite3.oracle.tlp; |
2 | 2 |
|
3 | 3 | import java.sql.SQLException; |
4 | | -import java.util.ArrayList; |
5 | | -import java.util.List; |
6 | 4 |
|
7 | | -import sqlancer.ComparatorHelper; |
8 | | -import sqlancer.Randomly; |
| 5 | +import sqlancer.common.oracle.TLPWhereOracle; |
| 6 | +import sqlancer.common.oracle.TestOracle; |
| 7 | +import sqlancer.common.query.ExpectedErrors; |
| 8 | +import sqlancer.sqlite3.SQLite3Errors; |
9 | 9 | import sqlancer.sqlite3.SQLite3GlobalState; |
10 | | -import sqlancer.sqlite3.SQLite3Visitor; |
| 10 | +import sqlancer.sqlite3.ast.SQLite3Expression; |
| 11 | +import sqlancer.sqlite3.ast.SQLite3Select; |
| 12 | +import sqlancer.sqlite3.gen.SQLite3ExpressionGenerator; |
| 13 | +import sqlancer.sqlite3.schema.SQLite3Schema; |
| 14 | +import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column; |
| 15 | +import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Table; |
11 | 16 |
|
12 | | -public class SQLite3TLPWhereOracle extends SQLite3TLPBase { |
| 17 | +public class SQLite3TLPWhereOracle implements TestOracle<SQLite3GlobalState> { |
13 | 18 |
|
14 | | - private String generatedQueryString; |
| 19 | + private final TLPWhereOracle<SQLite3Select, SQLite3Expression.Join, SQLite3Expression, SQLite3Schema, SQLite3Table, SQLite3Column, SQLite3GlobalState> oracle; |
15 | 20 |
|
16 | 21 | public SQLite3TLPWhereOracle(SQLite3GlobalState state) { |
17 | | - super(state); |
| 22 | + SQLite3ExpressionGenerator gen = new SQLite3ExpressionGenerator(state); |
| 23 | + ExpectedErrors expectedErrors = ExpectedErrors.newErrors().with(SQLite3Errors.getExpectedExpressionErrors()) |
| 24 | + .build(); |
| 25 | + this.oracle = new TLPWhereOracle<>(state, gen, expectedErrors); |
18 | 26 | } |
19 | 27 |
|
20 | 28 | @Override |
21 | 29 | public void check() throws SQLException { |
22 | | - super.check(); |
23 | | - select.setWhereClause(null); |
24 | | - String originalQueryString = SQLite3Visitor.asString(select); |
25 | | - generatedQueryString = originalQueryString; |
26 | | - List<String> resultSet = ComparatorHelper.getResultSetFirstColumnAsString(originalQueryString, errors, state); |
27 | | - |
28 | | - boolean orderBy = Randomly.getBooleanWithSmallProbability(); |
29 | | - if (orderBy) { |
30 | | - select.setOrderByClauses(gen.generateOrderBys()); |
31 | | - } |
32 | | - select.setWhereClause(predicate); |
33 | | - String firstQueryString = SQLite3Visitor.asString(select); |
34 | | - select.setWhereClause(negatedPredicate); |
35 | | - String secondQueryString = SQLite3Visitor.asString(select); |
36 | | - select.setWhereClause(isNullPredicate); |
37 | | - String thirdQueryString = SQLite3Visitor.asString(select); |
38 | | - List<String> combinedString = new ArrayList<>(); |
39 | | - List<String> secondResultSet = ComparatorHelper.getCombinedResultSet(firstQueryString, secondQueryString, |
40 | | - thirdQueryString, combinedString, !orderBy, state, errors); |
41 | | - ComparatorHelper.assumeResultSetsAreEqual(resultSet, secondResultSet, originalQueryString, combinedString, |
42 | | - state); |
| 30 | + oracle.check(); |
43 | 31 | } |
44 | 32 |
|
45 | 33 | @Override |
46 | 34 | public String getLastQueryString() { |
47 | | - return generatedQueryString; |
| 35 | + return oracle.getLastQueryString(); |
48 | 36 | } |
49 | | - |
50 | 37 | } |
0 commit comments