sqlancer.postgres.oracle.tlp.PostgresTLPHavingOracle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlancer Show documentation
Show all versions of sqlancer Show documentation
SQLancer finds logic bugs in Database Management Systems through automatic testing
package sqlancer.postgres.oracle.tlp;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import sqlancer.ComparatorHelper;
import sqlancer.Randomly;
import sqlancer.postgres.PostgresGlobalState;
import sqlancer.postgres.PostgresSchema.PostgresDataType;
import sqlancer.postgres.PostgresVisitor;
import sqlancer.postgres.ast.PostgresExpression;
import sqlancer.postgres.gen.PostgresCommon;
public class PostgresTLPHavingOracle extends PostgresTLPBase {
public PostgresTLPHavingOracle(PostgresGlobalState state) {
super(state);
PostgresCommon.addGroupingErrors(errors);
}
@Override
public void check() throws SQLException {
super.check();
havingCheck();
}
protected void havingCheck() throws SQLException {
if (Randomly.getBoolean()) {
select.setWhereClause(gen.generateExpression(PostgresDataType.BOOLEAN));
}
select.setGroupByExpressions(gen.generateExpressions(Randomly.smallNumber() + 1));
select.setHavingClause(null);
String originalQueryString = PostgresVisitor.asString(select);
List resultSet = ComparatorHelper.getResultSetFirstColumnAsString(originalQueryString, errors, state);
boolean orderBy = Randomly.getBoolean();
if (orderBy) {
select.setOrderByExpressions(gen.generateOrderBy());
}
select.setHavingClause(predicate);
String firstQueryString = PostgresVisitor.asString(select);
select.setHavingClause(negatedPredicate);
String secondQueryString = PostgresVisitor.asString(select);
select.setHavingClause(isNullPredicate);
String thirdQueryString = PostgresVisitor.asString(select);
List combinedString = new ArrayList<>();
List secondResultSet = ComparatorHelper.getCombinedResultSet(firstQueryString, secondQueryString,
thirdQueryString, combinedString, !orderBy, state, errors);
ComparatorHelper.assumeResultSetsAreEqual(resultSet, secondResultSet, originalQueryString, combinedString,
state);
}
@Override
protected PostgresExpression generatePredicate() {
return gen.generateHavingClause();
}
@Override
List generateFetchColumns() {
List expressions = gen.allowAggregates(true)
.generateExpressions(Randomly.smallNumber() + 1);
gen.allowAggregates(false);
return expressions;
}
}