Skip to content

Commit f059fa7

Browse files
committed
Remove the StateToReproduce subclasses
1 parent 20e4900 commit f059fa7

9 files changed

Lines changed: 9 additions & 159 deletions

src/sqlancer/StateToReproduce.java

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@
44
import java.util.ArrayList;
55
import java.util.Collections;
66
import java.util.List;
7-
import java.util.Map;
87

9-
import sqlancer.clickhouse.ClickHouseSchema;
10-
import sqlancer.clickhouse.ast.ClickHouseConstant;
11-
import sqlancer.clickhouse.ast.ClickHouseExpression;
128
import sqlancer.common.query.Query;
139
import sqlancer.common.query.QueryAdapter;
14-
import sqlancer.mysql.MySQLSchema.MySQLColumn;
15-
import sqlancer.mysql.ast.MySQLConstant;
16-
import sqlancer.mysql.ast.MySQLExpression;
17-
import sqlancer.postgres.PostgresSchema.PostgresColumn;
18-
import sqlancer.postgres.ast.PostgresConstant;
19-
import sqlancer.postgres.ast.PostgresExpression;
20-
import sqlancer.sqlite3.ast.SQLite3Constant;
21-
import sqlancer.sqlite3.ast.SQLite3Expression;
22-
import sqlancer.sqlite3.schema.SQLite3Schema.SQLite3Column;
2310

2411
public class StateToReproduce {
2512

@@ -101,91 +88,6 @@ public OracleRunReproductionState getLocalState() {
10188
return localState;
10289
}
10390

104-
public static class MySQLStateToReproduce extends StateToReproduce {
105-
106-
public Map<MySQLColumn, MySQLConstant> randomRowValues;
107-
108-
public MySQLExpression whereClause;
109-
110-
public String queryThatSelectsRow;
111-
112-
public MySQLStateToReproduce(String databaseName) {
113-
super(databaseName);
114-
}
115-
116-
public Map<MySQLColumn, MySQLConstant> getRandomRowValues() {
117-
return randomRowValues;
118-
}
119-
120-
public MySQLExpression getWhereClause() {
121-
return whereClause;
122-
}
123-
124-
}
125-
126-
public static class SQLite3StateToReproduce extends StateToReproduce {
127-
public Map<SQLite3Column, SQLite3Constant> randomRowValues;
128-
129-
public SQLite3Expression whereClause;
130-
131-
public SQLite3StateToReproduce(String databaseName) {
132-
super(databaseName);
133-
}
134-
135-
public Map<SQLite3Column, SQLite3Constant> getRandomRowValues() {
136-
return randomRowValues;
137-
}
138-
139-
public SQLite3Expression getWhereClause() {
140-
return whereClause;
141-
}
142-
143-
}
144-
145-
public static class PostgresStateToReproduce extends StateToReproduce {
146-
147-
public Map<PostgresColumn, PostgresConstant> randomRowValues;
148-
149-
public PostgresExpression whereClause;
150-
151-
public String queryThatSelectsRow;
152-
153-
public PostgresStateToReproduce(String databaseName) {
154-
super(databaseName);
155-
}
156-
157-
public Map<PostgresColumn, PostgresConstant> getRandomRowValues() {
158-
return randomRowValues;
159-
}
160-
161-
public PostgresExpression getWhereClause() {
162-
return whereClause;
163-
}
164-
165-
}
166-
167-
public static class ClickHouseStateToReproduce extends StateToReproduce {
168-
169-
public Map<ClickHouseSchema.ClickHouseColumn, ClickHouseConstant> randomRowValues;
170-
171-
public ClickHouseExpression whereClause;
172-
173-
public String queryThatSelectsRow;
174-
175-
public ClickHouseStateToReproduce(String databaseName) {
176-
super(databaseName);
177-
}
178-
179-
public Map<ClickHouseSchema.ClickHouseColumn, ClickHouseConstant> getRandomRowValues() {
180-
return randomRowValues;
181-
}
182-
183-
public ClickHouseExpression getWhereClause() {
184-
return whereClause;
185-
}
186-
187-
}
188-
18991
/**
19092
* State information that is logged if the test oracle finds a bug or if an exception is thrown.
19193
*/

src/sqlancer/mysql/MySQLProvider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import sqlancer.IgnoreMeException;
1111
import sqlancer.ProviderAdapter;
1212
import sqlancer.Randomly;
13-
import sqlancer.StateToReproduce;
14-
import sqlancer.StateToReproduce.MySQLStateToReproduce;
1513
import sqlancer.StatementExecutor;
1614
import sqlancer.common.query.Query;
1715
import sqlancer.common.query.QueryAdapter;
@@ -187,9 +185,4 @@ public String getDBMSName() {
187185
return "mysql";
188186
}
189187

190-
@Override
191-
public StateToReproduce getStateToReproduce(String databaseName) {
192-
return new MySQLStateToReproduce(databaseName);
193-
}
194-
195188
}

src/sqlancer/mysql/MySQLSchema.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.stream.Stream;
1313

1414
import sqlancer.Randomly;
15-
import sqlancer.StateToReproduce.MySQLStateToReproduce;
1615
import sqlancer.common.schema.AbstractRowValue;
1716
import sqlancer.common.schema.AbstractSchema;
1817
import sqlancer.common.schema.AbstractTable;
@@ -85,7 +84,7 @@ public MySQLTables(List<MySQLTable> tables) {
8584
super(tables);
8685
}
8786

88-
public MySQLRowValue getRandomRowValue(Connection con, MySQLStateToReproduce state) throws SQLException {
87+
public MySQLRowValue getRandomRowValue(Connection con) throws SQLException {
8988
String randomRow = String.format("SELECT %s FROM %s ORDER BY RAND() LIMIT 1", columnNamesAsString(
9089
c -> c.getTable().getName() + "." + c.getName() + " AS " + c.getTable().getName() + c.getName()),
9190
// columnNamesAsString(c -> "typeof(" + c.getTable().getName() + "." +
@@ -95,7 +94,7 @@ public MySQLRowValue getRandomRowValue(Connection con, MySQLStateToReproduce sta
9594
try (Statement s = con.createStatement()) {
9695
ResultSet randomRowValues = s.executeQuery(randomRow);
9796
if (!randomRowValues.next()) {
98-
throw new AssertionError("could not find random row! " + randomRow + "\n" + state);
97+
throw new AssertionError("could not find random row! " + randomRow + "\n");
9998
}
10099
for (int i = 0; i < getColumns().size(); i++) {
101100
MySQLColumn column = getColumns().get(i);
@@ -135,7 +134,6 @@ public MySQLRowValue getRandomRowValue(Connection con, MySQLStateToReproduce sta
135134
values.put(column, constant);
136135
}
137136
assert !randomRowValues.next();
138-
state.randomRowValues = values;
139137
return new MySQLRowValue(this, values);
140138
}
141139

src/sqlancer/mysql/oracle/MySQLPivotedQuerySynthesisOracle.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.stream.Collectors;
99

1010
import sqlancer.Randomly;
11-
import sqlancer.StateToReproduce.MySQLStateToReproduce;
1211
import sqlancer.common.oracle.PivotedQuerySynthesisBase;
1312
import sqlancer.mysql.MySQLGlobalState;
1413
import sqlancer.mysql.MySQLSchema.MySQLColumn;
@@ -30,13 +29,11 @@
3029
public class MySQLPivotedQuerySynthesisOracle
3130
extends PivotedQuerySynthesisBase<MySQLGlobalState, MySQLRowValue, MySQLExpression> {
3231

33-
private final MySQLStateToReproduce state;
3432
private List<MySQLExpression> fetchColumns;
3533
private List<MySQLColumn> columns;
3634

3735
public MySQLPivotedQuerySynthesisOracle(MySQLGlobalState globalState) throws SQLException {
3836
super(globalState);
39-
this.state = (MySQLStateToReproduce) globalState.getState();
4037
}
4138

4239
@Override
@@ -60,18 +57,15 @@ public String getQueryThatContainsAtLeastOneRow() throws SQLException {
6057
MySQLTables randomFromTables = globalState.getSchema().getRandomTableNonEmptyTables();
6158
List<MySQLTable> tables = randomFromTables.getTables();
6259

63-
state.queryTargetedTablesString = randomFromTables.tableNamesAsString();
64-
6560
MySQLSelect selectStatement = new MySQLSelect();
6661
selectStatement.setSelectType(Randomly.fromOptions(MySQLSelect.SelectType.values()));
67-
state.whereClause = selectStatement;
6862
columns = randomFromTables.getColumns();
6963
// for (MySQLTable t : tables) {
7064
// if (t.getRowid() != null) {
7165
// columns.add(t.getRowid());
7266
// }
7367
// }
74-
pivotRow = randomFromTables.getRandomRowValue(globalState.getConnection(), state);
68+
pivotRow = randomFromTables.getRandomRowValue(globalState.getConnection());
7569

7670
// List<Join> joinStatements = new ArrayList<>();
7771
// for (int i = 1; i < tables.size(); i++) {
@@ -94,11 +88,8 @@ public String getQueryThatContainsAtLeastOneRow() throws SQLException {
9488

9589
fetchColumns = columns.stream().map(c -> new MySQLColumnReference(c, null)).collect(Collectors.toList());
9690
selectStatement.setFetchColumns(fetchColumns);
97-
state.queryTargetedColumnsString = columns.stream().map(c -> c.getFullQualifiedName())
98-
.collect(Collectors.joining(", "));
9991
MySQLExpression whereClause = generateWhereClauseThatContainsRowValue(columns, pivotRow);
10092
selectStatement.setWhereClause(whereClause);
101-
state.whereClause = selectStatement;
10293
List<MySQLExpression> groupByClause = generateGroupByClause(columns, pivotRow);
10394
selectStatement.setGroupByExpressions(groupByClause);
10495
MySQLExpression limitClause = generateLimit();
@@ -134,7 +125,6 @@ public String getQueryThatContainsAtLeastOneRow() throws SQLException {
134125
}
135126
}
136127
sb2.append(") as result;");
137-
state.queryThatSelectsRow = sb2.toString();
138128

139129
MySQLToStringVisitor visitor = new MySQLToStringVisitor();
140130
visitor.visit(selectStatement);
@@ -204,7 +194,6 @@ private boolean isContainedIn(String queryString) throws SQLException {
204194
}
205195

206196
String resultingQueryString = sb.toString();
207-
state.getLocalState().log(resultingQueryString);
208197
if (globalState.getOptions().logEachSelect()) {
209198
globalState.getLogger().writeCurrent(resultingQueryString);
210199
}

src/sqlancer/postgres/PostgresProvider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import sqlancer.IgnoreMeException;
1313
import sqlancer.ProviderAdapter;
1414
import sqlancer.Randomly;
15-
import sqlancer.StateToReproduce;
16-
import sqlancer.StateToReproduce.PostgresStateToReproduce;
1715
import sqlancer.StatementExecutor;
1816
import sqlancer.common.query.Query;
1917
import sqlancer.common.query.QueryAdapter;
@@ -315,9 +313,4 @@ public String getDBMSName() {
315313
return "postgres";
316314
}
317315

318-
@Override
319-
public StateToReproduce getStateToReproduce(String databaseName) {
320-
return new PostgresStateToReproduce(databaseName);
321-
}
322-
323316
}

src/sqlancer/postgres/PostgresSchema.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import sqlancer.IgnoreMeException;
1818
import sqlancer.Randomly;
19-
import sqlancer.StateToReproduce.PostgresStateToReproduce;
2019
import sqlancer.common.schema.AbstractRowValue;
2120
import sqlancer.common.schema.AbstractTable;
2221
import sqlancer.common.schema.AbstractTableColumn;
@@ -63,7 +62,7 @@ public PostgresTables(List<PostgresTable> tables) {
6362
super(tables);
6463
}
6564

66-
public PostgresRowValue getRandomRowValue(Connection con, PostgresStateToReproduce state) throws SQLException {
65+
public PostgresRowValue getRandomRowValue(Connection con) throws SQLException {
6766
String randomRow = String.format("SELECT %s FROM %s ORDER BY RANDOM() LIMIT 1", columnNamesAsString(
6867
c -> c.getTable().getName() + "." + c.getName() + " AS " + c.getTable().getName() + c.getName()),
6968
// columnNamesAsString(c -> "typeof(" + c.getTable().getName() + "." +
@@ -73,7 +72,7 @@ public PostgresRowValue getRandomRowValue(Connection con, PostgresStateToReprodu
7372
try (Statement s = con.createStatement()) {
7473
ResultSet randomRowValues = s.executeQuery(randomRow);
7574
if (!randomRowValues.next()) {
76-
throw new AssertionError("could not find random row! " + randomRow + "\n" + state);
75+
throw new AssertionError("could not find random row! " + randomRow + "\n");
7776
}
7877
for (int i = 0; i < getColumns().size(); i++) {
7978
PostgresColumn column = getColumns().get(i);
@@ -100,7 +99,6 @@ public PostgresRowValue getRandomRowValue(Connection con, PostgresStateToReprodu
10099
values.put(column, constant);
101100
}
102101
assert !randomRowValues.next();
103-
state.randomRowValues = values;
104102
return new PostgresRowValue(this, values);
105103
}
106104

src/sqlancer/postgres/oracle/PostgresPivotedQuerySynthesisOracle.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import sqlancer.Main.StateLogger;
1313
import sqlancer.MainOptions;
1414
import sqlancer.Randomly;
15-
import sqlancer.StateToReproduce.PostgresStateToReproduce;
1615
import sqlancer.common.oracle.PivotedQuerySynthesisBase;
1716
import sqlancer.postgres.PostgresGlobalState;
1817
import sqlancer.postgres.PostgresSchema.PostgresColumn;
@@ -29,7 +28,6 @@
2928
public class PostgresPivotedQuerySynthesisOracle
3029
extends PivotedQuerySynthesisBase<PostgresGlobalState, PostgresRowValue, PostgresExpression> {
3130

32-
private PostgresStateToReproduce state;
3331
private List<PostgresColumn> fetchColumns;
3432
private final MainOptions options;
3533
private final StateLogger logger;
@@ -42,8 +40,8 @@ public PostgresPivotedQuerySynthesisOracle(PostgresGlobalState globalState) thro
4240

4341
@Override
4442
public void check() throws SQLException {
45-
String queryString = getQueryThatContainsAtLeastOneRow(state);
46-
state.getLocalState().log(queryString);
43+
String queryString = getQueryThatContainsAtLeastOneRow();
44+
globalState.getState().getLocalState().log(queryString);
4745
if (options.logEachSelect()) {
4846
logger.writeCurrent(queryString);
4947
}
@@ -56,27 +54,21 @@ public void check() throws SQLException {
5654

5755
}
5856

59-
public String getQueryThatContainsAtLeastOneRow(PostgresStateToReproduce state) throws SQLException {
60-
this.state = state;
57+
public String getQueryThatContainsAtLeastOneRow() throws SQLException {
6158
PostgresTables randomFromTables = globalState.getSchema().getRandomTableNonEmptyTables();
6259

63-
state.queryTargetedTablesString = randomFromTables.tableNamesAsString();
64-
6560
PostgresSelect selectStatement = new PostgresSelect();
6661
selectStatement.setSelectType(Randomly.fromOptions(PostgresSelect.SelectType.values()));
6762
List<PostgresColumn> columns = randomFromTables.getColumns();
68-
pivotRow = randomFromTables.getRandomRowValue(globalState.getConnection(), state);
63+
pivotRow = randomFromTables.getRandomRowValue(globalState.getConnection());
6964

7065
fetchColumns = columns;
7166
selectStatement.setFromList(randomFromTables.getTables().stream().map(t -> new PostgresFromTable(t, false))
7267
.collect(Collectors.toList()));
7368
selectStatement.setFetchColumns(fetchColumns.stream()
7469
.map(c -> new PostgresColumnValue(c, pivotRow.getValues().get(c))).collect(Collectors.toList()));
75-
state.queryTargetedColumnsString = fetchColumns.stream().map(c -> c.getFullQualifiedName())
76-
.collect(Collectors.joining(", "));
7770
PostgresExpression whereClause = generateWhereClauseThatContainsRowValue(columns, pivotRow);
7871
selectStatement.setWhereClause(whereClause);
79-
state.whereClause = selectStatement;
8072
List<PostgresExpression> groupByClause = generateGroupByClause(columns, pivotRow);
8173
selectStatement.setGroupByExpressions(groupByClause);
8274
PostgresExpression limitClause = generateLimit();
@@ -107,7 +99,6 @@ public String getQueryThatContainsAtLeastOneRow(PostgresStateToReproduce state)
10799
}
108100
}
109101
sb2.append(") as result;");
110-
state.queryThatSelectsRow = sb2.toString();
111102

112103
PostgresToStringVisitor visitor = new PostgresToStringVisitor();
113104
visitor.visit(selectStatement);
@@ -170,7 +161,6 @@ private boolean isContainedIn(String queryString, MainOptions options, StateLogg
170161
}
171162
String resultingQueryString = sb.toString();
172163
// log both SELECT queries at the bottom of the error log file
173-
state.getLocalState().log(String.format("-- %s;\n-- %s;", queryString, resultingQueryString));
174164
if (options.logEachSelect()) {
175165
logger.writeCurrent(resultingQueryString);
176166
}

src/sqlancer/sqlite3/SQLite3Provider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import sqlancer.IgnoreMeException;
1616
import sqlancer.ProviderAdapter;
1717
import sqlancer.Randomly;
18-
import sqlancer.StateToReproduce;
19-
import sqlancer.StateToReproduce.SQLite3StateToReproduce;
2018
import sqlancer.StatementExecutor;
2119
import sqlancer.common.query.ExpectedErrors;
2220
import sqlancer.common.query.Query;
@@ -359,9 +357,4 @@ public String getDBMSName() {
359357
return "sqlite3";
360358
}
361359

362-
@Override
363-
public StateToReproduce getStateToReproduce(String databaseName) {
364-
return new SQLite3StateToReproduce(databaseName);
365-
}
366-
367360
}

0 commit comments

Comments
 (0)