Skip to content

Commit 933e813

Browse files
committed
[SQLite] Add a GROUP BY tester
1 parent a4d8a90 commit 933e813

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/sqlancer/sqlite3/SQLite3Options.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sqlancer.sqlite3.queries.SQLite3PivotedQuerySynthesizer;
1818
import sqlancer.sqlite3.queries.SQLite3QueryPartitioningAggregateTester;
1919
import sqlancer.sqlite3.queries.SQLite3QueryPartitioningDistinctTester;
20+
import sqlancer.sqlite3.queries.SQLite3QueryPartitioningGroupByTester;
2021
import sqlancer.sqlite3.queries.SQLite3QueryPartitioningHavingTester;
2122
import sqlancer.sqlite3.queries.SQLite3QueryPartitioningWhereTester;
2223

@@ -104,6 +105,12 @@ public TestOracle create(SQLite3GlobalState globalState) throws SQLException {
104105
return new SQLite3QueryPartitioningDistinctTester(globalState);
105106
}
106107
},
108+
GROUP_BY {
109+
@Override
110+
public TestOracle create(SQLite3GlobalState globalState) throws SQLException {
111+
return new SQLite3QueryPartitioningGroupByTester(globalState);
112+
}
113+
},
107114
HAVING() {
108115
@Override
109116
public TestOracle create(SQLite3GlobalState globalState) throws SQLException {
@@ -114,8 +121,11 @@ public TestOracle create(SQLite3GlobalState globalState) throws SQLException {
114121
@Override
115122
public TestOracle create(SQLite3GlobalState globalState) throws SQLException {
116123
List<TestOracle> oracles = new ArrayList<>();
117-
oracles.add(new SQLite3QueryPartitioningAggregateTester(globalState));
124+
oracles.add(new SQLite3QueryPartitioningWhereTester(globalState));
125+
oracles.add(new SQLite3QueryPartitioningDistinctTester(globalState));
126+
oracles.add(new SQLite3QueryPartitioningGroupByTester(globalState));
118127
oracles.add(new SQLite3QueryPartitioningHavingTester(globalState));
128+
oracles.add(new SQLite3QueryPartitioningAggregateTester(globalState));
119129
return new CompositeTestOracle(oracles);
120130
}
121131
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package sqlancer.sqlite3.queries;
2+
3+
import java.sql.SQLException;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
import sqlancer.DatabaseProvider;
9+
import sqlancer.Randomly;
10+
import sqlancer.TestOracle;
11+
import sqlancer.sqlite3.SQLite3Provider.SQLite3GlobalState;
12+
import sqlancer.sqlite3.SQLite3Visitor;
13+
import sqlancer.sqlite3.ast.SQLite3Expression;
14+
import sqlancer.sqlite3.ast.SQLite3Expression.SQLite3ColumnName;
15+
16+
public class SQLite3QueryPartitioningGroupByTester extends SQLite3QueryPartitioningBase {
17+
18+
public SQLite3QueryPartitioningGroupByTester(SQLite3GlobalState state) {
19+
super(state);
20+
}
21+
22+
@Override
23+
public void check() throws SQLException {
24+
super.check();
25+
select.setGroupByClause(select.getFetchColumns());
26+
select.setWhereClause(null);
27+
String originalQueryString = SQLite3Visitor.asString(select);
28+
29+
List<String> resultSet = DatabaseProvider.getResultSetFirstColumnAsString(originalQueryString, errors,
30+
state.getConnection(), state);
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 = TestOracle.getCombinedResultSetNoDuplicates(firstQueryString, secondQueryString,
40+
thirdQueryString, combinedString, true, state, errors);
41+
TestOracle.assumeResultSetsAreEqual(resultSet, secondResultSet, originalQueryString, combinedString, state);
42+
}
43+
44+
List<SQLite3Expression> generateFetchColumns() {
45+
List<SQLite3Expression> columns = new ArrayList<>();
46+
columns = Randomly.nonEmptySubset(targetTables.getColumns()).stream().map(c -> new SQLite3ColumnName(c, null))
47+
.collect(Collectors.toList());
48+
return columns;
49+
}
50+
51+
}

0 commit comments

Comments
 (0)