All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sqlancer.h2.H2QueryPartitioningBase Maven / Gradle / Ivy

Go to download

SQLancer finds logic bugs in Database Management Systems through automatic testing

There is a newer version: 2.0.0
Show newest version
package sqlancer.h2;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import sqlancer.common.ast.newast.ColumnReferenceNode;
import sqlancer.common.ast.newast.Node;
import sqlancer.common.ast.newast.TableReferenceNode;
import sqlancer.common.gen.ExpressionGenerator;
import sqlancer.common.oracle.TernaryLogicPartitioningOracleBase;
import sqlancer.common.oracle.TestOracle;
import sqlancer.h2.H2Provider.H2GlobalState;
import sqlancer.h2.H2Schema.H2Column;
import sqlancer.h2.H2Schema.H2Table;
import sqlancer.h2.H2Schema.H2Tables;

public class H2QueryPartitioningBase extends TernaryLogicPartitioningOracleBase, H2GlobalState>
        implements TestOracle {

    H2Schema s;
    H2Tables targetTables;
    H2ExpressionGenerator gen;
    H2Select select;

    public H2QueryPartitioningBase(H2GlobalState state) {
        super(state);
        H2Errors.addExpressionErrors(errors);
    }

    @Override
    public void check() throws SQLException {
        s = state.getSchema();
        targetTables = s.getRandomTableNonEmptyTables();
        gen = new H2ExpressionGenerator(state).setColumns(targetTables.getColumns());
        initializeTernaryPredicateVariants();
        select = new H2Select();
        select.setFetchColumns(generateFetchColumns());
        List tables = targetTables.getTables();
        List> tableList = tables.stream()
                .map(t -> new TableReferenceNode(t)).collect(Collectors.toList());
        List> joins = H2Join.getJoins(tableList, state);
        select.setJoinList(joins.stream().collect(Collectors.toList()));
        select.setFromList(tableList.stream().collect(Collectors.toList()));
        select.setWhereClause(null);
    }

    List> generateFetchColumns() {
        List> columns = new ArrayList<>();
        columns.add(new ColumnReferenceNode<>(new H2Column("*", null)));
        return columns;
    }

    @Override
    protected ExpressionGenerator> getGen() {
        return gen;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy