Skip to content

Commit d0d0d60

Browse files
committed
Simplify the schema update logic
1 parent f5d1d44 commit d0d0d60

File tree

10 files changed

+23
-19
lines changed

10 files changed

+23
-19
lines changed

src/sqlancer/GlobalState.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ protected void setSchema(S schema) {
164164
this.schema = schema;
165165
}
166166

167-
protected abstract void updateSchema() throws SQLException;
167+
public void updateSchema() throws SQLException {
168+
setSchema(readSchema());
169+
}
170+
171+
protected abstract S readSchema() throws SQLException;
168172

169173
}

src/sqlancer/citus/CitusGlobalState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public boolean getRepartition() {
1717
}
1818

1919
@Override
20-
public void updateSchema() throws SQLException {
21-
setSchema(CitusSchema.fromConnection(getConnection(), getDatabaseName()));
20+
public CitusSchema readSchema() throws SQLException {
21+
return CitusSchema.fromConnection(getConnection(), getDatabaseName());
2222
}
2323

2424
}

src/sqlancer/clickhouse/ClickHouseProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public String getDatabaseName() {
7474
}
7575

7676
@Override
77-
protected void updateSchema() throws SQLException {
78-
setSchema(ClickHouseSchema.fromConnection(getConnection(), getDatabaseName()));
77+
protected ClickHouseSchema readSchema() throws SQLException {
78+
return ClickHouseSchema.fromConnection(getConnection(), getDatabaseName());
7979
}
8080
}
8181

src/sqlancer/cockroachdb/CockroachDBProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ public Query getQuery(CockroachDBGlobalState state) throws SQLException {
113113
public static class CockroachDBGlobalState extends GlobalState<CockroachDBOptions, CockroachDBSchema> {
114114

115115
@Override
116-
protected void updateSchema() throws SQLException {
117-
setSchema(CockroachDBSchema.fromConnection(getConnection(), getDatabaseName()));
116+
protected CockroachDBSchema readSchema() throws SQLException {
117+
return CockroachDBSchema.fromConnection(getConnection(), getDatabaseName());
118118
}
119119

120120
}

src/sqlancer/duckdb/DuckDBProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ private static int mapActions(DuckDBGlobalState globalState, Action a) {
8888
public static class DuckDBGlobalState extends GlobalState<DuckDBOptions, DuckDBSchema> {
8989

9090
@Override
91-
protected void updateSchema() throws SQLException {
92-
setSchema(DuckDBSchema.fromConnection(getConnection(), getDatabaseName()));
91+
protected DuckDBSchema readSchema() throws SQLException {
92+
return DuckDBSchema.fromConnection(getConnection(), getDatabaseName());
9393
}
9494

9595
}

src/sqlancer/mariadb/MariaDBProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ public void generateDatabase(MariaDBGlobalState globalState) throws SQLException
155155
public static class MariaDBGlobalState extends GlobalState<MariaDBOptions, MariaDBSchema> {
156156

157157
@Override
158-
protected void updateSchema() throws SQLException {
159-
setSchema(MariaDBSchema.fromConnection(getConnection(), getDatabaseName()));
158+
protected MariaDBSchema readSchema() throws SQLException {
159+
return MariaDBSchema.fromConnection(getConnection(), getDatabaseName());
160160
}
161161

162162
}

src/sqlancer/mysql/MySQLGlobalState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
public class MySQLGlobalState extends GlobalState<MySQLOptions, MySQLSchema> {
1010

1111
@Override
12-
protected void updateSchema() throws SQLException {
13-
setSchema(MySQLSchema.fromConnection(getConnection(), getDatabaseName()));
12+
protected MySQLSchema readSchema() throws SQLException {
13+
return MySQLSchema.fromConnection(getConnection(), getDatabaseName());
1414
}
1515

1616
public boolean usesPQS() {

src/sqlancer/postgres/PostgresGlobalState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public String getRandomOpclass() {
101101
}
102102

103103
@Override
104-
public void updateSchema() throws SQLException {
105-
setSchema(PostgresSchema.fromConnection(getConnection(), getDatabaseName()));
104+
public PostgresSchema readSchema() throws SQLException {
105+
return PostgresSchema.fromConnection(getConnection(), getDatabaseName());
106106
}
107107

108108
public void addFunctionAndType(String functionName, Character functionType) {

src/sqlancer/sqlite3/SQLite3Provider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public Query getQuery(SQLite3GlobalState state) throws SQLException {
115115
public static class SQLite3GlobalState extends GlobalState<SQLite3Options, SQLite3Schema> {
116116

117117
@Override
118-
protected void updateSchema() throws SQLException {
119-
setSchema(SQLite3Schema.fromConnection(this));
118+
protected SQLite3Schema readSchema() throws SQLException {
119+
return SQLite3Schema.fromConnection(this);
120120
}
121121

122122
}

src/sqlancer/tidb/TiDBProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public Query getQuery(TiDBGlobalState state) throws SQLException {
6969
public static class TiDBGlobalState extends GlobalState<TiDBOptions, TiDBSchema> {
7070

7171
@Override
72-
protected void updateSchema() throws SQLException {
73-
setSchema(TiDBSchema.fromConnection(getConnection(), getDatabaseName()));
72+
protected TiDBSchema readSchema() throws SQLException {
73+
return TiDBSchema.fromConnection(getConnection(), getDatabaseName());
7474
}
7575

7676
}

0 commit comments

Comments
 (0)